APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.graphics

public abstract Class Camera

extends Object
Class Inheritance
Known Direct Subclasses
com.badlogic.gdx.graphics.OrthographicCamera, com.badlogic.gdx.graphics.PerspectiveCamera
Imports
com.badlogic.gdx.Gdx, .Graphics, .Input, com.badlogic.gdx.graphics.g2d.Batch, com.badlogic.gdx.math.Frustum, .Matrix4, .Quaternion, .Vector3, com.badlogic.gdx.math.collision.Ray

Base class for OrthographicCamera and PerspectiveCamera.
Author
mzechner

Field Summary

Modifier and TypeField and Description
public final Matrix4
combined

the combined projection and view matrix

public final Vector3
direction

the unit length direction vector of the camera

public float
far

the far clipping plane distance, has to be positive

public final Frustum
frustum

the frustum

public final Matrix4
invProjectionView

the inverse combined projection and view matrix

public float
near

the near clipping plane distance, has to be positive

public final Vector3
position

the position of the camera

public final Matrix4
projection

the projection matrix

private final Ray
private final Vector3
public final Vector3
up

the unit length up vector of the camera

public final Matrix4
view

the view matrix

public float
viewportHeight

the viewport height

public float
viewportWidth

the viewport width

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Ray

Returns:

the picking Ray.
getPickRay
(float touchX, float touchY, float
the coordinate of the bottom left corner of the viewport in glViewport coordinates.
viewportX
,
float
the coordinate of the bottom left corner of the viewport in glViewport coordinates.
viewportY
,
float
the width of the viewport in pixels
viewportWidth
,
float
the height of the viewport in pixels
viewportHeight
)

Creates a picking Ray from the coordinates given in touch coordinates.

public Ray

Returns:

the picking Ray.
getPickRay
(float touchX, float touchY)

Creates a picking Ray from the coordinates given in touch coordinates.

public void
lookAt(float
the x-coordinate of the point to look at
x
,
float
the y-coordinate of the point to look at
y
,
float
the z-coordinate of the point to look at
z
)

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

public void
lookAt(Vector3
the point to look at
target
)

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

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.

public Vector3

Returns:

the mutated and projected worldCoords Vector3
project
(Vector3 worldCoords)

Projects the Vector3 given in world space to screen coordinates.

public Vector3

Returns:

the mutated and projected worldCoords Vector3
project
(Vector3 worldCoords, float
the coordinate of the bottom left corner of the viewport in glViewport coordinates.
viewportX
,
float
the coordinate of the bottom left corner of the viewport in glViewport coordinates.
viewportY
,
float
the width of the viewport in pixels
viewportWidth
,
float
the height of the viewport in pixels
viewportHeight
)

Projects the Vector3 given in world space to screen coordinates.

public void
rotate(float
the angle
angle
,
float
the x-component of the axis
axisX
,
float
the y-component of the axis
axisY
,
float
the z-component of the axis
axisZ
)

Rotates the direction and up vector of this camera by the given angle around the given axis.

public void
rotate(Vector3
the axis to rotate around
axis
,
float
the angle, in degrees
angle
)

Rotates the direction and up vector of this camera by the given angle around the given axis.

public void
rotate(final Matrix4
The rotation matrix
transform
)

Rotates the direction and up vector of this camera by the given rotation matrix.

public void
rotate(final Quaternion
The quaternion
quat
)

Rotates the direction and up vector of this camera by the given Quaternion.

