[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl ViewXYListener.java,1.1.1.1,1.2 ViewXZListe
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2005-07-18 10:34:56
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31474 Modified Files: ViewXYListener.java ViewXZListener.java Log Message: added zoom and move Index: ViewXZListener.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/ViewXZListener.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ViewXZListener.java 14 Jul 2005 09:49:59 -0000 1.1.1.1 --- ViewXZListener.java 18 Jul 2005 10:34:42 -0000 1.2 *************** *** 20,23 **** --- 20,29 ---- private static Logger log = Logger.getLogger(ViewXZListener.class); + /** The relative center of the view */ + 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 *************** *** 34,45 **** gl.glClear(GL.GL_COLOR_BUFFER_BIT); - // MatrixMode have to be MODELVIEW for positioning - gl.glMatrixMode(GL.GL_MODELVIEW); - gl.glLoadIdentity(); - glu.gluLookAt(0.0f, -10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); - // Matrix mode have to be projection for perspecive gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); if (width <= height) { gl.glOrtho(-size, size, --- 40,47 ---- 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, *************** *** 52,61 **** } grid(gl); coords(gl); ! gl.glColor3f(1.0f, 1.0f, 1.0f); gl.glLineWidth(1.0f); gl.glFlush(); } /** --- 54,82 ---- } + // MatrixMode have to be MODELVIEW for positioning + gl.glMatrixMode(GL.GL_MODELVIEW); + 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(); } + + /** + * Move the center left/right, up/down, left/right + * @param mv the move vector + */ + public void translateCenter(double [] mv) { + if (mv.length == 3) { + this.center[0] += mv[0]; + this.center[1] += mv[2]; + this.center[2] += mv[1]; + } else { + log.error("[translateViewMatrix] Wrong parameter size"); + } + } /** *************** *** 67,70 **** --- 88,97 ---- 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++) { gl.glVertex3d((double) x, 0.0, -size); *************** *** 93,95 **** --- 120,133 ---- gl.glEnd(); } + + /** + * 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; + } + } } Index: ViewXYListener.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/ViewXYListener.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ViewXYListener.java 14 Jul 2005 09:49:59 -0000 1.1.1.1 --- ViewXYListener.java 18 Jul 2005 10:34:42 -0000 1.2 *************** *** 20,23 **** --- 20,29 ---- private static Logger log = Logger.getLogger(ViewXYListener.class); + /** The relative center of the view */ + 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 *************** *** 34,43 **** gl.glClear(GL.GL_COLOR_BUFFER_BIT); - gl.glMatrixMode(GL.GL_MODELVIEW); - gl.glLoadIdentity(); - glu.gluLookAt(0.0f, 0.0f, 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); - gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); if (width <= height) { gl.glOrtho(-size, size, --- 40,46 ---- 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, *************** *** 49,59 **** -25.0, 25.0); } grid(gl); coords(gl); ! gl.glColor3f(1.0f, 1.0f, 1.0f); gl.glLineWidth(1.0f); gl.glFlush(); } /** --- 52,79 ---- -25.0, 25.0); } + gl.glMatrixMode(GL.GL_MODELVIEW); + 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(); } + + /** + * Move the center left/right, up/down, left/right + * @param mv the move vector + */ + public void translateCenter(double [] mv) { + if (mv.length == 3) { + this.center[0] += mv[0]; + this.center[1] += mv[1]; + this.center[2] += mv[2]; + } else { + log.error("[translateViewMatrix] Wrong parameter size"); + } + } /** *************** *** 65,68 **** --- 85,94 ---- 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++) { gl.glVertex3d((double) x, -size, 0.0); *************** *** 91,93 **** --- 117,130 ---- gl.glEnd(); } + + /** + * 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; + } + } } |