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
Modifier and TypeFieldDescriptionprotected Camera
protected boolean
static final String
Deprecated.static final String
Deprecated.static final String
Deprecated.static final String
Deprecated.static final String
Deprecated.static final String
Deprecated.static final String
Deprecated.protected boolean
protected float
protected float
protected float
protected boolean
protected boolean
protected boolean
protected Vector3f
protected InputManager
protected boolean
protected boolean
protected boolean
protected Vector3f
protected float
protected float
protected float
protected float
protected float
protected final Vector3f
protected float
protected Vector3f
protected boolean
protected boolean
protected float
protected float
protected float
protected float
protected boolean
protected Spatial
protected final Vector3f
protected float
protected Vector3f
protected boolean
protected float
protected float
protected Vector3f
protected boolean
protected boolean
protected float
protected float
protected float
protected boolean
protected boolean
protected float
protected float
protected boolean
protected boolean
protected float
-
Constructor Summary
ConstructorDescriptionChaseCamera
(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 TypeMethodDescriptionvoid
Cleans up the input mappings from the input manager.void
cloneFields
(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 void
float
returns the chasing sensitivityfloat
return the current distance from the camera to the targetboolean
float
returns the current horizontal rotation around the target in radiansreturns the offset from the target's position where the camera looks atfloat
Returns the max zoom distance of the camera (default is 40)float
float
Returns the min zoom distance of the camera (default is 1)float
float
Returns the rotation sensitivityfloat
Returns the rotation speed when the mouse is moved.float
returns the trailing rotation inertiafloat
returns the trailing sensitivityReturns the up vector of the camera used for the lookAt on the targetfloat
returns the current vertical rotation around the target in radians.float
returns the zoom sensitivityboolean
boolean
Return the enabled/disabled state of the cameraboolean
boolean
boolean
returns true if the trailing is enabledjmeClone()
Performs a regular shallow clone of the object.void
Called when an input to which this listener is registered to is invoked.void
Called to notify the implementation that an analog event has occurred.void
read
(JmeImporter im) Read the camerafinal void
registerWithInput
(InputManager inputManager) Registers inputs with the input managervoid
render
(RenderManager rm, ViewPort vp) renders the camera control, should only be used internallyprotected void
rotateCamera
(float value) 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 enabledvoid
setDefaultDistance
(float defaultDistance) Sets the default distance at start of applicationvoid
setDefaultHorizontalRotation
(float angleInRad) sets the default horizontal rotation in radian of the camera at start of the applicationvoid
setDefaultVerticalRotation
(float angleInRad) sets the default vertical rotation in radian of the camera at start of the applicationvoid
setDownRotateOnCloseViewOnly
(boolean rotateOnlyWhenClose) void
setDragToRotate
(boolean dragToRotate) void
setEnabled
(boolean enabled) Enable or disable the cameravoid
setHideCursorOnRotate
(boolean hideCursorOnRotate) void
setInvertHorizontalAxis
(boolean invertXaxis) invert the Horizontal axis movement of the mousevoid
setInvertVerticalAxis
(boolean invertYaxis) invert the vertical axis movement of the mousevoid
setLookAtOffset
(Vector3f lookAtOffset) Sets the offset from the target's position where the camera looks atvoid
setMaxDistance
(float maxDistance) Sets the max zoom distance of the camera (default is 40)void
setMaxVerticalRotation
(float maxVerticalRotation) Sets the maximal vertical rotation angle in radian of the camera around the target.void
setMinDistance
(float minDistance) Sets the min zoom distance of the camera (default is 1)void
setMinVerticalRotation
(float minHeight) Sets the minimal vertical rotation angle in radian of the camera around the target default is 0;void
setRotationSensitivity
(float rotationSensitivity) Sets the rotation sensitivity.void
setRotationSpeed
(float rotationSpeed) Sets the rotate amount when user moves his mouse.void
setSmoothMotion
(boolean smoothMotion) Enables smooth motion for this chase cameravoid
setSpatial
(Spatial spatial) Sets the spatial for the camera control, should only be used internallyvoid
setToggleRotationTrigger
(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 buttonvoid
setTrailingEnabled
(boolean trailingEnabled) Enable the camera trailing : The camera smoothly go in the targets trail when it moves.void
setTrailingRotationInertia
(float trailingRotationInertia) Sets the trailing rotation inertia : default is 0.1.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.void
setUpVector
(Vector3f up) Sets the up vector of the camera used for the lookAt on the targetvoid
setZoomInTrigger
(Trigger... triggers) Sets custom triggers for zooming in the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true) mouse wheel upvoid
setZoomOutTrigger
(Trigger... triggers) Sets custom triggers for zooming out the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false) mouse wheel downvoid
setZoomSensitivity
(float zoomSensitivity) Sets the zoom sensitivity, the lower the value, the slower the camera will zoom in and out.void
update
(float tpf) update the camera control, should only be used internallyprotected void
updateCamera
(float tpf) Updates the camera, should only be called internallyprotected void
vRotateCamera
(float value) void
write
(JmeExporter ex) Write the cameraprotected void
zoomCamera
(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:ActionListener
Called when an input to which this listener is registered to is invoked.- Specified by:
onAction
in 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:AnalogListener
Called to notify the implementation that an analog event has occurred. The results of KeyTrigger and MouseButtonTrigger events will have tpf == value.- Specified by:
onAnalog
in 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:
cloneForSpatial
in interfaceControl
- Parameters:
spatial
- ignored- Returns:
- never
-
jmeClone
Description copied from interface:JmeCloneable
Performs 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:
jmeClone
in interfaceJmeCloneable
- Returns:
- a new instance
-
cloneFields
Description copied from interface:JmeCloneable
Implemented 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:
cloneFields
in 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:
setSpatial
in 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:
write
in interfaceSavable
- Parameters:
ex
- the exporter- Throws:
IOException
- from the exporter
-
read
Read the camera- Specified by:
read
in 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