com.badlogic.gdx.graphics
Class Camera

java.lang.Object
  extended by com.badlogic.gdx.graphics.Camera
Direct Known Subclasses:
OrthographicCamera, PerspectiveCamera

public abstract class Camera
extends Object

Base class for OrthographicCamera and PerspectiveCamera.

Author:
mzechner

Field Summary
 Matrix4 combined
          the combined projection and view matrix
 Vector3 direction
          the unit length direction vector of the camera
 float far
          the far clipping plane distance, has to be positive
 Frustum frustum
          the frustum
 Matrix4 invProjectionView
          the inverse combined projection and view matrix
 float near
          the near clipping plane distance, has to be positive
 Vector3 position
          the position of the camera
 Matrix4 projection
          the projection matrix
 Vector3 up
          the unit length up vector of the camera
 Matrix4 view
          the view matrix
 float viewportHeight
          the viewport height
 float viewportWidth
          the viewport width
 
Constructor Summary
Camera()
           
 
Method Summary
 void apply(GL10 gl)
          Sets the current projection and model-view matrix of this camera.
 Ray getPickRay(float x, float y)
          Creates a picking Ray from the coordinates given in window coordinates.
 Ray getPickRay(float x, float y, float viewportX, float viewportY, float viewportWidth, float viewportHeight)
          Creates a picking Ray from the coordinates given in window coordinates.
 void lookAt(float x, float y, float z)
          Recalculates the direction of the camera to look at the point (x, y, z).
 void lookAt(Vector3 target)
          Recalculates the direction of the camera to look at the point (x, y, z).
 void normalizeUp()
          Normalizes the up vector by first calculating the right vector via a cross product between direction and up, and then recalculating the up vector via a cross product between right and direction.
 void project(Vector3 vec)
          Projects the Vector3 given in object/world space to window coordinates.
 void project(Vector3 vec, float viewportX, float viewportY, float viewportWidth, float viewportHeight)
          Projects the Vector3 given in object/world space to window coordinates.
 void rotate(float angle, float axisX, float axisY, float axisZ)
          Rotates the direction and up vector of this camera by the given angle around the given axis.
 void rotate(Matrix4 transform)
          Rotates the direction and up vector of this camera by the given rotation matrix.
 void rotate(Quaternion quat)
          Rotates the direction and up vector of this camera by the given Quaternion.
 void rotate(Vector3 axis, float angle)
          Rotates the direction and up vector of this camera by the given angle around the given axis.
 void rotateAround(Vector3 point, Vector3 axis, float angle)
          Rotates the direction and up vector of this camera by the given angle around the given axis, with the axis attached to given point.
 void transform(Matrix4 transform)
          Transform the position, direction and up vector by the given matrix
 void translate(float x, float y, float z)
          Moves the camera by the given amount on each axis.
 void translate(Vector3 vec)
          Moves the camera by the given vector.
 void unproject(Vector3 vec)
          Function to translate a point given in window (or window) coordinates to world space.
 void unproject(Vector3 vec, float viewportX, float viewportY, float viewportWidth, float viewportHeight)
          Function to translate a point given in window (or window) coordinates to world space.
abstract  void update()
          Recalculates the projection and view matrix of this camera and the Frustum planes.
abstract  void update(boolean updateFrustum)
          Recalculates the projection and view matrix of this camera and the Frustum planes if updateFrustum is true.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

position

public final Vector3 position
the position of the camera


direction

public final Vector3 direction
the unit length direction vector of the camera


up

public final Vector3 up
the unit length up vector of the camera


projection

public final Matrix4 projection
the projection matrix


view

public final Matrix4 view
the view matrix


combined

public final Matrix4 combined
the combined projection and view matrix


invProjectionView

public final Matrix4 invProjectionView
the inverse combined projection and view matrix


near

public float near
the near clipping plane distance, has to be positive


far

public float far
the far clipping plane distance, has to be positive


viewportWidth

public float viewportWidth
the viewport width


viewportHeight

public float viewportHeight
the viewport height


frustum

public final Frustum frustum
the frustum

Constructor Detail

Camera

public Camera()
Method Detail

update

public abstract void update()
Recalculates the projection and view matrix of this camera and the Frustum planes. Use this after you've manipulated any of the attributes of the camera.


update

public abstract void update(boolean updateFrustum)
Recalculates the projection and view matrix of this camera and the Frustum planes if updateFrustum is true. Use this after you've manipulated any of the attributes of the camera.


apply

public void apply(GL10 gl)
Sets the current projection and model-view matrix of this camera. Only works with GL10 and GL11 of course. The parameter is there to remind you that it does not work with GL20. Make sure to call update() before calling this method so all matrices are up to date.

Parameters:
gl - the GL10 or GL11 instance.

lookAt

public void lookAt(float x,
                   float y,
                   float z)
Recalculates the direction of the camera to look at the point (x, y, z).

Parameters:
x - the x-coordinate of the point to look at
y - the x-coordinate of the point to look at
z - the x-coordinate of the point to look at

lookAt

public void lookAt(Vector3 target)
Recalculates the direction of the camera to look at the point (x, y, z).

Parameters:
target - the point to look at

normalizeUp

public void normalizeUp()
Normalizes the up vector by first calculating the right vector via a cross product between direction and up, and then recalculating the up vector via a cross product between right and direction.


rotate

public void rotate(float angle,
                   float axisX,
                   float axisY,
                   float axisZ)
Rotates the direction and up vector of this camera by the given angle around the given axis. The direction and up vector will not be orthogonalized.