public void
rotateAround(Vector3
the point to attach the axis to
point
,
Vector3
the axis to rotate around
axis
,
float
the angle, in degrees
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.

public void
transform(final Matrix4
The transform matrix
transform
)

Transform the position, direction and up vector by the given matrix

public void
translate(float
the displacement on the x-axis
x
,
float
the displacement on the y-axis
y
,
float
the displacement on the z-axis
z
)

Moves the camera by the given amount on each axis.

public void
translate(Vector3
the displacement vector
vec
)

Moves the camera by the given vector.

public Vector3

Returns:

the mutated and unprojected touchCoords Vector3
unproject
(Vector3
the point in touch coordinates (origin top left)
touchCoords
,
float
the coordinate of the bottom left corner of the viewport in glViewport coordinates.
viewportX
,
float
the coordinate of the bottom left corner of the viewport in glViewport coordinates.
viewportY
,
float
the width of the viewport in pixels
viewportWidth
,
float
the height of the viewport in pixels
viewportHeight
)

Function to translate a point given in touch coordinates to world space.

public Vector3

Returns:

the mutated and unprojected touchCoords Vector3
unproject
(Vector3
the point in touch coordinates
touchCoords
)

Function to translate a point given in touch coordinates to world space.

public abstract void
update()

Recalculates the projection and view matrix of this camera and the Frustum planes.

public abstract void
update(boolean updateFrustum)

Recalculates the projection and view matrix of this camera and the Frustum planes if updateFrustum is true.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

combinedback to summary
public final Matrix4 combined

the combined projection and view matrix

directionback to summary
public final Vector3 direction

the unit length direction vector of the camera

farback to summary
public float far

the far clipping plane distance, has to be positive

frustumback to summary
public final Frustum frustum

the frustum

invProjectionViewback to summary
public final Matrix4 invProjectionView

the inverse combined projection and view matrix

nearback to summary
public float near

the near clipping plane distance, has to be positive

positionback to summary
public final Vector3 position

the position of the camera

projectionback to summary
public final Matrix4 projection

the projection matrix

rayback to summary
private final Ray ray
tmpVecback to summary
private final Vector3 tmpVec
upback to summary
public final Vector3 up

the unit length up vector of the camera

viewback to summary
public final Matrix4 view

the view matrix

viewportHeightback to summary
public float viewportHeight

the viewport height

viewportWidthback to summary
public float viewportWidth

the viewport width

Constructor Detail

Cameraback to summary
public Camera()

Method Detail

getPickRayback to summary
public Ray getPickRay(float touchX, float touchY, float viewportX, float viewportY, float viewportWidth, float viewportHeight)

Creates a picking Ray from the coordinates given in touch coordinates. It is assumed that the viewport spans the whole screen. The touch 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:float

the coordinate of the bottom left corner of the viewport in glViewport coordinates.

viewportY:float

the coordinate of the bottom left corner of the viewport in glViewport coordinates.

viewportWidth:float

the width of the viewport in pixels

viewportHeight:float

the height of the viewport in pixels

Returns:Ray

the picking Ray.

getPickRayback to summary
public Ray getPickRay(float touchX, float touchY)

Creates a picking Ray from the coordinates given in touch coordinates. It is assumed that the viewport spans the whole screen. The touch 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:Ray

the picking Ray.

lookAtback to summary
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:float

the x-coordinate of the point to look at

y:float

the y-coordinate of the point to look at

z:float

the z-coordinate of the point to look at

lookAtback to summary
public void lookAt(Vector3 target)

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

Parameters
target:Vector3

the point to look at

normalizeUpback to summary
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.

projectback to summary
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.

Returns:Vector3

the mutated and projected worldCoords Vector3

projectback to summary
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:float

the coordinate of the bottom left corner of the viewport in glViewport coordinates.

viewportY:float

the coordinate of the bottom left corner of the viewport in glViewport coordinates.

viewportWidth:float

the width of the viewport in pixels

viewportHeight:float

the height of the viewport in pixels

Returns:Vector3

the mutated and projected worldCoords Vector3

rotateback to summary
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:float

the angle

axisX:float

the x-component of the axis

axisY:float

the y-component of the axis

axisZ:float

the z-component of the axis

rotateback to summary
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:Vector3

the axis to rotate around

angle:float

the angle, in degrees

rotateback to summary
public void rotate(final 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:Matrix4

The rotation matrix

rotateback to summary
public void rotate(final 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:Quaternion

The quaternion

rotateAroundback to summary
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:Vector3

the point to attach the axis to

axis:Vector3

the axis to rotate around

angle:float

the angle, in degrees

transformback to summary
public void transform(final Matrix4 transform)

Transform the position, direction and up vector by the given matrix

Parameters
transform:Matrix4

The transform matrix

translateback to summary
public void translate(float x, float y, float z)

Moves the camera by the given amount on each axis.

Parameters
x:float

the displacement on the x-axis

y:float

the displacement on the y-axis

z:float

the displacement on the z-axis

translateback to summary
public void translate(Vector3 vec)

Moves the camera by the given vector.

Parameters
vec:Vector3

the displacement vector

unprojectback to summary
public Vector3 unproject(Vector3 touchCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight)

Function to translate a point given in touch 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 touch 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
touchCoords:Vector3

the point in touch coordinates (origin top left)

viewportX:float

the coordinate of the bottom left corner of the viewport in glViewport coordinates.

viewportY:float

the coordinate of the bottom left corner of the viewport in glViewport coordinates.

viewportWidth:float

the width of the viewport in pixels

viewportHeight:float

the height of the viewport in pixels

Returns:Vector3

the mutated and unprojected touchCoords Vector3

unprojectback to summary
public Vector3 unproject(Vector3 touchCoords)

Function to translate a point given in touch 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 touch 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
touchCoords:Vector3

the point in touch coordinates

Returns:Vector3

the mutated and unprojected touchCoords Vector3

updateback to summary
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.

updateback to summary
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.