Advertisement
Guest User

Camera.java

a guest
Apr 12th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. package base;
  2.  
  3. import org.lwjgl.input.Keyboard;
  4. import org.lwjgl.util.vector.Matrix4f;
  5. import org.lwjgl.util.vector.Vector3f;
  6.  
  7. import base.*;
  8.  
  9. public class Camera {
  10.     Vector3f xAxis, yAxis, zAxis;
  11.     float moveSpeed = 0.1f;
  12.     boolean moveUp, moveDown, moveLeft, moveRight;
  13.    
  14.     public Camera(){
  15.         Matrices.viewMatrix = new Matrix4f();
  16.         Matrix4f.setIdentity(Matrices.viewMatrix);
  17.     }
  18.    
  19.     public void cameraLogic(){
  20.         //MOVE FORWARD
  21.         if(Keyboard.isKeyDown(Keyboard.KEY_W))
  22.             moveUp = true;
  23.         else
  24.             moveUp = false;
  25.        
  26.         //MOVE LEFT
  27.         if(Keyboard.isKeyDown(Keyboard.KEY_A))
  28.             moveLeft = true;
  29.         else
  30.             moveLeft = false;
  31.        
  32.         //MOVE BACK
  33.         if(Keyboard.isKeyDown(Keyboard.KEY_S))
  34.             moveDown = true;
  35.         else
  36.             moveDown = false;
  37.        
  38.         //MOVE RIGHT
  39.         if(Keyboard.isKeyDown(Keyboard.KEY_D))
  40.             moveRight = true;
  41.         else
  42.             moveRight = false;
  43.        
  44.         if(moveUp)
  45.             Matrices.viewMatrix.translate(new Vector3f(0, 1.0f * moveSpeed, 0));
  46.         if(moveLeft)
  47.             Matrices.viewMatrix.translate(new Vector3f(-1.0f * moveSpeed, 0, 0));
  48.         if(moveDown)
  49.             Matrices.viewMatrix.translate(new Vector3f(0, -1.0f * moveSpeed, 0));
  50.         if(moveRight)
  51.             Matrices.viewMatrix.translate(new Vector3f(1.0f * moveSpeed, 0, 0));
  52.     }
  53.    
  54.     public void translate(Vector3f amount){
  55.         Matrix4f.translate(amount, Matrices.viewMatrix, Matrices.viewMatrix);
  56.     }
  57.    
  58.     public void rotateX(float amount){
  59.         Matrix4f.rotate(amount, new Vector3f(1, 0, 0), Matrices.viewMatrix, Matrices.viewMatrix);
  60.     }
  61.    
  62.     public void rotateY(float amount){
  63.        
  64.     }
  65.    
  66.     public void rotateZ(float amount){
  67.        
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement