public class ChaseCamera extends java.lang.Object implements ActionListener, AnalogListener, Control, JmeCloneable
Modifier and Type | Field and Description |
---|---|
protected Camera |
cam |
protected boolean |
canRotate |
static java.lang.String |
ChaseCamDown
Deprecated.
|
static java.lang.String |
ChaseCamMoveLeft
Deprecated.
|
static java.lang.String |
ChaseCamMoveRight
Deprecated.
|
static java.lang.String |
ChaseCamToggleRotate
Deprecated.
|
static java.lang.String |
ChaseCamUp
Deprecated.
|
static java.lang.String |
ChaseCamZoomIn
Deprecated.
|
static java.lang.String |
ChaseCamZoomOut
Deprecated.
|
protected boolean |
chasing |
protected float |
chasingSensitivity |
protected float |
distance |
protected float |
distanceLerpFactor |
protected boolean |
dragToRotate |
protected boolean |
enabled |
protected boolean |
hideCursorOnRotate |
protected Vector3f |
initialUpVec |
protected InputManager |
inputManager |
protected boolean |
invertXaxis |
protected boolean |
invertYaxis |
protected boolean |
leftClickRotate |
protected Vector3f |
lookAtOffset |
protected float |
maxDistance |
protected float |
maxVerticalRotation |
protected float |
minDistance |
protected float |
minVerticalRotation |
protected float |
offsetDistance |
protected Vector3f |
pos |
protected float |
previousTargetRotation |
protected Vector3f |
prevPos |
protected boolean |
rightClickRotate |
protected boolean |
rotating |
protected float |
rotation |
protected float |
rotationLerpFactor |
protected float |
rotationSensitivity |
protected float |
rotationSpeed |
protected boolean |
smoothMotion |
protected Spatial |
target |
protected Vector3f |
targetDir |
protected float |
targetDistance |
protected Vector3f |
targetLocation |
protected boolean |
targetMoves |
protected float |
targetRotation |
protected float |
targetVRotation |
protected Vector3f |
temp |
protected boolean |
trailing |
protected boolean |
trailingEnabled |
protected float |
trailingLerpFactor |
protected float |
trailingRotationInertia |
protected float |
trailingSensitivity |
protected boolean |
veryCloseRotation |
protected boolean |
vRotating |
protected float |
vRotation |
protected float |
vRotationLerpFactor |
protected boolean |
zoomin |
protected boolean |
zooming |
protected float |
zoomSensitivity |
Constructor and Description |
---|
ChaseCamera(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 camera
|
ChaseCamera(Camera cam,
Spatial target,
InputManager inputManager)
Constructs the chase camera, and registers inputs
|
Modifier and Type | Method and Description |
---|---|
void |
cleanupWithInput(InputManager mgr)
Cleans up the input mappings from the input manager.
|
void |
cloneFields(Cloner cloner,
java.lang.Object original)
Implemented to perform deep cloning for this object, resolving
local cloned references using the specified cloner.
|
Control |
cloneForSpatial(Spatial spatial)
Deprecated.
|
protected void |
computePosition() |
float |
getChasingSensitivity()
returns the chasing sensitivity
|
float |
getDistanceToTarget()
return the current distance from the camera to the target
|
boolean |
getDownRotateOnCloseViewOnly() |
float |
getHorizontalRotation()
returns the current horizontal rotation around the target in radians
|
Vector3f |
getLookAtOffset()
returns the offset from the target's position where the camera looks at
|
float |
getMaxDistance()
Returns the max zoom distance of the camera (default is 40)
|
float |
getMaxVerticalRotation() |
float |
getMinDistance()
Returns the min zoom distance of the camera (default is 1)
|
float |
getMinVerticalRotation() |
float |
getRotationSensitivity()
Returns the rotation sensitivity
|
float |
getRotationSpeed()
Returns the rotation speed when the mouse is moved.
|
float |
getTrailingRotationInertia()
returns the trailing rotation inertia
|
float |
getTrailingSensitivity()
returns the trailing sensitivity
|
Vector3f |
getUpVector()
Returns the up vector of the camera used for the lookAt on the target
|
float |
getVerticalRotation()
returns the current vertical rotation around the target in radians.
|
float |
getZoomSensitivity()
returns the zoom sensitivity
|
boolean |
isDragToRotate() |
boolean |
isEnabled()
Return the enabled/disabled state of the camera
|
boolean |
isHideCursorOnRotate() |
boolean |
isSmoothMotion() |
boolean |
isTrailingEnabled()
returns true if the trailing is enabled
|
java.lang.Object |
jmeClone()
Performs a regular shallow clone of the object.
|
void |
onAction(java.lang.String name,
boolean keyPressed,
float tpf)
Called when an input to which this listener is registered to is invoked.
|
void |
onAnalog(java.lang.String name,
float value,
float tpf)
Called to notify the implementation that an analog event has occurred.
|
void |
read(JmeImporter im)
Read the camera
|
void |
registerWithInput(InputManager inputManager)
Registers inputs with the input manager
|
void |
render(RenderManager rm,
ViewPort vp)
renders the camera control, should only be used internally
|
protected 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 enabled
|
void |
setDefaultDistance(float defaultDistance)
Sets the default distance at start of application
|
void |
setDefaultHorizontalRotation(float angleInRad)
sets the default horizontal rotation in radian of the camera at start of the application
|
void |
setDefaultVerticalRotation(float angleInRad)
sets the default vertical rotation in radian of the camera at start of the application
|
void |
setDownRotateOnCloseViewOnly(boolean rotateOnlyWhenClose) |
void |
setDragToRotate(boolean dragToRotate) |
void |
setEnabled(boolean enabled)
Enable or disable the camera
|
void |
setHideCursorOnRotate(boolean hideCursorOnRotate) |
void |
setInvertHorizontalAxis(boolean invertXaxis)
invert the Horizontal axis movement of the mouse
|
void |
setInvertVerticalAxis(boolean invertYaxis)
invert the vertical axis movement of the mouse
|
void |
setLookAtOffset(Vector3f lookAtOffset)
Sets the offset from the target's position where the camera looks at
|
void |
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, the lower the value the slower the camera will rotates around the target when dragging with the mouse
default is 5, values over 5 should have no effect.
|
void |
setRotationSpeed(float rotationSpeed)
Sets the rotate amount when user moves his mouse, the lower the value,
the slower the camera will rotate.
|
void |
setSmoothMotion(boolean smoothMotion)
Enables smooth motion for this chase camera
|
void |
setSpatial(Spatial spatial)
Sets the spacial for the camera control, should only be used internally
|
void |
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 button
|
void |
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 target
|
void |
setZoomInTrigger(Trigger... triggers)
Sets custom triggers for zooming in the cam
default is
new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true) mouse wheel up
|
void |
setZoomOutTrigger(Trigger... triggers)
Sets custom triggers for zooming out the cam
default is
new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false) mouse wheel down
|
void |
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 internally
|
protected void |
updateCamera(float tpf)
Updates the camera, should only be called internally
|
protected void |
vRotateCamera(float value) |
void |
write(JmeExporter ex)
Write the camera
|
protected void |
zoomCamera(float value) |
protected Spatial target
protected float minVerticalRotation
protected float maxVerticalRotation
protected float minDistance
protected float maxDistance
protected float distance
protected float rotationSpeed
protected float rotation
protected float trailingRotationInertia
protected float zoomSensitivity
protected float rotationSensitivity
protected float chasingSensitivity
protected float trailingSensitivity
protected float vRotation
protected boolean smoothMotion
protected boolean trailingEnabled
protected float rotationLerpFactor
protected float trailingLerpFactor
protected boolean rotating
protected boolean vRotating
protected float targetRotation
protected InputManager inputManager
protected Vector3f initialUpVec
protected float targetVRotation
protected float vRotationLerpFactor
protected float targetDistance
protected float distanceLerpFactor
protected boolean zooming
protected boolean trailing
protected boolean chasing
protected boolean veryCloseRotation
protected boolean canRotate
protected float offsetDistance
protected Vector3f prevPos
protected boolean targetMoves
protected boolean enabled
protected Camera cam
protected final Vector3f targetDir
protected float previousTargetRotation
protected final Vector3f pos
protected Vector3f targetLocation
protected boolean dragToRotate
protected Vector3f lookAtOffset
protected boolean leftClickRotate
protected boolean rightClickRotate
protected Vector3f temp
protected boolean invertYaxis
protected boolean invertXaxis
@Deprecated public static final java.lang.String ChaseCamDown
CameraInput.CHASECAM_DOWN
@Deprecated public static final java.lang.String ChaseCamUp
CameraInput.CHASECAM_UP
@Deprecated public static final java.lang.String ChaseCamZoomIn
CameraInput.CHASECAM_ZOOMIN
@Deprecated public static final java.lang.String ChaseCamZoomOut
CameraInput.CHASECAM_ZOOMOUT
@Deprecated public static final java.lang.String ChaseCamMoveLeft
CameraInput.CHASECAM_MOVELEFT
@Deprecated public static final java.lang.String ChaseCamMoveRight
CameraInput.CHASECAM_MOVERIGHT
@Deprecated public static final java.lang.String ChaseCamToggleRotate
CameraInput.CHASECAM_TOGGLEROTATE
protected boolean zoomin
protected boolean hideCursorOnRotate
public ChaseCamera(Camera cam, Spatial target)
cam
- the application cameratarget
- the spatial to followpublic ChaseCamera(Camera cam)
cam
- the application camerapublic ChaseCamera(Camera cam, InputManager inputManager)
cam
- the application camerainputManager
- the inputManager of the application to register inputspublic ChaseCamera(Camera cam, Spatial target, InputManager inputManager)
cam
- the application cameratarget
- the spatial to followinputManager
- the inputManager of the application to register inputspublic void onAction(java.lang.String name, boolean keyPressed, float tpf)
ActionListener
onAction
in interface ActionListener
name
- The name of the mapping that was invokedkeyPressed
- True if the action is "pressed", false otherwisetpf
- The time per frame value.public void onAnalog(java.lang.String name, float value, float tpf)
AnalogListener
onAnalog
in interface AnalogListener
name
- The name of the mapping that was invokedvalue
- Value of the axis, from 0 to 1.tpf
- The time per frame value.public final void registerWithInput(InputManager inputManager)
inputManager
- public void cleanupWithInput(InputManager mgr)
mgr
- the InputManager to clean uppublic void setToggleRotationTrigger(Trigger... triggers)
triggers
- public void setZoomInTrigger(Trigger... triggers)
triggers
- public void setZoomOutTrigger(Trigger... triggers)
triggers
- protected void computePosition()
protected void rotateCamera(float value)
protected void zoomCamera(float value)
protected void vRotateCamera(float value)
protected void updateCamera(float tpf)
public boolean isEnabled()
public void setEnabled(boolean enabled)
enabled
- true to enablepublic float getMaxDistance()
public void setMaxDistance(float maxDistance)
maxDistance
- public float getMinDistance()
public void setMinDistance(float minDistance)
@Deprecated public Control cloneForSpatial(Spatial spatial)
cloneForSpatial
in interface Control
spatial
- public java.lang.Object jmeClone()
JmeCloneable
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.
jmeClone
in interface JmeCloneable
public void cloneFields(Cloner cloner, java.lang.Object original)
JmeCloneable
Note: during normal clone operations the original object will not be needed as the clone has already had all of the fields shallow copied.
cloneFields
in interface JmeCloneable
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 merely clone what it wants.public void setSpatial(Spatial spatial)
setSpatial
in interface Control
spatial
- public void update(float tpf)
public void render(RenderManager rm, ViewPort vp)
public void write(JmeExporter ex) throws java.io.IOException
public void read(JmeImporter im) throws java.io.IOException
public float getMaxVerticalRotation()
public void setMaxVerticalRotation(float maxVerticalRotation)
maxVerticalRotation
- public float getMinVerticalRotation()
public void setMinVerticalRotation(float minHeight)
minHeight
- public boolean isSmoothMotion()
public void setSmoothMotion(boolean smoothMotion)
smoothMotion
- public float getChasingSensitivity()
public void setChasingSensitivity(float chasingSensitivity)
chasingSensitivity
- public float getRotationSensitivity()
public void setRotationSensitivity(float rotationSensitivity)
rotationSensitivity
- public boolean isTrailingEnabled()
public void setTrailingEnabled(boolean trailingEnabled)
trailingEnabled
- public float getTrailingRotationInertia()
public void setTrailingRotationInertia(float trailingRotationInertia)
trailingRotationInertia
- public float getTrailingSensitivity()
public void setTrailingSensitivity(float trailingSensitivity)
trailingSensitivity
- public float getZoomSensitivity()
public void setZoomSensitivity(float zoomSensitivity)
zoomSensitivity
- public float getRotationSpeed()
public void setRotationSpeed(float rotationSpeed)
rotationSpeed
- Rotation speed on mouse movement, default is 1.public void setDefaultDistance(float defaultDistance)
defaultDistance
- public void setDefaultHorizontalRotation(float angleInRad)
angleInRad
- public void setDefaultVerticalRotation(float angleInRad)
angleInRad
- public boolean isDragToRotate()
setDragToRotate(boolean)
public void setDragToRotate(boolean dragToRotate)
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.public void setDownRotateOnCloseViewOnly(boolean rotateOnlyWhenClose)
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).public boolean getDownRotateOnCloseViewOnly()
public float getDistanceToTarget()
public float getHorizontalRotation()
public float getVerticalRotation()
public Vector3f getLookAtOffset()
public void setLookAtOffset(Vector3f lookAtOffset)
lookAtOffset
- public void setUpVector(Vector3f up)
up
- public Vector3f getUpVector()
public boolean isHideCursorOnRotate()
public void setHideCursorOnRotate(boolean hideCursorOnRotate)
public void setInvertVerticalAxis(boolean invertYaxis)
invertYaxis
- public void setInvertHorizontalAxis(boolean invertXaxis)
invertXaxis
-