Parameters:
angle - the angle
axisX - the x-component of the axis
axisY - the y-component of the axis
axisZ - the z-component of the axis

rotate

public void rotate(Vector3 axis,
                   float angle)
Rotates the direction and up vector of this camera by the given angle around the given axis. The direction and up vector will not be orthogonalized.

Parameters:
axis -
angle - the angle

rotate

public void rotate(Matrix4 transform)
Rotates the direction and up vector of this camera by the given rotation matrix. The direction and up vector will not be orthogonalized.

Parameters:
transform - The rotation matrix

rotate

public void rotate(Quaternion quat)
Rotates the direction and up vector of this camera by the given Quaternion. The direction and up vector will not be orthogonalized.

Parameters:
quat - The quaternion

rotateAround

public void rotateAround(Vector3 point,
                         Vector3 axis,
                         float angle)
Rotates the direction and up vector of this camera by the given angle around the given axis, with the axis attached to given point. The direction and up vector will not be orthogonalized.

Parameters:
point -
axis -
angle - the angle

transform

public void transform(Matrix4 transform)
Transform the position, direction and up vector by the given matrix

Parameters:
transform - The transform matrix

translate

public void translate(float x,
                      float y,
                      float z)
Moves the camera by the given amount on each axis.

Parameters:
x - the displacement on the x-axis
y - the displacement on the y-axis
z - the displacement on the z-axis

translate

public void translate(Vector3 vec)
Moves the camera by the given vector.

Parameters:
vec - the displacement vector

unproject

public void unproject(Vector3 vec,
                      float viewportX,
                      float viewportY,
                      float viewportWidth,
                      float viewportHeight)
Function to translate a point given in window (or window) coordinates to world space. It's the same as GLU gluUnProject, but does not rely on OpenGL. The x- and y-coordinate of vec are assumed to be in window coordinates (origin is the top left corner, y pointing down, x pointing to the right) as reported by the touch methods in Input. A z-coordinate of 0 will return a point on the near plane, a z-coordinate of 1 will return a point on the far plane. This method allows you to specify the viewport position and dimensions in the coordinate system expected by GLCommon.glViewport(int, int, int, int), with the origin in the bottom left corner of the screen.

Parameters:
vec - the point in window coordinates (origin top left)
viewportX - the coordinate of the top left corner of the viewport in glViewport coordinates (origin bottom left)
viewportY - the coordinate of the top left corner of the viewport in glViewport coordinates (origin bottom left)
viewportWidth - the width of the viewport in pixels
viewportHeight - the height of the viewport in pixels

unproject

public void unproject(Vector3 vec)
Function to translate a point given in window (or window) coordinates to world space. It's the same as GLU gluUnProject but does not rely on OpenGL. The viewport is assumed to span the whole screen and is fetched from Graphics.getWidth() and Graphics.getHeight(). The x- and y-coordinate of vec are assumed to be in window coordinates (origin is the top left corner, y pointing down, x pointing to the right) as reported by the touch methods in Input. A z-coordinate of 0 will return a point on the near plane, a z-coordinate of 1 will return a point on the far plane.

Parameters:
vec - the point in window coordinates

project

public void project(Vector3 vec)
Projects the Vector3 given in object/world space to window coordinates. It's the same as GLU gluProject with one small deviation: The viewport is assumed to span the whole screen. The window coordinate system has its origin in the bottom left, with the y-axis pointing upwards and the x-axis pointing to the right. This makes it easily useable in conjunction with SpriteBatch and similar classes.

Parameters:
vec - the position in object/world space.

project

public void project(Vector3 vec,
                    float viewportX,
                    float viewportY,
                    float viewportWidth,
                    float viewportHeight)
Projects the Vector3 given in object/world space to window coordinates. It's the same as GLU gluProject with one small deviation: The viewport is assumed to span the whole screen. The window coordinate system has its origin in the bottom left, with the y-axis pointing upwards and the x-axis pointing to the right. This makes it easily useable in conjunction with SpriteBatch and similar classes. This method allows you to specify the viewport position and dimensions in the coordinate system expected by GLCommon.glViewport(int, int, int, int), with the origin in the bottom left corner of the screen.

Parameters:
vec - the point in object/world space
viewportX - the coordinate of the top left corner of the viewport in glViewport coordinates (origin bottom left)
viewportY - the coordinate of the top left corner of the viewport in glViewport coordinates (origin bottom left)
viewportWidth - the width of the viewport in pixels
viewportHeight - the height of the viewport in pixels

getPickRay

public Ray getPickRay(float x,
                      float y,
                      float viewportX,
                      float viewportY,
                      float viewportWidth,
                      float viewportHeight)
Creates a picking Ray from the coordinates given in window coordinates. It is assumed that the viewport spans the whole screen. The window coordinates origin is assumed to be in the top left corner, its y-axis pointing down, the x-axis pointing to the right. The returned instance is not a new instance but an internal member only accessible via this function.

Parameters:
x - the x-coordinate in window coordinates.
y - the y-coordinate in window coordinates.
Returns:
the picking Ray.

getPickRay

public Ray getPickRay(float x,
                      float y)
Creates a picking Ray from the coordinates given in window coordinates. It is assumed that the viewport spans the whole screen. The window coordinates origin is assumed to be in the top left corner, its y-axis pointing down, the x-axis pointing to the right. The returned instance is not a new instance but an internal member only accessible via this function.

Parameters:
x - the x-coordinate in window coordinates.
y - the y-coordinate in window coordinates.
Returns:
the picking Ray.


Copyright © 2013. All Rights Reserved.