Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31744
Modified Files:
ViewYZListener.java
Log Message:
Added zoom and move
Index: ViewYZListener.java
===================================================================
RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/ViewYZListener.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** ViewYZListener.java 14 Jul 2005 09:49:59 -0000 1.1.1.1
--- ViewYZListener.java 18 Jul 2005 10:36:34 -0000 1.2
***************
*** 20,23 ****
--- 20,29 ----
private static Logger log = Logger.getLogger(ViewYZListener.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(-10.0f, 0.0f, 0.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,
***************
*** 50,59 ****
}
grid(gl);
coords(gl);
! gl.glColor3f(1.0f, 1.0f, 1.0f);
gl.glLineWidth(1.0f);
gl.glFlush();
}
/**
--- 53,80 ----
}
+ gl.glMatrixMode(GL.GL_MODELVIEW);
+ 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();
}
+
+ /**
+ * 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[2];
+ this.center[1] += mv[1];
+ this.center[2] += mv[0];
+ } else {
+ log.error("[translateViewMatrix] Wrong parameter size");
+ }
+ }
/**
***************
*** 62,65 ****
--- 83,92 ----
*/
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);
***************
*** 91,93 ****
--- 118,131 ----
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;
+ }
+ }
}
|