Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/model
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv20304/src/net/sourceforge/bprocessor/gl/model
Added Files:
GlCamera.java
Log Message:
A 3d representation of cameras
--- NEW FILE: GlCamera.java ---
//---------------------------------------------------------------------------------
// $Id: GlCamera.java,v 1.1 2007/02/20 15:13:00 nordholt 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.model;
import javax.media.opengl.GL;
import org.apache.log4j.Logger;
import com.sun.opengl.util.GLUT;
import net.sourceforge.bprocessor.model.Camera;
import net.sourceforge.bprocessor.model.Edge;
import net.sourceforge.bprocessor.model.Geometry;
import net.sourceforge.bprocessor.model.Plane;
import net.sourceforge.bprocessor.model.Vertex;
/**
* Af 3d representation of a camera
*/
public class GlCamera implements GlObject {
/** The logger */
private static Logger log = Logger.getLogger(GlCamera.class);
/** The camera to represent in 3d */
private Camera cam;
/** Constructor setting the camera
* @param c the camera to present in 3d
*/
public GlCamera(Camera c) {
cam = c;
}
/**
* {@inheritDoc}
*/
public void draw(GL gl) {
Vertex position = new Vertex(cam.getCamera());
Vertex lookAt = position.minus(new Vertex(cam.getCenter()));
lookAt.normalize();
GLUT glut = new GLUT();
//Drawing the camera box
gl.glPushMatrix();
gl.glEnable(GL.GL_LIGHTING);
gl.glColor3d(0.1, 0.1, 0.1);
gl.glTranslated(position.getX(), position.getY(), position.getZ());
gl.glRotated(Math.toDegrees(Geometry.degreesAboutZ(lookAt)), 0.0, 0.0, 1.0);
gl.glRotated(-Math.toDegrees(Geometry.degreesAboutY(lookAt)), 0.0, 1.0, 0.0);
gl.glScaled(0.5, 0.25, 0.25);
glut.glutSolidCube(2.0f);
gl.glPopMatrix();
//Drawing the camera lense (the cone)
gl.glPushMatrix();
gl.glTranslated(position.getX(), position.getY(), position.getZ());
gl.glRotated(Math.toDegrees(Geometry.degreesAboutZ(lookAt)), 0.0, 0.0, 1.0);
gl.glRotated(-Math.toDegrees(Geometry.degreesAboutY(lookAt)), 0.0, 1.0, 0.0);
gl.glTranslated(-1.5 / 2, 0, 0);
gl.glRotated(90, 0.0, 1.0, 0.0);
glut.glutSolidCone(0.25, 1.5 / 2, 32, 32);
gl.glPopMatrix();
gl.glDisable(GL.GL_LIGHTING);
}
/**
* {@inheritDoc}
*/
public Plane getPlane() {
Vertex roll = new Vertex(cam.getRoll());
Vertex position = new Vertex(cam.getCamera());
Vertex lookAt = position.minus(new Vertex(cam.getCenter()));
Vertex cross = lookAt.cross(roll);
Plane p = new Plane(cross.getX(), cross.getY(), cross.getX(),
position);
return p;
}
/**
* {@inheritDoc}
*/
public Vertex intersection(Edge e) {
Plane p = getPlane();
return p.intersection(e);
}
/**
* get the ca model camera of this gl camera
* @return the camera
*/
public Camera getCamera() {
return cam;
}
}
|