Package com.jme3.input
Class ChaseCamera
java.lang.Object
com.jme3.input.ChaseCamera
- All Implemented Interfaces:
- Savable,- ActionListener,- AnalogListener,- InputListener,- Control,- JmeCloneable,- Cloneable
public class ChaseCamera
extends Object
implements ActionListener, AnalogListener, Control, JmeCloneable
A camera that follows a spatial and can turn around it by dragging the mouse
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected Cameraprotected booleanstatic final StringDeprecated.static final StringDeprecated.static final StringDeprecated.static final StringDeprecated.static final StringDeprecated.static final StringDeprecated.static final StringDeprecated.protected booleanprotected floatprotected floatprotected floatprotected booleanprotected booleanprotected booleanprotected Vector3fprotected InputManagerprotected booleanprotected booleanprotected booleanprotected Vector3fprotected floatprotected floatprotected floatprotected floatprotected floatprotected final Vector3fprotected floatprotected Vector3fprotected booleanprotected booleanprotected floatprotected floatprotected floatprotected floatprotected booleanprotected Spatialprotected final Vector3fprotected floatprotected Vector3fprotected booleanprotected floatprotected floatprotected Vector3fprotected booleanprotected booleanprotected floatprotected floatprotected floatprotected booleanprotected booleanprotected floatprotected floatprotected booleanprotected booleanprotected float
- 
Constructor SummaryConstructorsConstructorDescriptionChaseCamera(Camera cam) Constructs the chase camera if you use this constructor you have to attach the cam later to a spatial doing spatial.addControl(chaseCamera);ChaseCamera(Camera cam, InputManager inputManager) Constructs the chase camera, and registers inputs if you use this constructor you have to attach the cam later to a spatial doing spatial.addControl(chaseCamera);ChaseCamera(Camera cam, Spatial target) Constructs the chase cameraChaseCamera(Camera cam, Spatial target, InputManager inputManager) Constructs the chase camera, and registers inputs
- 
Method SummaryModifier and TypeMethodDescriptionvoidCleans up the input mappings from the input manager.voidcloneFields(Cloner cloner, Object original) Implemented to perform deep cloning for this object, resolving local cloned references using the specified cloner.cloneForSpatial(Spatial spatial) Deprecated.protected voidfloatreturns the chasing sensitivityfloatreturn the current distance from the camera to the targetbooleanfloatreturns the current horizontal rotation around the target in radiansreturns the offset from the target's position where the camera looks atfloatReturns the max zoom distance of the camera (default is 40)floatfloatReturns the min zoom distance of the camera (default is 1)floatfloatReturns the rotation sensitivityfloatReturns the rotation speed when the mouse is moved.floatreturns the trailing rotation inertiafloatreturns the trailing sensitivityReturns the up vector of the camera used for the lookAt on the targetfloatreturns the current vertical rotation around the target in radians.floatreturns the zoom sensitivitybooleanbooleanReturn the enabled/disabled state of the camerabooleanbooleanbooleanreturns true if the trailing is enabledjmeClone()Performs a regular shallow clone of the object.voidCalled when an input to which this listener is registered to is invoked.voidCalled to notify the implementation that an analog event has occurred.voidread(JmeImporter im) Read the camerafinal voidregisterWithInput(InputManager inputManager) Registers inputs with the input managervoidrender(RenderManager rm, ViewPort vp) renders the camera control, should only be used internallyprotected voidrotateCamera(float value) voidsetChasingSensitivity(float chasingSensitivity) Sets the chasing sensitivity, the lower the value the slower the camera will follow the target when it moves default is 5 Only has an effect if smoothMotion is set to true and trailing is enabledvoidsetDefaultDistance(float defaultDistance) Sets the default distance at start of applicationvoidsetDefaultHorizontalRotation(float angleInRad) sets the default horizontal rotation in radian of the camera at start of the applicationvoidsetDefaultVerticalRotation(float angleInRad) sets the default vertical rotation in radian of the camera at start of the applicationvoidsetDownRotateOnCloseViewOnly(boolean rotateOnlyWhenClose) voidsetDragToRotate(boolean dragToRotate) voidsetEnabled(boolean enabled) Enable or disable the cameravoidsetHideCursorOnRotate(boolean hideCursorOnRotate) voidsetInvertHorizontalAxis(boolean invertXaxis) invert the Horizontal axis movement of the mousevoidsetInvertVerticalAxis(boolean invertYaxis) invert the vertical axis movement of the mousevoidsetLookAtOffset(Vector3f lookAtOffset) Sets the offset from the target's position where the camera looks atvoidsetMaxDistance(float maxDistance) Sets the max zoom distance of the camera (default is 40)voidsetMaxVerticalRotation(float maxVerticalRotation) Sets the maximal vertical rotation angle in radian of the camera around the target.voidsetMinDistance(float minDistance) Sets the min zoom distance of the camera (default is 1)voidsetMinVerticalRotation(float minHeight) Sets the minimal vertical rotation angle in radian of the camera around the target default is 0;voidsetRotationSensitivity(float rotationSensitivity) Sets the rotation sensitivity.voidsetRotationSpeed(float rotationSpeed) Sets the rotate amount when user moves his mouse.voidsetSmoothMotion(boolean smoothMotion) Enables smooth motion for this chase cameravoidsetSpatial(Spatial spatial) Sets the spatial for the camera control, should only be used internallyvoidsetToggleRotationTrigger(Trigger... triggers) Sets custom triggers for toggling the rotation of the cam default are new MouseButtonTrigger(MouseInput.BUTTON_LEFT) left mouse button new MouseButtonTrigger(MouseInput.BUTTON_RIGHT) right mouse buttonvoidsetTrailingEnabled(boolean trailingEnabled) Enable the camera trailing : The camera smoothly go in the targets trail when it moves.voidsetTrailingRotationInertia(float trailingRotationInertia) Sets the trailing rotation inertia : default is 0.1.voidsetTrailingSensitivity(float trailingSensitivity) Only has an effect if smoothMotion is set to true and trailing is enabled Sets the trailing sensitivity, the lower the value, the slower the camera will go in the target trail when it moves.voidsetUpVector(Vector3f up) Sets the up vector of the camera used for the lookAt on the targetvoidsetZoomInTrigger(Trigger... triggers) Sets custom triggers for zooming in the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true) mouse wheel upvoidsetZoomOutTrigger(Trigger... triggers) Sets custom triggers for zooming out the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false) mouse wheel downvoidsetZoomSensitivity(float zoomSensitivity) Sets the zoom sensitivity, the lower the value, the slower the camera will zoom in and out.voidupdate(float tpf) update the camera control, should only be used internallyprotected voidupdateCamera(float tpf) Updates the camera, should only be called internallyprotected voidvRotateCamera(float value) voidwrite(JmeExporter ex) Write the cameraprotected voidzoomCamera(float value) 
- 
Field Details- 
target
- 
minVerticalRotationprotected float minVerticalRotation
- 
maxVerticalRotationprotected float maxVerticalRotation
- 
minDistanceprotected float minDistance
- 
maxDistanceprotected float maxDistance
- 
distanceprotected float distance
- 
rotationSpeedprotected float rotationSpeed
- 
rotationprotected float rotation
- 
trailingRotationInertiaprotected float trailingRotationInertia
- 
zoomSensitivityprotected float zoomSensitivity
- 
rotationSensitivityprotected float rotationSensitivity
- 
chasingSensitivityprotected float chasingSensitivity
- 
trailingSensitivityprotected float trailingSensitivity
- 
vRotationprotected float vRotation
- 
smoothMotionprotected boolean smoothMotion
- 
trailingEnabledprotected boolean trailingEnabled
- 
rotationLerpFactorprotected float rotationLerpFactor
- 
trailingLerpFactorprotected float trailingLerpFactor
- 
rotatingprotected boolean rotating
- 
vRotatingprotected boolean vRotating
- 
targetRotationprotected float targetRotation
- 
inputManager
- 
initialUpVec
- 
targetVRotationprotected float targetVRotation
- 
vRotationLerpFactorprotected float vRotationLerpFactor
- 
targetDistanceprotected float targetDistance
- 
distanceLerpFactorprotected float distanceLerpFactor
- 
zoomingprotected boolean zooming
- 
trailingprotected boolean trailing
- 
chasingprotected boolean chasing
- 
veryCloseRotationprotected boolean veryCloseRotation
- 
canRotateprotected boolean canRotate
- 
offsetDistanceprotected float offsetDistance
- 
prevPos
- 
targetMovesprotected boolean targetMoves
- 
enabledprotected boolean enabled
- 
cam
- 
targetDir
- 
previousTargetRotationprotected float previousTargetRotation
- 
pos
- 
targetLocation
- 
dragToRotateprotected boolean dragToRotate
- 
lookAtOffset
- 
leftClickRotateprotected boolean leftClickRotate
- 
rightClickRotateprotected boolean rightClickRotate
- 
temp
- 
invertYaxisprotected boolean invertYaxis
- 
invertXaxisprotected boolean invertXaxis
- 
ChaseCamDownDeprecated.- See Also:
 
