Package com.badlogic.gdx.graphics
Class Camera
- java.lang.Object
-
- com.badlogic.gdx.graphics.Camera
-
- Direct Known Subclasses:
OrthographicCamera,PerspectiveCamera
public abstract class Camera extends java.lang.ObjectBase class forOrthographicCameraandPerspectiveCamera.
-
-
Field Summary
Fields Modifier and Type Field Description Matrix4combinedthe combined projection and view matrixVector3directionthe unit length direction vector of the camerafloatfarthe far clipping plane distance, has to be positiveFrustumfrustumthe frustumMatrix4invProjectionViewthe inverse combined projection and view matrixfloatnearthe near clipping plane distance, has to be positiveVector3positionthe position of the cameraMatrix4projectionthe projection matrixVector3upthe unit length up vector of the cameraMatrix4viewthe view matrixfloatviewportHeightthe viewport heightfloatviewportWidththe viewport width
-
Constructor Summary
Constructors Constructor Description Camera()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description RaygetPickRay(float screenX, float screenY)Creates a pickingRayfrom the coordinates given in screen coordinates.RaygetPickRay(float screenX, float screenY, float viewportX, float viewportY, float viewportWidth, float viewportHeight)Creates a pickingRayfrom the coordinates given in screen coordinates.voidlookAt(float x, float y, float z)Recalculates the direction of the camera to look at the point (x, y, z).voidlookAt(Vector3 target)Recalculates the direction of the camera to look at the point (x, y, z).voidnormalizeUp()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.Vector3project(Vector3 worldCoords)Projects theVector3given in world space to screen coordinates.Vector3project(Vector3 worldCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight)Projects theVector3given in world space to screen coordinates.voidrotate(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.voidrotate(Matrix4 transform)Rotates the direction and up vector of this camera by the given rotation matrix.voidrotate(Quaternion quat)Rotates the direction and up vector of this camera by the givenQuaternion.voidrotate(Vector3 axis, float angle)Rotates the direction and up vector of this camera by the given angle around the given axis.voidrotateAround(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.voidtransform(Matrix4 transform)Transform the position, direction and up vector by the given matrixvoidtranslate(float x, float y, float z)Moves the camera by the given amount on each axis.voidtranslate(Vector3 vec)Moves the camera by the given vector.Vector3unproject(Vector3 screenCoords)Function to translate a point given in screen coordinates to world space.Vector3unproject(Vector3 screenCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight)Function to translate a point given in screen coordinates to world space.abstract voidupdate()Recalculates the projection and view matrix of this camera and theFrustumplanes.abstract voidupdate(boolean updateFrustum)Recalculates the projection and view matrix of this camera and theFrustumplanes ifupdateFrustumis true.
-
-
-
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
-
-
Method Detail
-
update
public abstract void update()
Recalculates the projection and view matrix of this camera and theFrustumplanes. 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 theFrustumplanes ifupdateFrustumis 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 aty- the y-coordinate of the point to look atz- the z-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 angleaxisX- the x-component of the axisaxisY- the y-component of the axisaxisZ- 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 aroundangle- the angle, in degrees
-
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 givenQuaternion. 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 toaxis- the axis to rotate aroundangle- the angle, in degrees
-
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-axisy- the displacement on the y-axisz- 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 inInput. 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 byGL20.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 pixelsviewportHeight- the height of the viewport in pixels- Returns:
- the mutated and unprojected screenCoords
Vector3
-
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 fromGraphics.getWidth()andGraphics.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 inInput. 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- Returns:
- the mutated and unprojected screenCoords
Vector3
-
project
public Vector3 project(Vector3 worldCoords)
Projects theVector3given 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 withBatchand similar classes.- Returns:
- the mutated and projected worldCoords
Vector3
-
project
public Vector3 project(Vector3 worldCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight)
Projects theVector3given 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 withBatchand similar classes. This method allows you to specify the viewport position and dimensions in the coordinate system expected byGL20.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 pixelsviewportHeight- the height of the viewport in pixels- Returns:
- the mutated and projected worldCoords
Vector3
-
getPickRay
public Ray getPickRay(float screenX, float screenY, float viewportX, float viewportY, float viewportWidth, float viewportHeight)
Creates a pickingRayfrom 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 pixelsviewportHeight- the height of the viewport in pixels- Returns:
- the picking Ray.
-
getPickRay
public Ray getPickRay(float screenX, float screenY)
Creates a pickingRayfrom 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.
-
-