[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/view ViewXY.java,NONE,1.1 ViewXZ.java,NONE,
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2005-07-26 12:43:38
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15807 Added Files: ViewXY.java ViewXZ.java ViewYZ.java Log Message: the 2D views --- NEW FILE: ViewYZ.java --- //--------------------------------------------------------------------------------- // $Id: ViewYZ.java,v 1.1 2005/07/26 12:43:21 rimestad Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gl.view; import net.java.games.jogl.GL; import net.java.games.jogl.GLDrawable; import net.java.games.jogl.GLU; import org.apache.log4j.Logger; /** * The Y-Z plane view */ public class ViewYZ extends AbstractView { /** The logger */ private static Logger log = Logger.getLogger(ViewYZ.class); /** The relative center of the view */ 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, -(size * (height / width)), (size * (height / width)), -25.0, 25.0); } else { gl.glOrtho(-(size * aspect), size * aspect, -size, size, -25.0, 25.0); } 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); } /** * 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"); } } /** * 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++) { gl.glVertex3d(0.0, (double)y, -size); gl.glVertex3d(0.0, (double)y, size); } for (int z = -(int)size; z <= size; z++) { gl.glVertex3d(0.0, -size, (double)z); gl.glVertex3d(0.0, size, (double)z); } gl.glEnd(); } /** * 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); gl.glEnd(); } /** * 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}; } } } --- NEW FILE: ViewXY.java --- //--------------------------------------------------------------------------------- // $Id: ViewXY.java,v 1.1 2005/07/26 12:43:21 rimestad Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gl.view; import net.java.games.jogl.GL; import net.java.games.jogl.GLDrawable; import net.java.games.jogl.GLU; import org.apache.log4j.Logger; /** * The X-Y plane view */ public class ViewXY extends AbstractView { /** The logger */ private static Logger log = Logger.getLogger(ViewXY.class); /** The relative center of the view */ 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, -(size * (height / width)), (size * (height / width)), -25.0, 25.0); } else { gl.glOrtho(-(size * aspect), size * aspect, -size, size, -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); } /** * 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"); } } /** * 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++) { gl.glVertex3d((double) x, -size, 0.0); gl.glVertex3d((double) x, size, 0.0); } for (int y = -(int)size; y <= (int)size; y++) { gl.glVertex3d(-size, (double) y, 0.0); gl.glVertex3d(size, (double) y, 0.0); } gl.glEnd(); } /** * 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.glEnd(); } /** * 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}; } } } --- NEW FILE: ViewXZ.java --- //--------------------------------------------------------------------------------- // $Id: ViewXZ.java,v 1.1 2005/07/26 12:43:21 rimestad Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gl.view; import net.java.games.jogl.GL; import net.java.games.jogl.GLDrawable; import net.java.games.jogl.GLU; import org.apache.log4j.Logger; /** * The X-Z plane view */ public class ViewXZ extends AbstractView { /** The logger */ private static Logger log = Logger.getLogger(ViewXZ.class); /** The relative center of the view */ 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, -(size * (height / width)), (size * (height / width)), -25.0, 25.0); } else { gl.glOrtho(-(size * aspect), size * aspect, -size, size, -25.0, 25.0); } // 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); } /** * 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"); } } /** * 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++) { 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(); } /** * 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); gl.glEnd(); } /** * 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}; } } } |