- 
ChaseCamUpDeprecated.- See Also:
 
- 
ChaseCamZoomInDeprecated.- See Also:
 
- 
ChaseCamZoomOutDeprecated.- See Also:
 
- 
ChaseCamMoveLeftDeprecated.- See Also:
 
- 
ChaseCamMoveRightDeprecated.- See Also:
 
- 
ChaseCamToggleRotateDeprecated.- See Also:
 
- 
zoominprotected boolean zoomin
- 
hideCursorOnRotateprotected boolean hideCursorOnRotate
 
- 
- 
Constructor Details- 
ChaseCameraConstructs the chase camera- Parameters:
- cam- the application camera
- target- the spatial to follow
 
- 
ChaseCameraConstructs the chase camera if you use this constructor you have to attach the cam later to a spatial doing spatial.addControl(chaseCamera);- Parameters:
- cam- the application camera
 
- 
ChaseCameraConstructs the chase camera, and registers inputs if you use this constructor you have to attach the cam later to a spatial doing spatial.addControl(chaseCamera);- Parameters:
- cam- the application camera
- inputManager- the inputManager of the application to register inputs
 
- 
ChaseCameraConstructs the chase camera, and registers inputs- Parameters:
- cam- the application camera
- target- the spatial to follow
- inputManager- the inputManager of the application to register inputs
 
 
- 
- 
Method Details- 
onActionDescription copied from interface:ActionListenerCalled when an input to which this listener is registered to is invoked.- Specified by:
- onActionin interface- ActionListener
- Parameters:
- name- The name of the mapping that was invoked
- keyPressed- True if the action is "pressed", false otherwise
- tpf- The time per frame value.
 
- 
onAnalogDescription copied from interface:AnalogListenerCalled to notify the implementation that an analog event has occurred. The results of KeyTrigger and MouseButtonTrigger events will have tpf == value.- Specified by:
- onAnalogin interface- AnalogListener
- Parameters:
- name- The name of the mapping that was invoked
- value- Value of the axis, from 0 to 1.
- tpf- The time per frame value.
 
- 
registerWithInputRegisters inputs with the input manager- Parameters:
- inputManager- (alias created)
 
- 
cleanupWithInputCleans up the input mappings from the input manager. Undoes the work of registerWithInput().- Parameters:
- mgr- the InputManager to clean up
 
- 
setToggleRotationTriggerSets custom triggers for toggling the rotation of the cam default are new MouseButtonTrigger(MouseInput.BUTTON_LEFT) left mouse button new MouseButtonTrigger(MouseInput.BUTTON_RIGHT) right mouse button- Parameters:
- triggers- the triggers to assign
 
- 
setZoomInTriggerSets custom triggers for zooming in the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true) mouse wheel up- Parameters:
- triggers- the triggers to assign
 
- 
setZoomOutTriggerSets custom triggers for zooming out the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false) mouse wheel down- Parameters:
- triggers- the triggers to assign
 
- 
computePositionprotected void computePosition()
- 
rotateCameraprotected void rotateCamera(float value) 
- 
zoomCameraprotected void zoomCamera(float value) 
- 
vRotateCameraprotected void vRotateCamera(float value) 
- 
updateCameraprotected void updateCamera(float tpf) Updates the camera, should only be called internally- Parameters:
- tpf- time per frame (in seconds)
 
- 
isEnabledpublic boolean isEnabled()Return the enabled/disabled state of the camera- Returns:
- true if the camera is enabled
 
- 
setEnabledpublic void setEnabled(boolean enabled) Enable or disable the camera- Parameters:
- enabled- true to enable
 
- 
getMaxDistancepublic float getMaxDistance()Returns the max zoom distance of the camera (default is 40)- Returns:
- maxDistance the configured distance (in world units)
 
- 
setMaxDistancepublic void setMaxDistance(float maxDistance) Sets the max zoom distance of the camera (default is 40)- Parameters:
- maxDistance- the desired distance (in world units, default=40)
 
- 
getMinDistancepublic float getMinDistance()Returns the min zoom distance of the camera (default is 1)- Returns:
- minDistance the configured distance (in world units)
 
- 
setMinDistancepublic void setMinDistance(float minDistance) Sets the min zoom distance of the camera (default is 1)- Parameters:
- minDistance- the desired distance (in world units, default=1)
 
- 
cloneForSpatialDeprecated.clone this camera for a spatial- Specified by:
- cloneForSpatialin interface- Control
- Parameters:
- spatial- ignored
- Returns:
- never
 
- 
jmeCloneDescription copied from interface:JmeCloneablePerforms a regular shallow clone of the object. Some fields may also be cloned but generally only if they will never be shared with other objects. (For example, local Vector3fs and so on.)This method is separate from the regular clone() method so that objects might still maintain their own regular java clone() semantics (perhaps even using Cloner for those methods). However, because Java's clone() has specific features in the sense of Object's clone() implementation, it's usually best to have some path for subclasses to bypass the public clone() method that might be cloning fields and instead get at the superclass protected clone() methods. For example, through super.jmeClone() or another protected clone method that some base class eventually calls super.clone() in. - Specified by:
- jmeClonein interface- JmeCloneable
- Returns:
- a new instance
 
- 
cloneFieldsDescription copied from interface:JmeCloneableImplemented to perform deep cloning for this object, resolving local cloned references using the specified cloner. The object can call cloner.clone(fieldValue) to deep clone any of its fields.Note: during normal clone operations the original object will not be needed as the clone has already had all of the fields shallow copied. - Specified by:
- cloneFieldsin interface- JmeCloneable
- Parameters:
- cloner- The cloner that is performing the cloning operation. The cloneFields method can call back into the cloner to make clones of its subordinate fields.
- original- The original object from which this object was cloned. This is provided for the very rare case that this object needs to refer to its original for some reason. In general, all of the relevant values should have been transferred during the shallow clone, and this object need only clone what it wants.
 
- 
setSpatialSets the spatial for the camera control, should only be used internally- Specified by:
- setSpatialin interface- Control
- Parameters:
- spatial- the desired camera target, or null for none
 
- 
updatepublic void update(float tpf) update the camera control, should only be used internally
- 
renderrenders the camera control, should only be used internally
- 
writeWrite the camera- Specified by:
- writein interface- Savable
- Parameters:
- ex- the exporter
- Throws:
- IOException- from the exporter
 
- 
readRead the camera- Specified by:
- readin interface- Savable
- Parameters:
- im- the importer (not null)
- Throws:
- IOException- from the importer
 
