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 Summary
FieldsModifier 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 Summary
ConstructorsConstructorDescriptionChaseCamera(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 Summary
Modifier 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
-
minVerticalRotation
protected float minVerticalRotation -
maxVerticalRotation
protected float maxVerticalRotation -
minDistance
protected float minDistance -
maxDistance
protected float maxDistance -
distance
protected float distance -
rotationSpeed
protected float rotationSpeed -
rotation
protected float rotation -
trailingRotationInertia
protected float trailingRotationInertia -
zoomSensitivity
protected float zoomSensitivity -
rotationSensitivity
protected float rotationSensitivity -
chasingSensitivity
protected float chasingSensitivity -
trailingSensitivity
protected float trailingSensitivity -
vRotation
protected float vRotation -
smoothMotion
protected boolean smoothMotion -
trailingEnabled
protected boolean trailingEnabled -
rotationLerpFactor
protected float rotationLerpFactor -
trailingLerpFactor
protected float trailingLerpFactor -
rotating
protected boolean rotating -
vRotating
protected boolean vRotating -
targetRotation
protected float targetRotation -
inputManager
-
initialUpVec
-
targetVRotation
protected float targetVRotation -
vRotationLerpFactor
protected float vRotationLerpFactor -
targetDistance
protected float targetDistance -
distanceLerpFactor
protected float distanceLerpFactor -
zooming
protected boolean zooming -
trailing
protected boolean trailing -
chasing
protected boolean chasing -
veryCloseRotation
protected boolean veryCloseRotation -
canRotate
protected boolean canRotate -
offsetDistance
protected float offsetDistance -
prevPos
-
targetMoves
protected boolean targetMoves -
enabled
protected boolean enabled -
cam
-
targetDir
-
previousTargetRotation
protected float previousTargetRotation -
pos
-
targetLocation
-
dragToRotate
protected boolean dragToRotate -
lookAtOffset
-
leftClickRotate
protected boolean leftClickRotate -
rightClickRotate
protected boolean rightClickRotate -
temp
-
invertYaxis
protected boolean invertYaxis -
invertXaxis
protected boolean invertXaxis -
ChaseCamDown
Deprecated.- See Also:
-
ChaseCamUp
Deprecated.- See Also:
-
ChaseCamZoomIn
Deprecated.- See Also:
-
ChaseCamZoomOut
Deprecated.- See Also:
-
ChaseCamMoveLeft
Deprecated.- See Also:
-
ChaseCamMoveRight
Deprecated.- See Also:
-
ChaseCamToggleRotate
Deprecated.- See Also:
-
zoomin
protected boolean zoomin -
hideCursorOnRotate
protected boolean hideCursorOnRotate
-
-
Constructor Details
-
ChaseCamera
Constructs the chase camera- Parameters:
cam- the application cameratarget- the spatial to follow
-
ChaseCamera
Constructs 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
-
ChaseCamera
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);- Parameters:
cam- the application camerainputManager- the inputManager of the application to register inputs
-
ChaseCamera
Constructs the chase camera, and registers inputs- Parameters:
cam- the application cameratarget- the spatial to followinputManager- the inputManager of the application to register inputs
-
-
Method Details
-
onAction
Description copied from interface:ActionListenerCalled when an input to which this listener is registered to is invoked.- Specified by:
onActionin interfaceActionListener- Parameters:
name- The name of the mapping that was invokedkeyPressed- True if the action is "pressed", false otherwisetpf- The time per frame value.
-
onAnalog
Description 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 interfaceAnalogListener- Parameters:
name- The name of the mapping that was invokedvalue- Value of the axis, from 0 to 1.tpf- The time per frame value.
-
registerWithInput
Registers inputs with the input manager- Parameters:
inputManager- (alias created)
-
cleanupWithInput
Cleans up the input mappings from the input manager. Undoes the work of registerWithInput().- Parameters:
mgr- the InputManager to clean up
-
setToggleRotationTrigger
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 button- Parameters:
triggers- the triggers to assign
-
setZoomInTrigger
Sets custom triggers for zooming in the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true) mouse wheel up- Parameters:
triggers- the triggers to assign
-
setZoomOutTrigger
Sets custom triggers for zooming out the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false) mouse wheel down- Parameters:
triggers- the triggers to assign
-
computePosition
protected void computePosition() -
rotateCamera
protected void rotateCamera(float value) -
zoomCamera
protected void zoomCamera(float value) -
vRotateCamera
protected void vRotateCamera(float value) -
updateCamera
protected void updateCamera(float tpf) Updates the camera, should only be called internally- Parameters:
tpf- time per frame (in seconds)
-
isEnabled
public boolean isEnabled()Return the enabled/disabled state of the camera- Returns:
- true if the camera is enabled
-
setEnabled
public void setEnabled(boolean enabled) Enable or disable the camera- Parameters:
enabled- true to enable
-
getMaxDistance
public float getMaxDistance()Returns the max zoom distance of the camera (default is 40)- Returns:
- maxDistance the configured distance (in world units)
-
setMaxDistance
public 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)
-
getMinDistance
public float getMinDistance()Returns the min zoom distance of the camera (default is 1)- Returns:
- minDistance the configured distance (in world units)
-
setMinDistance
public 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)
-
cloneForSpatial
Deprecated.clone this camera for a spatial- Specified by:
cloneForSpatialin interfaceControl- Parameters:
spatial- ignored- Returns:
- never
-
jmeClone
Description 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 interfaceJmeCloneable- Returns:
- a new instance
-
cloneFields
Description 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 interfaceJmeCloneable- 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.
-
setSpatial
Sets the spatial for the camera control, should only be used internally- Specified by:
setSpatialin interfaceControl- Parameters:
spatial- the desired camera target, or null for none
-
update
public void update(float tpf) update the camera control, should only be used internally -
render
renders the camera control, should only be used internally -
write
Write the camera- Specified by:
writein interfaceSavable- Parameters:
ex- the exporter- Throws:
IOException- from the exporter
-
read
Read the camera- Specified by:
readin interfaceSavable- Parameters:
im- the importer (not null)- Throws:
IOException- from the importer
-
getMaxVerticalRotation
public float getMaxVerticalRotation()- Returns:
- The maximal vertical rotation angle in radian of the camera around the target
-
setMaxVerticalRotation
public 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)
-
getMinVerticalRotation
public float getMinVerticalRotation()- Returns:
- The minimal vertical rotation angle in radian of the camera around the target
-
setMinVerticalRotation
public 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)
-
isSmoothMotion
public boolean isSmoothMotion()- Returns:
- True is smooth motion is enabled for this chase camera
-
setSmoothMotion
public void setSmoothMotion(boolean smoothMotion) Enables smooth motion for this chase camera- Parameters:
smoothMotion- true to enable, false to disable (default=false)
-
getChasingSensitivity
public float getChasingSensitivity()returns the chasing sensitivity- Returns:
- the sensitivity
-
setChasingSensitivity
public 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)
-
getRotationSensitivity
public float getRotationSensitivity()Returns the rotation sensitivity- Returns:
- the sensitivity
-
setRotationSensitivity
public 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)
-
isTrailingEnabled
public boolean isTrailingEnabled()returns true if the trailing is enabled- Returns:
- true if enabled, otherwise false
-
setTrailingEnabled
public 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)
-
getTrailingRotationInertia
public float getTrailingRotationInertia()returns the trailing rotation inertia- Returns:
- the inertia
-
setTrailingRotationInertia
public 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)
-
getTrailingSensitivity
public float getTrailingSensitivity()returns the trailing sensitivity- Returns:
- the sensitivity
-
setTrailingSensitivity
public 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)
-
getZoomSensitivity
public float getZoomSensitivity()returns the zoom sensitivity- Returns:
- the sensitivity
-
setZoomSensitivity
public 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)
-
getRotationSpeed
public float getRotationSpeed()Returns the rotation speed when the mouse is moved.- Returns:
- the rotation speed when the mouse is moved.
-
setRotationSpeed
public 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.
-
setDefaultDistance
public void setDefaultDistance(float defaultDistance) Sets the default distance at start of application- Parameters:
defaultDistance- the desired distance (in world units, default=20)
-
setDefaultHorizontalRotation
public 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)
-
setDefaultVerticalRotation
public 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)
-
isDragToRotate
public boolean isDragToRotate()- Returns:
- If drag to rotate feature is enabled.
- See Also:
-
setDragToRotate
public 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.
-
setDownRotateOnCloseViewOnly
public 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).
-
getDownRotateOnCloseViewOnly
public 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.
-
getDistanceToTarget
public float getDistanceToTarget()return the current distance from the camera to the target- Returns:
- the distance
-
getHorizontalRotation
public float getHorizontalRotation()returns the current horizontal rotation around the target in radians- Returns:
- the angle
-
getVerticalRotation
public float getVerticalRotation()returns the current vertical rotation around the target in radians.- Returns:
- the angle in radians
-
getLookAtOffset
returns the offset from the target's position where the camera looks at- Returns:
- the pre-existing vector
-
setLookAtOffset
Sets the offset from the target's position where the camera looks at- Parameters:
lookAtOffset- the desired offset (alias created)
-
setUpVector
Sets the up vector of the camera used for the lookAt on the target- Parameters:
up- the desired direction (alias created)
-
getUpVector
Returns the up vector of the camera used for the lookAt on the target- Returns:
- the pre-existing vector
-
isHideCursorOnRotate
public boolean isHideCursorOnRotate() -
setHideCursorOnRotate
public void setHideCursorOnRotate(boolean hideCursorOnRotate) -
setInvertVerticalAxis
public void setInvertVerticalAxis(boolean invertYaxis) invert the vertical axis movement of the mouse- Parameters:
invertYaxis- true→invert, false→don't invert
-
setInvertHorizontalAxis
public void setInvertHorizontalAxis(boolean invertXaxis) invert the Horizontal axis movement of the mouse- Parameters:
invertXaxis- true→invert, false→don't invert
-
CameraInput.CHASECAM_DOWN