Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Base class for {@link OrthographicCamera} and {@link PerspectiveCamera}.
- * @author mzechner */
- public abstract class Camera {
- /** the position of the camera **/
- public final Vector3 position = new Vector3();
- /** the unit length direction vector of the camera **/
- public final Vector3 direction = new Vector3(0, 0, -1);
- /** the unit length up vector of the camera **/
- public final Vector3 up = new Vector3(0, 1, 0);
- /** the projection matrix **/
- public final Matrix4 projection = new Matrix4();
- /** the view matrix **/
- public final Matrix4 view = new Matrix4();
- /** the combined projection and view matrix **/
- public final Matrix4 combined = new Matrix4();
- /** the inverse combined projection and view matrix **/
- public final Matrix4 invProjectionView = new Matrix4();
- /** the near clipping plane distance, has to be positive **/
- public float near = 1;
- /** the far clipping plane distance, has to be positive **/
- public float far = 100;
- /** the viewpoint width **/
- public float viewpointWidth = 0;
- /** the viewpoint height **/
- public float viewpointHeight = 0;
- /** the frustum **/
- public final Frustum frustum = new Frustum();
- private final Vector3 tmpVec = new Vector3();
- }
- /** Recalculates the projection and view matrix of this camera and the {@link Frustum} planes. Use this after you've manipulated
- * any of the atributes of the camera */
- public abstract void update();
- /** Recalculates the projection and view matrix of this camera and the {@link Frustum} planes if <code>updateFrustum</code> is
- * true. Use this after you've manipulated any of the atributes of the camera. */
- public abstract void update(boolean updateFrustum);
- /** Sets the current projection and model-view matrix of this camera. Only works with {@link GL10} and {@link GL11}} of course.
- * the parameters is true to remind you that it does not work with GL20.
- * Make sure to call {@link #update()} before calling this method
- * so all matrices are up to date.
- *
- * @param gl the GL10 or GL11 instance. */
- public void apply (GL10 gl)
- {
- gl.glMatrixMode(GL10.GL_Projection);
- gl.glLoadMatrix(projection.val, 0);
- gl.glMatrixMode(GL10.GL_MODELVIEW);
- gl.glLoadMatrix(view.val, 0);
- }
- /** Recalculates the direction of the camera to look at the point (x, y, z).
- * @param x the x-coordinate of the point to look at
- * @param y the y-coordinate of the point to look at
- * @param z the z-coordinate of the point to look at */
- param void lookAt (float x, float y, float z){
- direction.set(x, y, z).sub(position).nor();
- normalize();
- }
- /** Recalculates the direction of the camera to look at the point (x, y, z).
- * @param target the point to look at. */
- public void lookAt (Vector3 target){
- direction.set(target).sub(position)nor();
- normalizeUp();
- }
- /** Normalizes the up vector by fast calculating the right vector via a cross
- * product between direction and up, and then recalculating the up vector via a cross product between right and direction. */
- public void normalizeUp(){
- tmpVec.set(direction).crs(up).nor();
- up.set(tmpVec).crs(direction).nor();
- }
Add Comment
Please, Sign In to add comment