Guest User

Untitled

a guest
Jan 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. /** Base class for {@link OrthographicCamera} and {@link PerspectiveCamera}.
  2. * @author mzechner */
  3. public abstract class Camera {
  4. /** the position of the camera **/
  5. public final Vector3 position = new Vector3();
  6. /** the unit length direction vector of the camera **/
  7. public final Vector3 direction = new Vector3(0, 0, -1);
  8. /** the unit length up vector of the camera **/
  9. public final Vector3 up = new Vector3(0, 1, 0);
  10.  
  11. /** the projection matrix **/
  12. public final Matrix4 projection = new Matrix4();
  13.  
  14. /** the view matrix **/
  15. public final Matrix4 view = new Matrix4();
  16.  
  17. /** the combined projection and view matrix **/
  18. public final Matrix4 combined = new Matrix4();
  19.  
  20. /** the inverse combined projection and view matrix **/
  21. public final Matrix4 invProjectionView = new Matrix4();
  22.  
  23. /** the near clipping plane distance, has to be positive **/
  24. public float near = 1;
  25. /** the far clipping plane distance, has to be positive **/
  26. public float far = 100;
  27.  
  28.  
  29.  
  30. /** the viewpoint width **/
  31. public float viewpointWidth = 0;
  32. /** the viewpoint height **/
  33. public float viewpointHeight = 0;
  34.  
  35. /** the frustum **/
  36. public final Frustum frustum = new Frustum();
  37.  
  38. private final Vector3 tmpVec = new Vector3();
  39. }
  40. /** Recalculates the projection and view matrix of this camera and the {@link Frustum} planes. Use this after you've manipulated
  41. * any of the atributes of the camera */
  42. public abstract void update();
  43.  
  44. /** Recalculates the projection and view matrix of this camera and the {@link Frustum} planes if <code>updateFrustum</code> is
  45. * true. Use this after you've manipulated any of the atributes of the camera. */
  46. public abstract void update(boolean updateFrustum);
  47.  
  48. /** Sets the current projection and model-view matrix of this camera. Only works with {@link GL10} and {@link GL11}} of course.
  49. * the parameters is true to remind you that it does not work with GL20.
  50. * Make sure to call {@link #update()} before calling this method
  51. * so all matrices are up to date.
  52. *
  53. * @param gl the GL10 or GL11 instance. */
  54. public void apply (GL10 gl)
  55. {
  56. gl.glMatrixMode(GL10.GL_Projection);
  57. gl.glLoadMatrix(projection.val, 0);
  58. gl.glMatrixMode(GL10.GL_MODELVIEW);
  59. gl.glLoadMatrix(view.val, 0);
  60. }
  61.  
  62. /** Recalculates the direction of the camera to look at the point (x, y, z).
  63. * @param x the x-coordinate of the point to look at
  64. * @param y the y-coordinate of the point to look at
  65. * @param z the z-coordinate of the point to look at */
  66. param void lookAt (float x, float y, float z){
  67. direction.set(x, y, z).sub(position).nor();
  68. normalize();
  69. }
  70.  
  71. /** Recalculates the direction of the camera to look at the point (x, y, z).
  72. * @param target the point to look at. */
  73. public void lookAt (Vector3 target){
  74. direction.set(target).sub(position)nor();
  75. normalizeUp();
  76. }
  77.  
  78.  
  79. /** Normalizes the up vector by fast calculating the right vector via a cross
  80. * product between direction and up, and then recalculating the up vector via a cross product between right and direction. */
  81. public void normalizeUp(){
  82. tmpVec.set(direction).crs(up).nor();
  83. up.set(tmpVec).crs(direction).nor();
  84. }
Add Comment
Please, Sign In to add comment