atm959

Camera.java

Nov 14th, 2018
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. package com.atm959.openglgame;
  2.  
  3. import android.opengl.Matrix;
  4.  
  5. import static java.lang.Math.cos;
  6. import static java.lang.Math.sin;
  7.  
  8. public class Camera {
  9.  
  10.     private float posX, posY, posZ;
  11.     private float lookX, lookY, lookZ;
  12.  
  13.     public Camera(){
  14.         this.posX = 0.0f; this.posY = 0.0f; this.posZ = 0.0f;
  15.         this.lookX = 0.0f; this.lookY = 0.0f; this.lookZ = 2.0f;
  16.     }
  17.  
  18.     public void setPosX(float x){
  19.         this.posX = x;
  20.     }
  21.  
  22.     public void setPosY(float y){
  23.         this.posY = y;
  24.     }
  25.  
  26.     public void setPosZ(float z){
  27.         this.posZ = z;
  28.     }
  29.  
  30.     public void setPosition(float x, float y, float z){
  31.         this.posX = x;
  32.         this.posY = y;
  33.         this.posZ = z;
  34.     }
  35.  
  36.     public void setYaw(float angle){
  37.         this.lookX = this.posX + (float)(5 * sin(angle));
  38.         this.lookZ = this.posZ + (float)(5 * cos(angle));
  39.     }
  40.  
  41.     public void setPitch(float angle){
  42.         this.lookY = this.posY + (float)(5 * sin(angle));
  43.     }
  44.  
  45.     public float[] calculateCamMatrix(){
  46.         float[] camMatrix = new float[16];
  47.         Matrix.setLookAtM(camMatrix, 0, this.posX, this.posY, this.posZ, this.lookX, this.lookY, this.lookZ, 0f, 1.0f, 0.0f);
  48.         return camMatrix;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment