Package com.ardor3d.renderer
Class Camera
java.lang.Object
com.ardor3d.renderer.Camera
- All Implemented Interfaces:
Savable
,Externalizable
,Serializable
- Direct Known Subclasses:
ExtendedCamera
,PSSMCamera
,StereoCamera
,TextureProjector
This class represents a view into a 3d scene and how that view should map to a 2D rendering surface.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
static enum
Projection mode used by the camera. -
Field Summary
Modifier and TypeFieldDescriptionprotected double[]
protected double[]
protected double[]
protected double[]
protected boolean
protected double
The far range for mapping depth values from normalized device coordinates to window coordinates.protected double
The near range for mapping depth values from normalized device coordinates to window coordinates.protected final Vector3
Direction the camera is facing.protected double
Convenience store for fovY.protected boolean
protected double
Distance from camera to bottom frustum plane.protected boolean
protected double
Distance from camera to far frustum plane.protected double
Distance from camera to left frustum plane.protected double
Distance from camera to near frustum plane.protected double
Distance from camera to right frustum plane.protected double
Distance from camera to top frustum plane.protected int
protected final Vector3
Direction of camera's 'left'protected final Vector3
Camera's locationprotected final FloatBuffer
protected final Matrix4
protected int
Number of camera planes used by this camera.protected final Matrix4
protected final Vector3
Computation vector used in various operations.protected final Vector3
Direction of 'up' for camera.protected double
Percent value on display where vertical viewing begins for this camera.protected boolean
protected double
Percent value on display where horizontal viewing starts for this camera.protected double
Percent value on display where horizontal viewing ends for this camera.protected double
Percent value on display where vertical viewing ends for this camera.protected int
protected Plane[]
Array holding the planes that this camera will check for culling.static final int
BOTTOM_PLANE represents the bottom plane of the camera frustum.static final int
FAR_PLANE represents the far plane of the camera frustum.static final int
FRUSTUM_PLANES represents the number of planes of the camera frustum.static final int
LEFT_PLANE represents the left plane of the camera frustum.static final int
MAX_WORLD_PLANES holds the maximum planes allowed by the system.static final int
NEAR_PLANE represents the near plane of the camera frustum.static final int
RIGHT_PLANE represents the right plane of the camera frustum.static final int
TOP_PLANE represents the top plane of the camera frustum. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Apply this camera's values to the given Renderer.protected void
applyModelViewMatrix
(Renderer renderer) Apply the camera's modelview matrix using the given Renderer.protected void
applyProjectionMatrix
(Renderer renderer) Apply the camera's projection matrix using the given Renderer.protected void
applyViewport
(Renderer renderer) Apply the camera's viewport using the given Renderer.contains
(BoundingVolume bound) Checks a bounding volume against the planes of this camera's frustum and returns if it is completely inside of, outside of, or intersecting.static Camera
Convenience method for retrieving the Camera set on the current RenderContext.double
double
double
getFovY()
Accessor for the fovY value.double
getFrustumCoordinates
(ReadOnlyVector3 worldPos) Converts a position in world coordinate space to a x,y,z frustum position using the current settings of this camera.getFrustumCoordinates
(ReadOnlyVector3 worldPosition, Vector3 store) Converts a position in world coordinate space to a x,y,z frustum position using the current settings of this camera.double
double
double
double
double
int
getLeft()
getNormalizedDeviceCoordinates
(ReadOnlyVector3 worldPosition, Vector3 store) getPickRay
(ReadOnlyVector2 screenPosition, boolean flipVertical, Ray3 store) Calculate a Pick Ray using the given screen position at the near plane of this camera and the camera's position in space.int
getScreenCoordinates
(ReadOnlyVector3 worldPos) Converts a position in world coordinate space to an x,y screen position and depth value using the current settings of this camera.getScreenCoordinates
(ReadOnlyVector3 worldPosition, Vector3 store) Converts a position in world coordinate space to an x,y screen position and depth value using the current settings of this camera.getUp()
double
double
double
double
int
getWidth()
getWorldCoordinates
(ReadOnlyVector2 screenPosition, double zDepth) Converts a local x,y screen position and depth value to world coordinates based on the current settings of this camera.getWorldCoordinates
(ReadOnlyVector2 screenPosition, double zDepth, Vector3 store) Converts a local x,y screen position and depth value to world coordinates based on the current settings of this camera.boolean
void
lookAt
(double x, double y, double z, ReadOnlyVector3 worldUpVector) A convenience method for auto-setting the frame based on a world position the user desires the camera to look at.void
lookAt
(ReadOnlyVector3 pos, ReadOnlyVector3 worldUpVector) A convenience method for auto-setting the frame based on a world position the user desires the camera to look at.void
Ensure our up, left and direction are unit-length vectors.void
Updates the values of the world planes associated with this camera.void
Updates internal frustum coefficient values to reflect the current frustum plane values.protected void
Mark view port dirty.void
read
(InputCapsule capsule) void
void
resize
(int width, int height) Resizes this camera's view with the given width and height.void
Copy the source camera's fields to this cameravoid
setAxes
(ReadOnlyMatrix3 axes) Sets our left, up and direction values from the given rotation matrix.void
setAxes
(ReadOnlyVector3 left, ReadOnlyVector3 up, ReadOnlyVector3 direction) void
setDepthRangeFar
(double depthRangeFar) void
setDepthRangeNear
(double depthRangeNear) void
setDirection
(ReadOnlyVector3 direction) Sets the new direction this camera is facing.void
setFrame
(ReadOnlyVector3 location, ReadOnlyMatrix3 axes) Sets the axes and location of the camera.void
setFrame
(ReadOnlyVector3 location, ReadOnlyVector3 left, ReadOnlyVector3 up, ReadOnlyVector3 direction) Sets the axes and location of the camera.void
Sets the axes and location of the camera using those of a given source cameravoid
setFrustum
(double near, double far, double left, double right, double top, double bottom) Sets the frustum plane values of this camera using the given values.void
setFrustum
(Camera source) Sets the frustum plane values of this camera using those of a given source cameravoid
setFrustumBottom
(double frustumBottom) void
setFrustumFar
(double frustumFar) void
setFrustumLeft
(double frustumLeft) void
setFrustumNear
(double frustumNear) void
setFrustumPerspective
(double fovY, double aspect, double near, double far) Sets the frustum plane values of this camera using the given perspective values.void
setFrustumRight
(double frustumRight) void
setFrustumTop
(double frustumTop) void
setLeft
(ReadOnlyVector3 left) Sets the new left axis of this camera.void
setLocation
(double x, double y, double z) void
setLocation
(ReadOnlyVector3 location) void
setPlaneState
(int planeState) void
setProjectionMatrix
(ReadOnlyMatrix4 projection) void
setProjectionMode
(Camera.ProjectionMode projectionMode) void
setUp
(ReadOnlyVector3 up) Sets the new up axis of this camera.void
setViewPort
(double left, double right, double bottom, double top) Sets the boundaries of this camera's viewport to the given valuesvoid
setViewPortBottom
(double bottom) void
setViewPortLeft
(double left) void
setViewPortRight
(double right) void
setViewPortTop
(double top) toString()
void
update()
Forces all aspect of the camera to be updated from internal values, and sets all dirty flags to true so that the next apply() call will fully set this camera to the render context.protected void
Updates the value of our model view matrix.protected void
Updates the value of our projection matrix.void
write
(OutputCapsule capsule) void
-
Field Details
-
LEFT_PLANE
public static final int LEFT_PLANELEFT_PLANE represents the left plane of the camera frustum.- See Also:
-
RIGHT_PLANE
public static final int RIGHT_PLANERIGHT_PLANE represents the right plane of the camera frustum.- See Also:
-
BOTTOM_PLANE
public static final int BOTTOM_PLANEBOTTOM_PLANE represents the bottom plane of the camera frustum.- See Also:
-
TOP_PLANE
public static final int TOP_PLANETOP_PLANE represents the top plane of the camera frustum.- See Also:
-
FAR_PLANE
public static final int FAR_PLANEFAR_PLANE represents the far plane of the camera frustum.- See Also:
-
NEAR_PLANE
public static final int NEAR_PLANENEAR_PLANE represents the near plane of the camera frustum.- See Also:
-
FRUSTUM_PLANES
public static final int FRUSTUM_PLANESFRUSTUM_PLANES represents the number of planes of the camera frustum.- See Also:
-
MAX_WORLD_PLANES
public static final int MAX_WORLD_PLANESMAX_WORLD_PLANES holds the maximum planes allowed by the system.- See Also:
-
_location
Camera's location -
_left
Direction of camera's 'left' -
_up
Direction of 'up' for camera. -
_direction
Direction the camera is facing. -
_depthRangeNear
protected double _depthRangeNearThe near range for mapping depth values from normalized device coordinates to window coordinates. -
_depthRangeFar
protected double _depthRangeFarThe far range for mapping depth values from normalized device coordinates to window coordinates. -
_frustumNear
protected double _frustumNearDistance from camera to near frustum plane. -
_frustumFar
protected double _frustumFarDistance from camera to far frustum plane. -
_frustumLeft
protected double _frustumLeftDistance from camera to left frustum plane. -
_frustumRight
protected double _frustumRightDistance from camera to right frustum plane. -
_frustumTop
protected double _frustumTopDistance from camera to top frustum plane. -
_frustumBottom
protected double _frustumBottomDistance from camera to bottom frustum plane. -
_fovY
protected double _fovYConvenience store for fovY. Only set during setFrustumPerspective and never used. Retrieve by getFovY(). Default is NaN. -
_coeffLeft
protected double[] _coeffLeft -
_coeffRight
protected double[] _coeffRight -
_coeffBottom
protected double[] _coeffBottom -
_coeffTop
protected double[] _coeffTop -
_planeQuantity
protected int _planeQuantityNumber of camera planes used by this camera. Default is 6. -
_viewPortLeft
protected double _viewPortLeftPercent value on display where horizontal viewing starts for this camera. Default is 0. -
_viewPortRight
protected double _viewPortRightPercent value on display where horizontal viewing ends for this camera. Default is 1. -
_viewPortTop
protected double _viewPortTopPercent value on display where vertical viewing ends for this camera. Default is 1. -
_viewPortBottom
protected double _viewPortBottomPercent value on display where vertical viewing begins for this camera. Default is 0. -
_worldPlane
Array holding the planes that this camera will check for culling. -
_matrixBuffer
-
_tempVector
Computation vector used in various operations. -
_modelView
-
_projection
-
_depthRangeDirty
protected boolean _depthRangeDirty -
_frustumDirty
protected boolean _frustumDirty -
_viewPortDirty
protected boolean _viewPortDirty -
_frameDirty
protected boolean _frameDirty -
_width
protected int _width -
_height
protected int _height
-
-
Constructor Details
-
Camera
public Camera()Construct a new Camera with a width and height of 100. -
Camera
public Camera(int width, int height) Construct a new Camera with the given frame width and height.- Parameters:
width
- the widthheight
- the height
-
Camera
Construct a new camera, using the given source camera's values.- Parameters:
source
- the source camera to copy from
-
-
Method Details
-
set
Copy the source camera's fields to this camera- Parameters:
source
- the camera to copy from
-
getDepthRangeFar
public double getDepthRangeFar() -
setDepthRangeFar
public void setDepthRangeFar(double depthRangeFar) - Parameters:
depthRangeFar
- the far clipping plane for window coordinates. Should be in the range [0, 1]. Default is 1.
-
getDepthRangeNear
public double getDepthRangeNear() -
setDepthRangeNear
public void setDepthRangeNear(double depthRangeNear) - Parameters:
depthRangeNear
- the near clipping plane for window coordinates. Should be in the range [0, 1]. Default is 0.
-
getFrustumBottom
public double getFrustumBottom()- Returns:
- the value of the bottom frustum plane.
-
setFrustumBottom
public void setFrustumBottom(double frustumBottom) - Parameters:
frustumBottom
- the new value of the bottom frustum plane.
-
getFrustumFar
public double getFrustumFar()- Returns:
- the value of the far frustum plane.
-
setFrustumFar
public void setFrustumFar(double frustumFar) - Parameters:
frustumFar
- the new value of the far frustum plane.
-
getFrustumLeft
public double getFrustumLeft()- Returns:
- the value of the left frustum plane.
-
setFrustumLeft
public void setFrustumLeft(double frustumLeft) - Parameters:
frustumLeft
- the new value of the left frustum plane.
-
getFrustumNear
public double getFrustumNear()- Returns:
- the value of the near frustum plane.
-
setFrustumNear
public void setFrustumNear(double frustumNear) - Parameters:
frustumNear
- the new value of the near frustum plane.
-
getFrustumRight
public double getFrustumRight()- Returns:
- frustumRight the value of the right frustum plane.
-
setFrustumRight
public void setFrustumRight(double frustumRight) - Parameters:
frustumRight
- the new value of the right frustum plane.
-
getFrustumTop
public double getFrustumTop()- Returns:
- the value of the top frustum plane.
-
setFrustumTop
public void setFrustumTop(double frustumTop) - Parameters:
frustumTop
- the new value of the top frustum plane.
-
getLocation
- Returns:
- the current position of the camera.
-
getDirection
- Returns:
- the current direction the camera is facing.
-
getLeft
- Returns:
- the left axis of the camera.
-
getUp
- Returns:
- the up axis of the camera.
-
setLocation
- Parameters:
location
- the new location or position of the camera.
-
setLocation
public void setLocation(double x, double y, double z) - Parameters:
x
- the new x location or position of the camera.y
- the new y location or position of the camera.z
- the new z location or position of the camera.
-
setDirection
Sets the new direction this camera is facing. This does not change left or up axes, so make sure those vectors are properly set as well.- Parameters:
direction
- the new direction this camera is facing.
-
setLeft
Sets the new left axis of this camera. This does not change direction or up axis, so make sure those vectors are properly set as well.- Parameters:
left
- the new left axis of this camera.
-
setUp
Sets the new up axis of this camera. This does not change direction or left axis, so make sure those vectors are properly set as well.- Parameters:
up
- the new up axis of this camera.
-
setAxes
- Parameters:
left
- the new left axis of the camera.up
- the new up axis of the camera.direction
- the new direction the camera is facing.
-
setAxes
Sets our left, up and direction values from the given rotation matrix.- Parameters:
axes
- the matrix that defines the orientation of the camera.
-
normalize
public void normalize()Ensure our up, left and direction are unit-length vectors. -
setFrustum
public void setFrustum(double near, double far, double left, double right, double top, double bottom) Sets the frustum plane values of this camera using the given values.- Parameters:
near
- our near plane valuefar
- our far plane valueleft
- our left plane valueright
- our right plane valuetop
- our top plane valuebottom
- our bottom plane value
-
setFrustum
Sets the frustum plane values of this camera using those of a given source camera- Parameters:
source
- a source camera.
-
setFrustumPerspective
public void setFrustumPerspective(double fovY, double aspect, double near, double far) Sets the frustum plane values of this camera using the given perspective values.- Parameters:
fovY
- the full angle of view on the Y axis, in degrees.aspect
- the aspect ratio of our view (generally in [0,1]). Often this is canvas width / canvas height.near
- our near plane valuefar
- our far plane value
-
getFovY
public double getFovY()Accessor for the fovY value. Note that this value is only present if setFrustumPerspective was previously called.- Returns:
- the fovY value
-
setFrame
public void setFrame(ReadOnlyVector3 location, ReadOnlyVector3 left, ReadOnlyVector3 up, ReadOnlyVector3 direction) Sets the axes and location of the camera. Similar tosetAxes(ReadOnlyVector3, ReadOnlyVector3, ReadOnlyVector3)
, but sets camera location as well.- Parameters:
location
- the point position of the cameraleft
- the left vector of the camera's orientationup
- the up vector of the camera's orientationdirection
- the direction vector of the camera's orientation
-
setFrame
Sets the axes and location of the camera. Similar tosetAxes(ReadOnlyMatrix3)
, but sets camera location as well.- Parameters:
location
- the point position of the camera.axes
- the orientation of the camera.
-
setFrame
Sets the axes and location of the camera using those of a given source camera- Parameters:
source
- a source camera.
-
lookAt
A convenience method for auto-setting the frame based on a world position the user desires the camera to look at. It points the camera towards the given position using the difference between that position and the current camera location as a direction vector and the general worldUpVector to compute up and left camera vectors.- Parameters:
pos
- where to look at in terms of world coordinatesworldUpVector
- a normalized vector indicating the up direction of the world. (oftenVector3.UNIT_Y
orVector3.UNIT_Z
)
-
lookAt
A convenience method for auto-setting the frame based on a world position the user desires the camera to look at. It points the camera towards the given position using the difference between that position and the current camera location as a direction vector and the general worldUpVector to compute up and left camera vectors.- Parameters:
x
- where to look at in terms of world coordinates (x)y
- where to look at in terms of world coordinates (y)z
- where to look at in terms of world coordinates (z)worldUpVector
- a normalized vector indicating the up direction of the world. (oftenVector3.UNIT_Y
orVector3.UNIT_Z
)
-
update
public void update()Forces all aspect of the camera to be updated from internal values, and sets all dirty flags to true so that the next apply() call will fully set this camera to the render context. -
getPlaneState
public int getPlaneState()- Returns:
- an internally used bitmask describing what frustum planes have been examined for culling thus far.
-
setPlaneState
public void setPlaneState(int planeState) - Parameters:
planeState
- a new value for planeState.- See Also:
-
getViewPortLeft
public double getViewPortLeft()- Returns:
- the left boundary of the viewport
-
setViewPortLeft
public void setViewPortLeft(double left) - Parameters:
left
- the new left boundary of the viewport
-
getViewPortRight
public double getViewPortRight()- Returns:
- the right boundary of the viewport
-
setViewPortRight
public void setViewPortRight(double right) - Parameters:
right
- the new right boundary of the viewport
-
getViewPortTop
public double getViewPortTop()- Returns:
- the top boundary of the viewport
-
setViewPortTop
public void setViewPortTop(double top) - Parameters:
top
- the new top boundary of the viewport
-
getViewPortBottom
public double getViewPortBottom()- Returns:
- the bottom boundary of the viewport
-
setViewPortBottom
public void setViewPortBottom(double bottom) - Parameters:
bottom
- the new bottom boundary of the viewport
-
setViewPort
public void setViewPort(double left, double right, double bottom, double top) Sets the boundaries of this camera's viewport to the given values- Parameters:
left
- the new left boundary of the viewportright
- the new right boundary of the viewportbottom
- the new bottom boundary of the viewporttop
- the new top boundary of the viewport
-
contains
Checks a bounding volume against the planes of this camera's frustum and returns if it is completely inside of, outside of, or intersecting.- Parameters:
bound
- the bound to check for culling- Returns:
- intersection type
-
resize
public void resize(int width, int height) Resizes this camera's view with the given width and height.- Parameters:
width
- the view widthheight
- the view height
-
onFrustumChange
public void onFrustumChange()Updates internal frustum coefficient values to reflect the current frustum plane values. -
onFrameChange
public void onFrameChange()Updates the values of the world planes associated with this camera. -
updateProjectionMatrix
protected void updateProjectionMatrix()Updates the value of our projection matrix. -
setProjectionMatrix
-
getProjectionMatrix
- Returns:
- this camera's 4x4 projection matrix.
-
updateModelViewMatrix
protected void updateModelViewMatrix()Updates the value of our model view matrix. -
getModelViewMatrix
- Returns:
- this camera's 4x4 model view matrix.
-
getModelViewProjectionMatrix
- Returns:
- this camera's 4x4 model view X projection matrix.
-
getModelViewProjectionInverseMatrix
- Returns:
- the inverse of this camera's 4x4 model view X projection matrix.
-
getPickRay
Calculate a Pick Ray using the given screen position at the near plane of this camera and the camera's position in space.- Parameters:
screenPosition
- the x, y position on the near space to pass the ray through.flipVertical
- if true, we'll flip the screenPosition on the y axis. This is useful when you are dealing with non-opengl coordinate systems.store
- the Ray to store the result in. If false, a new Ray is created and returned.- Returns:
- the resulting Ray.
-
getWorldCoordinates
Converts a local x,y screen position and depth value to world coordinates based on the current settings of this camera.- Parameters:
screenPosition
- the x,y coordinates of the screen positionzDepth
- the depth into the camera view to take our point. 0 indicates the near plane of the camera and 1 indicates the far plane.- Returns:
- a new vector containing the world coordinates.
-
getWorldCoordinates
Converts a local x,y screen position and depth value to world coordinates based on the current settings of this camera.- Parameters:
screenPosition
- the x,y coordinates of the screen positionzDepth
- the depth into the camera view to take our point. 0 indicates the near plane of the camera and 1 indicates the far plane.store
- Use to avoid object creation. if not null, the results are stored in the given vector and returned. Otherwise, a new vector is created.- Returns:
- a vector containing the world coordinates.
-
getScreenCoordinates
Converts a position in world coordinate space to an x,y screen position and depth value using the current settings of this camera.- Parameters:
worldPos
- the position in space to retrieve screen coordinates for.- Returns:
- a new vector containing the screen coordinates as x and y and the distance as a percent between near and far planes.
-
getScreenCoordinates
Converts a position in world coordinate space to an x,y screen position and depth value using the current settings of this camera.- Parameters:
worldPosition
- the position in space to retrieve screen coordinates for.store
- Use to avoid object creation. if not null, the results are stored in the given vector and returned. Otherwise, a new vector is created.- Returns:
- a vector containing the screen coordinates as x and y and the distance as a percent between near and far planes.
-
getFrustumCoordinates
Converts a position in world coordinate space to a x,y,z frustum position using the current settings of this camera.- Parameters:
worldPos
- the position in space to retrieve frustum coordinates for.- Returns:
- a new vector containing the x,y,z frustum position
-
getFrustumCoordinates
Converts a position in world coordinate space to a x,y,z frustum position using the current settings of this camera.- Parameters:
worldPosition
- the position in space to retrieve frustum coordinates for.store
- Use to avoid object creation. if not null, the results are stored in the given vector and returned. Otherwise, a new vector is created.- Returns:
- a vector containing the x,y,z frustum position
-
getNormalizedDeviceCoordinates
-
getNormalizedDeviceCoordinates
-
getHeight
public int getHeight()- Returns:
- the height of the display.
-
getProjectionMode
-
setProjectionMode
-
getWidth
public int getWidth()- Returns:
- the width of the display.
-
apply
Apply this camera's values to the given Renderer. Only values determined to be dirty (via updates, setters, etc.) will be applied. This method must be run in the same thread as a valid OpenGL context.- Parameters:
renderer
- the Renderer to use.
-
onViewPortChange
protected void onViewPortChange()Mark view port dirty. -
applyProjectionMatrix
Apply the camera's projection matrix using the given Renderer.- Parameters:
renderer
- the Renderer to use.
-
applyViewport
Apply the camera's viewport using the given Renderer.- Parameters:
renderer
- the Renderer to use.
-
applyModelViewMatrix
Apply the camera's modelview matrix using the given Renderer.- Parameters:
renderer
- the Renderer to use.
-
write
- Specified by:
write
in interfaceSavable
- Throws:
IOException
-
read
- Specified by:
read
in interfaceSavable
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
toString
-
getClassTag
- Specified by:
getClassTag
in interfaceSavable
-
getCurrentCamera
Convenience method for retrieving the Camera set on the current RenderContext. Similar to ContextManager.getCurrentContext().getCurrentCamera() but with null checks for current context.- Returns:
- the Camera on the current RenderContext.
-
isFrameDirty
public boolean isFrameDirty()
-