Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.pandadev.eyecandy.graphics;
- import org.lwjgl.util.vector.Matrix4f;
- import org.lwjgl.util.vector.Vector3f;
- import com.pandadev.eyecandy.MatrixStack;
- public abstract class Camera {
- private final Vector3f position = new Vector3f();
- private final Vector3f target = new Vector3f(0f, 0f, -1f);
- private final Vector3f up = new Vector3f(0f, 1f, 0f);
- public abstract void update(float delta);
- public void applyTransformations(){
- Matrix4f viewMatrix = new Matrix4f();
- Vector3f zAxis = getForward();
- Vector3f xAxis = getRight();
- Vector3f yAxis = getUp();
- viewMatrix.m00 = xAxis.x;
- viewMatrix.m10 = xAxis.y;
- viewMatrix.m20 = xAxis.z;
- viewMatrix.m01 = yAxis.x;
- viewMatrix.m11 = yAxis.y;
- viewMatrix.m21 = yAxis.z;
- viewMatrix.m02 = zAxis.x;
- viewMatrix.m12 = zAxis.y;
- viewMatrix.m22 = zAxis.z;
- viewMatrix.m03 = position.x;
- viewMatrix.m13 = position.y;
- viewMatrix.m23 = position.z;
- MatrixStack.getViewMatrix().load(viewMatrix);
- }
- public Vector3f getForward(){
- Vector3f forward = new Vector3f();
- Vector3f.sub(position, target, forward);
- forward.normalise();
- return forward;
- }
- public Vector3f getBackward(){
- Vector3f backward = getForward();
- backward.negate();
- return backward;
- }
- public Vector3f getRight(){
- Vector3f right = new Vector3f();
- Vector3f.cross(getForward(), up, right);
- return right;
- }
- public Vector3f getLeft(){
- Vector3f left = getRight();
- left.negate();
- return left;
- }
- public Vector3f getUp(){
- Vector3f up = new Vector3f();
- Vector3f.cross(getForward(), getRight(), up);
- return up;
- }
- public Vector3f getDown(){
- Vector3f down = getUp();
- down.negate();
- return down;
- }
- public Vector3f getPosition(){
- return position;
- }
- public Vector3f getTarget(){
- return target;
- }
- public void setPosition(Vector3f position){
- this.position.set(position);
- }
- public void setTarget(Vector3f target){
- this.target.set(target);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement