Advertisement
PandaMoniumHUN

Camera.java

Dec 23rd, 2013
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. package com.pandadev.eyecandy.graphics;
  2.  
  3. import org.lwjgl.util.vector.Matrix4f;
  4. import org.lwjgl.util.vector.Vector3f;
  5.  
  6. import com.pandadev.eyecandy.MatrixStack;
  7.  
  8. public abstract class Camera {
  9.     private final Vector3f position = new Vector3f();
  10.     private final Vector3f target = new Vector3f(0f, 0f, -1f);
  11.     private final Vector3f up = new Vector3f(0f, 1f, 0f);
  12.    
  13.     public abstract void update(float delta);
  14.    
  15.     public void applyTransformations(){
  16.         Matrix4f viewMatrix = new Matrix4f();
  17.         Vector3f zAxis = getForward();
  18.         Vector3f xAxis = getRight();
  19.         Vector3f yAxis = getUp();
  20.         viewMatrix.m00 = xAxis.x;
  21.         viewMatrix.m10 = xAxis.y;
  22.         viewMatrix.m20 = xAxis.z;
  23.         viewMatrix.m01 = yAxis.x;
  24.         viewMatrix.m11 = yAxis.y;
  25.         viewMatrix.m21 = yAxis.z;
  26.         viewMatrix.m02 = zAxis.x;
  27.         viewMatrix.m12 = zAxis.y;
  28.         viewMatrix.m22 = zAxis.z;
  29.         viewMatrix.m03 = position.x;
  30.         viewMatrix.m13 = position.y;
  31.         viewMatrix.m23 = position.z;
  32.         MatrixStack.getViewMatrix().load(viewMatrix);
  33.     }
  34.    
  35.     public Vector3f getForward(){
  36.         Vector3f forward = new Vector3f();
  37.         Vector3f.sub(position, target, forward);
  38.         forward.normalise();
  39.         return forward;
  40.     }
  41.    
  42.     public Vector3f getBackward(){
  43.         Vector3f backward = getForward();
  44.         backward.negate();
  45.         return backward;
  46.     }
  47.    
  48.     public Vector3f getRight(){
  49.         Vector3f right = new Vector3f();
  50.         Vector3f.cross(getForward(), up, right);
  51.         return right;
  52.     }
  53.    
  54.     public Vector3f getLeft(){
  55.         Vector3f left = getRight();
  56.         left.negate();
  57.         return left;
  58.     }
  59.    
  60.     public Vector3f getUp(){
  61.         Vector3f up = new Vector3f();
  62.         Vector3f.cross(getForward(), getRight(), up);
  63.         return up;
  64.     }
  65.    
  66.     public Vector3f getDown(){
  67.         Vector3f down = getUp();
  68.         down.negate();
  69.         return down;
  70.     }
  71.    
  72.     public Vector3f getPosition(){
  73.         return position;
  74.     }
  75.    
  76.     public Vector3f getTarget(){
  77.         return target;
  78.     }
  79.    
  80.     public void setPosition(Vector3f position){
  81.         this.position.set(position);
  82.     }
  83.    
  84.     public void setTarget(Vector3f target){
  85.         this.target.set(target);
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement