Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15526
Added Files:
View3D.java
Log Message:
The 3D view
--- NEW FILE: View3D.java ---
//---------------------------------------------------------------------------------
// $Id: View3D.java,v 1.1 2005/07/26 12:41:58 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 3D view
*/
public class View3D extends AbstractView {
/** The logger */
private static Logger log = Logger.getLogger(View3D.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 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);
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 {
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);
}
/**
* 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
*/
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;
} 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();
}
/**
* 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);
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) {
return new double[] {0.0, 0.0, 0.0};
} else {
log.warn("Too many arguments");
return new double[] {0.0, 0.0, 0.0};
}
}
}
|