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
 Ray getPickRay(float screenX, float screenY)
          Creates a picking Ray from the coordinates given in screen coordinates.
 Ray getPickRay(float screenX, float screenY, float viewportX, float viewportY, float viewportWidth, float viewportHeight)
          Creates a picking Ray from the coordinates given in screen 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.
 Vector3 project(Vector3 worldCoords)
          Projects the Vector3 given in world space to screen coordinates.
 Vector3 project(Vector3 worldCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight)
          Projects the Vector3 given in world space to screen 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.
 Vector3 unproject(Vector3 screenCoords)
          Function to translate a point given in screen coordinates to world space.
 Vector3 unproject(Vector3 screenCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight)
          Function to translate a point given in screen 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.


lookAt

public void lookAt(float x,
                   float y,
                   float z)
Recalculates the direction of the camera to look at the point (x, y, z). This function assumes the up vector is normalized.

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 - the axis to rotate around
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 - the point to attach the axis to
axis - the axis to rotate around
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 Vector3 unproject(Vector3 screenCoords,
                         float viewportX,
                         float viewportY,
                         float viewportWidth,
                         float viewportHeight)
Function to translate a point given in screen 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 screen 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 GL20.glViewport(int, int, int, int), with the origin in the bottom left corner of the screen.

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

unproject

public Vector3 unproject(Vector3 screenCoords)
Function to translate a point given in screen 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 screen 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:
screenCoords - the point in screen coordinates

project

public Vector3 project(Vector3 worldCoords)
Projects the Vector3 given in world space to screen coordinates. It's the same as GLU gluProject with one small deviation: The viewport is assumed to span the whole screen. The screen 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 Batch and similar classes.


project

public Vector3 project(Vector3 worldCoords,
                       float viewportX,
                       float viewportY,
                       float viewportWidth,
                       float viewportHeight)
Projects the Vector3 given in world space to screen coordinates. It's the same as GLU gluProject with one small deviation: The viewport is assumed to span the whole screen. The screen 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 Batch and similar classes. This method allows you to specify the viewport position and dimensions in the coordinate system expected by GL20.glViewport(int, int, int, int), with the origin in the bottom left corner of the screen.

Parameters:
viewportX - the coordinate of the bottom left corner of the viewport in glViewport coordinates.
viewportY - the coordinate of the bottom left corner of the viewport in glViewport coordinates.
viewportWidth - the width of the viewport in pixels
viewportHeight - the height of the viewport in pixels

getPickRay

public Ray getPickRay(float screenX,
                      float screenY,
                      float viewportX,
                      float viewportY,
                      float viewportWidth,
                      float viewportHeight)
Creates a picking Ray from the coordinates given in screen coordinates. It is assumed that the viewport spans the whole screen. The screen 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:
viewportX - the coordinate of the bottom left corner of the viewport in glViewport coordinates.
viewportY - the coordinate of the bottom left corner of the viewport in glViewport coordinates.
viewportWidth - the width of the viewport in pixels
viewportHeight - the height of the viewport in pixels
Returns:
the picking Ray.

getPickRay

public Ray getPickRay(float screenX,
                      float screenY)
Creates a picking Ray from the coordinates given in screen coordinates. It is assumed that the viewport spans the whole screen. The screen 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.

Returns:
the picking Ray.


Copyright © 2014. All Rights Reserved.