- 
getMaxVerticalRotationpublic float getMaxVerticalRotation()- Returns:
- The maximal vertical rotation angle in radian of the camera around the target
 
- 
setMaxVerticalRotationpublic void setMaxVerticalRotation(float maxVerticalRotation) Sets the maximal vertical rotation angle in radian of the camera around the target. Default is Pi/2;- Parameters:
- maxVerticalRotation- the desired angle (in radians, default=Pi/2)
 
- 
getMinVerticalRotationpublic float getMinVerticalRotation()- Returns:
- The minimal vertical rotation angle in radian of the camera around the target
 
- 
setMinVerticalRotationpublic void setMinVerticalRotation(float minHeight) Sets the minimal vertical rotation angle in radian of the camera around the target default is 0;- Parameters:
- minHeight- the desired angle (in radians, default=0)
 
- 
isSmoothMotionpublic boolean isSmoothMotion()- Returns:
- True is smooth motion is enabled for this chase camera
 
- 
setSmoothMotionpublic void setSmoothMotion(boolean smoothMotion) Enables smooth motion for this chase camera- Parameters:
- smoothMotion- true to enable, false to disable (default=false)
 
- 
getChasingSensitivitypublic float getChasingSensitivity()returns the chasing sensitivity- Returns:
- the sensitivity
 
- 
setChasingSensitivitypublic void setChasingSensitivity(float chasingSensitivity) Sets the chasing sensitivity, the lower the value the slower the camera will follow the target when it moves default is 5 Only has an effect if smoothMotion is set to true and trailing is enabled- Parameters:
- chasingSensitivity- the desired value (default=5)
 
- 
getRotationSensitivitypublic float getRotationSensitivity()Returns the rotation sensitivity- Returns:
- the sensitivity
 
- 
setRotationSensitivitypublic void setRotationSensitivity(float rotationSensitivity) Sets the rotation sensitivity. The lower the value, the slower the camera will rotate around the target when dragging with the mouse. default is 5, values over 5 should have no effect. If you want a significant slow down try values below 1. Only has an effect if smoothMotion is set to true- Parameters:
- rotationSensitivity- the desired value (default=5)
 
- 
isTrailingEnabledpublic boolean isTrailingEnabled()returns true if the trailing is enabled- Returns:
- true if enabled, otherwise false
 
- 
setTrailingEnabledpublic void setTrailingEnabled(boolean trailingEnabled) Enable the camera trailing : The camera smoothly go in the targets trail when it moves. Only has an effect if smoothMotion is set to true- Parameters:
- trailingEnabled- true to enable, false to disable (default=true)
 
- 
getTrailingRotationInertiapublic float getTrailingRotationInertia()returns the trailing rotation inertia- Returns:
- the inertia
 
- 
setTrailingRotationInertiapublic void setTrailingRotationInertia(float trailingRotationInertia) Sets the trailing rotation inertia : default is 0.1. This causes the camera to stop roughly when the target stops moving before the camera reaches the trail position. Only has an effect if smoothMotion is set to true and trailing is enabled- Parameters:
- trailingRotationInertia- the desired value (default=0.05)
 
- 
getTrailingSensitivitypublic float getTrailingSensitivity()returns the trailing sensitivity- Returns:
- the sensitivity
 
- 
setTrailingSensitivitypublic void setTrailingSensitivity(float trailingSensitivity) Only has an effect if smoothMotion is set to true and trailing is enabled Sets the trailing sensitivity, the lower the value, the slower the camera will go in the target trail when it moves. default is 0.5;- Parameters:
- trailingSensitivity- the desired value (default=0.5)
 
- 
getZoomSensitivitypublic float getZoomSensitivity()returns the zoom sensitivity- Returns:
- the sensitivity
 
- 
setZoomSensitivitypublic void setZoomSensitivity(float zoomSensitivity) Sets the zoom sensitivity, the lower the value, the slower the camera will zoom in and out. default is 2.- Parameters:
- zoomSensitivity- the desired factor (default=2)
 
