Advertisement
Guest User

Camera.java

a guest
Sep 23rd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. package phigold.rendering;
  2.  
  3. import org.joml.Matrix4f;
  4. import org.joml.Vector3f;
  5.  
  6. public class Camera {
  7.    
  8.     private static final Vector3f UP_VECTOR = new Vector3f(0, 1, 0);
  9.    
  10.     protected Matrix4f viewMatrix = new Matrix4f();
  11.     protected Matrix4f projectionMatrix = new Matrix4f();
  12.    
  13.     protected Vector3f position = new Vector3f();
  14.     protected Vector3f rotation = new Vector3f(0, 90, 0);
  15.     protected Vector3f direction = new Vector3f();
  16.     protected Vector3f target = new Vector3f();
  17.    
  18.     protected float nearPlane = 0.01f;
  19.     protected float farPlane = 1000f;
  20.     protected float fov = 60;
  21.    
  22.     public void update() {
  23.         double pitch = Math.toRadians(rotation.x);
  24.         double yaw = Math.toRadians(rotation.y);
  25.        
  26.         direction.x = (float) (Math.cos(pitch) * Math.sin(yaw));
  27.         direction.y = (float) (Math.sin(pitch));
  28.         direction.z = (float) (Math.cos(pitch) * Math.cos(yaw));
  29.        
  30.         viewMatrix.setLookAt(position, position.add(direction, target), UP_VECTOR);
  31.         projectionMatrix.setPerspective((float)Math.toRadians(fov), 800f / 600f, nearPlane, farPlane);
  32.     }
  33.    
  34.     public Matrix4f getViewMatrix() {
  35.         return viewMatrix;
  36.     }
  37.    
  38.     public Matrix4f getProjectionMatrix() {
  39.         return projectionMatrix;
  40.     }
  41.    
  42.     public Vector3f getPosition() {
  43.         return position;
  44.     }
  45.    
  46.     public Vector3f getRotation() {
  47.         return rotation;
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement