[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl View3DListener.java,1.1.1.1,1.2
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2005-07-18 10:35:49
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31649 Modified Files: View3DListener.java Log Message: Added zoom, move and rotation Index: View3DListener.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/View3DListener.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** View3DListener.java 14 Jul 2005 09:49:59 -0000 1.1.1.1 --- View3DListener.java 18 Jul 2005 10:35:36 -0000 1.2 *************** *** 20,23 **** --- 20,35 ---- private static Logger log = Logger.getLogger(View3DListener.class); + /** The relative center of the view */ + private static double[] center = new double[] {0.0, 0.0, 0.0}; + + /** The rotaion about the X axis */ + private static double rotationX = 0; + + /** The rotation about the Y axis */ + private static double rotationY = -30; + + /** The zoom factor for the camera */ + private static double zoomFactor = 1.0; + /** * The drawing function *************** *** 35,55 **** gl.glShadeModel(GL.GL_FLAT); - gl.glMatrixMode(GL.GL_MODELVIEW); - gl.glLoadIdentity(); - glu.gluLookAt(14.0f, 11.0f, 25.0f, - 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); - double aspect = width / height; if (aspect < 1.0) { // fovy, aspect, near, far (relative to camera position) ! glu.gluPerspective(aspect * 60.0, 1.0, 0.0, 50.0); } else { ! // fovy, aspect, near, far (relative to camera position) ! glu.gluPerspective(60.0, aspect, 0.0, 50.0); } grid(gl); coords(gl); --- 47,69 ---- gl.glShadeModel(GL.GL_FLAT); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); double aspect = width / height; 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); *************** *** 60,63 **** --- 74,107 ---- /** + * Move the center left/right, up/down, forward/backward + * @param mv the move vector + */ + public void translateCenter(double [] mv) { + if (mv.length == 3) { + this.viewTrans[12] -= mv[0]; + this.viewTrans[13] += mv[2]; + this.viewTrans[14] += mv[1]; + } else { + log.error("[translateViewMatrix] Wrong parameter size"); + } + } + + /** + * Change the rotation about the x axis + * @param change The change in R+ (is divided with the window height) + */ + public void translateRotationX(double change) { + rotationX += change / height; + } + + /** + * Change the rotation about the y axis + * @param change The change in R+ (is divided with the window height) + */ + public void translateRotationY(double change) { + rotationY += change / width; + } + + /** * Draw a grid * @param gl The Graphic Layer *************** *** 67,77 **** gl.glColor3f(0.85f, 0.85f, 0.85f); gl.glBegin(GL.GL_LINES); ! for (int x = -25; x <= 25; x++) { ! gl.glVertex3d((double) x, 0.0, -15.0); ! gl.glVertex3d((double) x, 0.0, 15.0); } ! for (int z = -15; z <= 15; z++) { ! gl.glVertex3d(-25.0, 0.0, (double) z); ! gl.glVertex3d(25.0, 0.0, (double) z); } gl.glEnd(); --- 111,127 ---- gl.glColor3f(0.85f, 0.85f, 0.85f); gl.glBegin(GL.GL_LINES); ! double size = this.size / 2 * zoomFactor; ! if (aspect > 1) { ! size *= aspect; ! } else { ! size /= aspect; } ! for (int x = -(int)size; x <= (int)size; x++) { ! gl.glVertex3d((double) x, 0.0, -size); ! gl.glVertex3d((double) x, 0.0, size); ! } ! for (int z = -(int)size; z <= (int)size; z++) { ! gl.glVertex3d(-size, 0.0, (double) z); ! gl.glVertex3d(size, 0.0, (double) z); } gl.glEnd(); *************** *** 96,98 **** --- 146,159 ---- 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; + } + } } |