[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl View3DListener.java,1.2,1.3 ViewXYListener.
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2005-07-22 11:27:30
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18336 Modified Files: View3DListener.java ViewXYListener.java ViewXZListener.java ViewYZListener.java Log Message: moved as much common code as possible to AbstractViewListener so they now only take care of camera, draw grid, draw axis and convert app coords to view coords Index: View3DListener.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/View3DListener.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** View3DListener.java 18 Jul 2005 10:35:36 -0000 1.2 --- View3DListener.java 22 Jul 2005 11:12:37 -0000 1.3 *************** *** 29,49 **** private static double rotationY = -30; - /** The zoom factor for the camera */ - private static double zoomFactor = 1.0; - /** ! * The drawing function * @param gld The GLDrawable object */ ! public void display(GLDrawable gld) { if (log.isDebugEnabled()) { log.debug("[display]"); } ! GL gl = gld.getGL(); GLU glu = gld.getGLU(); - gl.glClear(GL.GL_COLOR_BUFFER_BIT); - gl.glViewport(0, 0, (int)width, (int)height); - gl.glShadeModel(GL.GL_FLAT); --- 29,43 ---- private static double rotationY = -30; /** ! * The camera setup function * @param gld The GLDrawable object */ ! public void camera(GLDrawable gld) { if (log.isDebugEnabled()) { log.debug("[display]"); } ! gl = gld.getGL(); GLU glu = gld.getGLU(); gl.glShadeModel(GL.GL_FLAT); *************** *** 53,74 **** if (aspect < 1.0) { // fovy, aspect, near, far (relative to camera position) ! glu.gluPerspective(aspect * 60.0 * zoomFactor, 1.0, 0.0, 50.0); } else { ! glu.gluPerspective(60.0 * zoomFactor, aspect, 0.0, 50.0); } gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); ! glu.gluLookAt(0.0, 15.0, 20.0, center[0], center[1], center[2], 0.0, 1.0, 0.0); gl.glRotated(rotationX, 1.0, 0.0, 0.0); gl.glRotated(rotationY, 0.0, 1.0, 0.0); - gl.glMultMatrixd(viewTrans); - grid(gl); - coords(gl); - gl.glColor3f(1.0f, 1.0f, 1.0f); - gl.glLineWidth(1.0f); - gl.glFlush(); } --- 47,63 ---- if (aspect < 1.0) { // fovy, aspect, near, far (relative to camera position) ! glu.gluPerspective(aspect * 60.0, 1.0, 0.0, 50.0); } else { ! glu.gluPerspective(60.0, aspect, 0.0, 50.0); } gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); ! glu.gluLookAt(0.0, 15.0 * getZoomFactor(), 20.0 * getZoomFactor(), center[0], center[1], center[2], 0.0, 1.0, 0.0); + gl.glMultMatrixd(viewTrans); gl.glRotated(rotationX, 1.0, 0.0, 0.0); gl.glRotated(rotationY, 0.0, 1.0, 0.0); } *************** *** 92,96 **** */ public void translateRotationX(double change) { ! rotationX += change / height; } --- 81,85 ---- */ public void translateRotationX(double change) { ! rotationX -= change / height; } *************** *** 100,115 **** */ public void translateRotationY(double change) { ! rotationY += change / width; } /** * Draw a grid - * @param gl The Graphic Layer */ ! private void grid(GL gl) { gl.glLineWidth(1.0f); ! gl.glColor3f(0.85f, 0.85f, 0.85f); gl.glBegin(GL.GL_LINES); ! double size = this.size / 2 * zoomFactor; if (aspect > 1) { size *= aspect; --- 89,103 ---- */ public void translateRotationY(double change) { ! rotationY -= change / width; } /** * Draw a grid */ ! protected void grid() { gl.glLineWidth(1.0f); ! gl.glColor3dv(GRID_COLOR); gl.glBegin(GL.GL_LINES); ! double size = this.size; if (aspect > 1) { size *= aspect; *************** *** 130,145 **** /** * Draw a coordinate system - * @param gl The Graphics Layer */ ! private void coords(GL gl) { gl.glLineWidth(2.0f); gl.glBegin(GL.GL_LINES); ! gl.glColor3d(0.0, 1.0, 0.0); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(10.0, 0.0, 0.0); ! gl.glColor3d(1.0, 0.0, 0.0); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 10.0, 0.0); ! gl.glColor3d(0.0, 0.0, 1.0); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 0.0, 10.0); --- 118,132 ---- /** * Draw a coordinate system */ ! protected void coords() { gl.glLineWidth(2.0f); gl.glBegin(GL.GL_LINES); ! gl.glColor3dv(X_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(10.0, 0.0, 0.0); ! gl.glColor3dv(Y_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 10.0, 0.0); ! gl.glColor3dv(Z_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 0.0, 10.0); *************** *** 148,159 **** /** ! * Change the zoom factor of the camera take only R+ ! * 1-oo is increase zoom and 0-1 decrease 1 keep the current zoom ! * @param zoom the zoom factor change */ ! public void zoom(double zoom) { ! if (zoomFactor > 0) { ! this.zoomFactor *= zoom; } ! } } --- 135,149 ---- /** ! * Return the 3D coordinates for the canvas matching the given 2D coords ! * @return The relative 3D coordinates ! * @param coords The window coordinates */ ! public double[] toCanvasCoords(double[] coords) { ! if (coords.length == 2) { ! return new double[] {0.0, 0.0, 0.0}; ! } else { ! log.warn("Too many arguments"); ! return new double[] {0.0, 0.0, 0.0}; } ! } } Index: ViewXYListener.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/ViewXYListener.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ViewXYListener.java 18 Jul 2005 10:34:42 -0000 1.2 --- ViewXYListener.java 22 Jul 2005 11:12:38 -0000 1.3 *************** *** 23,46 **** private static double[] center = new double[] {0.0, 0.0, 0.0}; - /** The zoom factor for the camera */ - private static double zoomFactor = 1.0; - /** ! * The drawing function * @param gld The GLDrawable object */ ! public void display(GLDrawable gld) { if (log.isDebugEnabled()) { log.debug("[display]"); } ! GL gl = gld.getGL(); GLU glu = gld.getGLU(); - gl.glClear(GL.GL_COLOR_BUFFER_BIT); - gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); ! double size = this.size * this.zoomFactor; if (width <= height) { gl.glOrtho(-size, size, --- 23,41 ---- private static double[] center = new double[] {0.0, 0.0, 0.0}; /** ! * The camera setup function * @param gld The GLDrawable object */ ! public void camera(GLDrawable gld) { if (log.isDebugEnabled()) { log.debug("[display]"); } ! gl = gld.getGL(); GLU glu = gld.getGLU(); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); ! double size = this.size * getZoomFactor(); if (width <= height) { gl.glOrtho(-size, size, *************** *** 55,64 **** gl.glLoadIdentity(); glu.gluLookAt(center[0], center[1], 10.0, center[0], center[1], center[2], 0.0, 1.0, 0.0); - - grid(gl); - coords(gl); - gl.glColor3d(1.0, 1.0, 1.0); - gl.glLineWidth(1.0f); - gl.glFlush(); } --- 50,53 ---- *************** *** 79,93 **** /** * Draw a grid - * @param gl The Graphic Layer */ ! private void grid(GL gl) { gl.glLineWidth(1.0f); ! gl.glColor3f(0.85f, 0.85f, 0.85f); gl.glBegin(GL.GL_LINES); double size; if (aspect > 1) { ! size = this.size * zoomFactor * aspect; } else { ! size = this.size * zoomFactor / aspect; } for (int x = -(int)size; x <= (int)size; x++) { --- 68,81 ---- /** * Draw a grid */ ! protected void grid() { gl.glLineWidth(1.0f); ! gl.glColor3dv(GRID_COLOR); gl.glBegin(GL.GL_LINES); double size; if (aspect > 1) { ! size = this.size * getZoomFactor() * aspect; } else { ! size = this.size * getZoomFactor() / aspect; } for (int x = -(int)size; x <= (int)size; x++) { *************** *** 104,116 **** /** * Draw a coordinate system - * @param gl The Graphics Layer */ ! private void coords(GL gl) { gl.glLineWidth(2.0f); gl.glBegin(GL.GL_LINES); ! gl.glColor3d(0.0, 1.0, 0.0); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(10.0, 0.0, 0.0); ! gl.glColor3d(1.0, 0.0, 0.0); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 10.0, 0.0); --- 92,103 ---- /** * Draw a coordinate system */ ! protected void coords() { gl.glLineWidth(2.0f); gl.glBegin(GL.GL_LINES); ! gl.glColor3dv(X_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(10.0, 0.0, 0.0); ! gl.glColor3dv(Y_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 10.0, 0.0); *************** *** 119,130 **** /** ! * Change the zoom factor of the camera take only R+ ! * 1-oo is increase zoom and 0-1 decrease 1 keep the current zoom ! * @param zoom the zoom factor change */ ! public void zoom(double zoom) { ! if (zoomFactor > 0) { ! this.zoomFactor *= zoom; } ! } } --- 106,131 ---- /** ! * Return the 3D coordinates for the canvas matching the given 2D coords ! * @return The relative 3D coordinates ! * @param coords The window coordinates */ ! public double[] toCanvasCoords(double[] coords) { ! if (coords.length == 2) { ! double pixelwidth, pixelheight; ! if (aspect < 1) { ! pixelheight = height / (2 * size * getZoomFactor() * (1 / aspect)); ! pixelwidth = width / (2 * size * getZoomFactor()); ! } else { ! pixelheight = height / (2 * size * getZoomFactor()); ! pixelwidth = width / (2 * size * getZoomFactor() * aspect); ! } ! double returnx = coords[0] / pixelwidth + center[0] - width / (2 * pixelwidth); ! double returny = -coords[1] / pixelheight + center[1] + height / (2 * pixelheight); ! double returnz = 0; ! return new double[] {returnx, returny, returnz}; ! } else { ! log.warn("Too many arguments"); ! return new double[] {0.0, 0.0, 0.0}; } ! } } Index: ViewXZListener.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/ViewXZListener.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ViewXZListener.java 18 Jul 2005 10:34:42 -0000 1.2 --- ViewXZListener.java 22 Jul 2005 11:12:38 -0000 1.3 *************** *** 23,47 **** private static double[] center = new double[] {0.0, 0.0, 0.0}; - /** The zoom factor for the camera */ - private static double zoomFactor = 1.0; - /** ! * The drawing function * @param gld The GLDrawable object */ ! public void display(GLDrawable gld) { if (log.isDebugEnabled()) { log.debug("[display]"); } ! GL gl = gld.getGL(); GLU glu = gld.getGLU(); - - gl.glClear(GL.GL_COLOR_BUFFER_BIT); // Matrix mode have to be projection for perspecive gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); ! double size = this.size * this.zoomFactor; if (width <= height) { gl.glOrtho(-size, size, --- 23,42 ---- private static double[] center = new double[] {0.0, 0.0, 0.0}; /** ! * The camera setup function * @param gld The GLDrawable object */ ! public void camera(GLDrawable gld) { if (log.isDebugEnabled()) { log.debug("[display]"); } ! gl = gld.getGL(); GLU glu = gld.getGLU(); // Matrix mode have to be projection for perspecive gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); ! double size = this.size * getZoomFactor(); if (width <= height) { gl.glOrtho(-size, size, *************** *** 58,67 **** gl.glLoadIdentity(); glu.gluLookAt(center[0], -10.0, center[2], center[0], center[1], center[2], 0.0, 0.0, 1.0); - - grid(gl); - coords(gl); - gl.glColor3d(1.0, 1.0, 1.0); - gl.glLineWidth(1.0f); - gl.glFlush(); } --- 53,56 ---- *************** *** 82,96 **** /** * Draw a grid - * @param gl The Graphic Layer */ ! private void grid(GL gl) { gl.glLineWidth(1.0f); ! gl.glColor3f(0.85f, 0.85f, 0.85f); gl.glBegin(GL.GL_LINES); double size; if (aspect > 1) { ! size = this.size * zoomFactor * aspect; } else { ! size = this.size * zoomFactor / aspect; } for (int x = -(int)size; x <= (int)size; x++) { --- 71,84 ---- /** * Draw a grid */ ! protected void grid() { gl.glLineWidth(1.0f); ! gl.glColor3dv(GRID_COLOR); gl.glBegin(GL.GL_LINES); double size; if (aspect > 1) { ! size = this.size * getZoomFactor() * aspect; } else { ! size = this.size * getZoomFactor() / aspect; } for (int x = -(int)size; x <= (int)size; x++) { *************** *** 107,119 **** /** * Draw a coordinate system - * @param gl The Graphics Layer */ ! private void coords(GL gl) { gl.glLineWidth(2.0f); gl.glBegin(GL.GL_LINES); ! gl.glColor3d(0.0, 1.0, 0.0); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(10.0, 0.0, 0.0); ! gl.glColor3d(0.0, 0.0, 1.0); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 0.0, 10.0); --- 95,106 ---- /** * Draw a coordinate system */ ! protected void coords() { gl.glLineWidth(2.0f); gl.glBegin(GL.GL_LINES); ! gl.glColor3dv(X_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(10.0, 0.0, 0.0); ! gl.glColor3dv(Z_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 0.0, 10.0); *************** *** 122,133 **** /** ! * Change the zoom factor of the camera take only R+ ! * 1-oo is increase zoom and 0-1 decrease 1 keep the current zoom ! * @param zoom the zoom factor change */ ! public void zoom(double zoom) { ! if (zoomFactor > 0) { ! this.zoomFactor *= zoom; } ! } } --- 109,134 ---- /** ! * Return the 3D coordinates for the canvas matching the given 2D coords ! * @return The relative 3D coordinates ! * @param coords The window coordinates */ ! public double[] toCanvasCoords(double[] coords) { ! if (coords.length == 2) { ! double pixelwidth, pixelheight; ! if (aspect < 1) { ! pixelheight = height / (2 * size * getZoomFactor() * (1 / aspect)); ! pixelwidth = width / (2 * size * getZoomFactor()); ! } else { ! pixelheight = height / (2 * size * getZoomFactor()); ! pixelwidth = width / (2 * size * getZoomFactor() * aspect); ! } ! double returnx = coords[0] / pixelwidth + center[0] - width / (2 * pixelwidth); ! double returny = 0; ! double returnz = height / (2 * pixelheight) - coords[1] / pixelheight + center[2]; ! return new double[] {returnx, returny, returnz}; ! } else { ! log.warn("Too many arguments"); ! return new double[] {0.0, 0.0, 0.0}; } ! } } Index: ViewYZListener.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/ViewYZListener.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ViewYZListener.java 18 Jul 2005 10:36:34 -0000 1.2 --- ViewYZListener.java 22 Jul 2005 11:12:38 -0000 1.3 *************** *** 23,46 **** private static double[] center = new double[] {0.0, 0.0, 0.0}; - /** The zoom factor for the camera */ - private static double zoomFactor = 1.0; - /** ! * The drawing function * @param gld The GLDrawable object */ ! public void display(GLDrawable gld) { if (log.isDebugEnabled()) { log.debug("[display]"); } ! GL gl = gld.getGL(); GLU glu = gld.getGLU(); - - gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); ! double size = this.size * this.zoomFactor; if (width <= height) { gl.glOrtho(-size, size, --- 23,41 ---- private static double[] center = new double[] {0.0, 0.0, 0.0}; /** ! * The camera setup function * @param gld The GLDrawable object */ ! public void camera(GLDrawable gld) { if (log.isDebugEnabled()) { log.debug("[display]"); } ! gl = gld.getGL(); GLU glu = gld.getGLU(); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); ! double size = this.size * getZoomFactor(); if (width <= height) { gl.glOrtho(-size, size, *************** *** 56,65 **** gl.glLoadIdentity(); glu.gluLookAt(-10.0, center[1], center[2], center[0], center[1], center[2], 0.0, 1.0, 0.0); - - grid(gl); - coords(gl); - gl.glColor3d(1.0, 1.0, 1.0); - gl.glLineWidth(1.0f); - gl.glFlush(); } --- 51,54 ---- *************** *** 80,94 **** /** * Draw a grid - * @param gl The Graphic Layer */ ! private void grid(GL gl) { double size; if (aspect > 1) { ! size = this.size * zoomFactor * aspect; } else { ! size = this.size * zoomFactor / aspect; } gl.glLineWidth(1.0f); ! gl.glColor3f(0.85f, 0.85f, 0.85f); gl.glBegin(GL.GL_LINES); for (int y = -(int)size; y <= size; y++) { --- 69,82 ---- /** * Draw a grid */ ! protected void grid() { double size; if (aspect > 1) { ! size = this.size * getZoomFactor() * aspect; } else { ! size = this.size * getZoomFactor() / aspect; } gl.glLineWidth(1.0f); ! gl.glColor3dv(GRID_COLOR); gl.glBegin(GL.GL_LINES); for (int y = -(int)size; y <= size; y++) { *************** *** 105,117 **** /** * Draw a coordinate system - * @param gl The Graphics Layer */ ! private void coords(GL gl) { gl.glLineWidth(2.0f); gl.glBegin(GL.GL_LINES); ! gl.glColor3d(1.0, 0.0, 0.0); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 10.0, 0.0); ! gl.glColor3d(0.0, 0.0, 1.0); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 0.0, 10.0); --- 93,104 ---- /** * Draw a coordinate system */ ! protected void coords() { gl.glLineWidth(2.0f); gl.glBegin(GL.GL_LINES); ! gl.glColor3dv(Y_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 10.0, 0.0); ! gl.glColor3dv(Z_AXIS_COLOR); gl.glVertex3d(0.0, 0.0, 0.0); gl.glVertex3d(0.0, 0.0, 10.0); *************** *** 120,131 **** /** ! * Change the zoom factor of the camera take only R+ ! * 1-oo is increase zoom and 0-1 decrease 1 keep the current zoom ! * @param zoom the zoom factor change */ ! public void zoom(double zoom) { ! if (zoomFactor > 0) { ! this.zoomFactor *= zoom; } ! } } --- 107,132 ---- /** ! * Return the 3D coordinates for the canvas matching the given 2D coords ! * @return The relative 3D coordinates ! * @param coords The window coordinates */ ! public double[] toCanvasCoords(double[] coords) { ! if (coords.length == 2) { ! double pixelwidth, pixelheight; ! if (aspect < 1) { ! pixelheight = height / (2 * size * getZoomFactor() * (1 / aspect)); ! pixelwidth = width / (2 * size * getZoomFactor()); ! } else { ! pixelheight = height / (2 * size * getZoomFactor()); ! pixelwidth = width / (2 * size * getZoomFactor() * aspect); ! } ! double returnx = 0; ! double returny = height / (2 * pixelheight) - coords[1] / pixelheight + center[1]; ! double returnz = coords[0] / pixelwidth + center[2] - width / (2 * pixelwidth); ! return new double[] {returnx, returny, returnz}; ! } else { ! log.warn("Too many arguments"); ! return new double[] {0.0, 0.0, 0.0}; } ! } } |