- 
getRotationSpeedpublic float getRotationSpeed()Returns the rotation speed when the mouse is moved.- Returns:
- the rotation speed when the mouse is moved.
 
- 
setRotationSpeedpublic void setRotationSpeed(float rotationSpeed) Sets the rotate amount when user moves his mouse. The lower the value, the slower the camera will rotate. Default is 1.- Parameters:
- rotationSpeed- Rotation speed on mouse movement, default is 1.
 
- 
setDefaultDistancepublic void setDefaultDistance(float defaultDistance) Sets the default distance at start of application- Parameters:
- defaultDistance- the desired distance (in world units, default=20)
 
- 
setDefaultHorizontalRotationpublic void setDefaultHorizontalRotation(float angleInRad) sets the default horizontal rotation in radian of the camera at start of the application- Parameters:
- angleInRad- the desired angle (in radians, default=0)
 
- 
setDefaultVerticalRotationpublic void setDefaultVerticalRotation(float angleInRad) sets the default vertical rotation in radian of the camera at start of the application- Parameters:
- angleInRad- the desired angle (in radians, default=Pi/6)
 
- 
isDragToRotatepublic boolean isDragToRotate()- Returns:
- If drag to rotate feature is enabled.
- See Also:
 
- 
setDragToRotatepublic void setDragToRotate(boolean dragToRotate) - Parameters:
- dragToRotate- When true, the user must hold the mouse button and drag over the screen to rotate the camera, and the cursor is visible until dragged. Otherwise, the cursor is invisible at all times and holding the mouse button is not needed to rotate the camera. This feature is disabled by default.
 
- 
setDownRotateOnCloseViewOnlypublic void setDownRotateOnCloseViewOnly(boolean rotateOnlyWhenClose) - Parameters:
- rotateOnlyWhenClose- When this flag is set to false the chase camera will always rotate around its spatial independently of their distance to one another. If set to true, the chase camera will only be allowed to rotated below the "horizon" when the distance is smaller than minDistance + 1.0f (when fully zoomed-in).
 
- 
getDownRotateOnCloseViewOnlypublic boolean getDownRotateOnCloseViewOnly()- Returns:
- True if rotation below the vertical plane of the spatial tied to the camera is allowed only when zoomed in at minDistance + 1.0f. False if vertical rotation is always allowed.
 
- 
getDistanceToTargetpublic float getDistanceToTarget()return the current distance from the camera to the target- Returns:
- the distance
 
- 
getHorizontalRotationpublic float getHorizontalRotation()returns the current horizontal rotation around the target in radians- Returns:
- the angle
 
- 
getVerticalRotationpublic float getVerticalRotation()returns the current vertical rotation around the target in radians.- Returns:
- the angle in radians
 
- 
getLookAtOffsetreturns the offset from the target's position where the camera looks at- Returns:
- the pre-existing vector
 
- 
setLookAtOffsetSets the offset from the target's position where the camera looks at- Parameters:
- lookAtOffset- the desired offset (alias created)
 
- 
setUpVectorSets the up vector of the camera used for the lookAt on the target- Parameters:
- up- the desired direction (alias created)
 
- 
getUpVectorReturns the up vector of the camera used for the lookAt on the target- Returns:
- the pre-existing vector
 
- 
isHideCursorOnRotatepublic boolean isHideCursorOnRotate()
- 
setHideCursorOnRotatepublic void setHideCursorOnRotate(boolean hideCursorOnRotate) 
- 
setInvertVerticalAxispublic void setInvertVerticalAxis(boolean invertYaxis) invert the vertical axis movement of the mouse- Parameters:
- invertYaxis- true→invert, false→don't invert
 
- 
setInvertHorizontalAxispublic void setInvertHorizontalAxis(boolean invertXaxis) invert the Horizontal axis movement of the mouse- Parameters:
- invertXaxis- true→invert, false→don't invert
 
 
- 
CameraInput.CHASECAM_DOWN