com.jme3.input
Class ChaseCamera

java.lang.Object
  extended by com.jme3.input.ChaseCamera
All Implemented Interfaces:
Savable, ActionListener, AnalogListener, InputListener, Control

public class ChaseCamera
extends java.lang.Object
implements ActionListener, AnalogListener, Control

A camera that follows a spatial and can turn around it by dragging the mouse


Field Summary
protected  Camera cam
           
protected  boolean canRotate
           
protected static java.lang.String ChaseCamDown
           
protected static java.lang.String ChaseCamMoveLeft
           
protected static java.lang.String ChaseCamMoveRight
           
protected static java.lang.String ChaseCamToggleRotate
           
protected static java.lang.String ChaseCamUp
           
protected static java.lang.String ChaseCamZoomIn
           
protected static java.lang.String ChaseCamZoomOut
           
protected  boolean chasing
           
protected  float chasingSensitivity
           
protected  float distance
           
protected  float distanceLerpFactor
           
protected  boolean dragToRotate
           
protected  boolean enabled
           
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
           
protected  float zoomSpeed
           
 
Constructor Summary
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
 
Method Summary
 Control cloneForSpatial(Spatial spatial)
          clone this camera for a spatial
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 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 isSmoothMotion()
           
 boolean isTrailingEnabled()
          returns true if the trailing is enabled
 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 applicaiton
 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 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 draging with the mouse default is 5, values over 5 should have no effect.
 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 toggleing the rotation of the cam deafult 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 zomming in the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true) mouse wheel up
 void setZoomOutTrigger(Trigger... triggers)
          Sets custom triggers for zomming 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

target

protected Spatial target

minVerticalRotation

protected float minVerticalRotation

maxVerticalRotation

protected float maxVerticalRotation

minDistance

protected float minDistance

maxDistance

protected float maxDistance

distance

protected float distance

zoomSpeed

protected float zoomSpeed

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

protected InputManager inputManager

initialUpVec

protected Vector3f 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

protected Vector3f prevPos

targetMoves

protected boolean targetMoves

enabled

protected boolean enabled

cam

protected Camera cam

targetDir

protected final Vector3f targetDir

previousTargetRotation

protected float previousTargetRotation

pos

protected final Vector3f pos

targetLocation

protected Vector3f targetLocation

dragToRotate

protected boolean dragToRotate

lookAtOffset

protected Vector3f lookAtOffset

leftClickRotate

protected boolean leftClickRotate

rightClickRotate

protected boolean rightClickRotate

temp

protected Vector3f temp

invertYaxis

protected boolean invertYaxis

invertXaxis

protected boolean invertXaxis

ChaseCamDown

protected static final java.lang.String ChaseCamDown
See Also:
Constant Field Values

ChaseCamUp

protected static final java.lang.String ChaseCamUp
See Also:
Constant Field Values

ChaseCamZoomIn

protected static final java.lang.String ChaseCamZoomIn
See Also:
Constant Field Values

ChaseCamZoomOut

protected static final java.lang.String ChaseCamZoomOut
See Also:
Constant Field Values

ChaseCamMoveLeft

protected static final java.lang.String ChaseCamMoveLeft
See Also:
Constant Field Values

ChaseCamMoveRight

protected static final java.lang.String ChaseCamMoveRight
See Also:
Constant Field Values

ChaseCamToggleRotate

protected static final java.lang.String ChaseCamToggleRotate
See Also:
Constant Field Values

zoomin

protected boolean zoomin
Constructor Detail

ChaseCamera

public ChaseCamera(Camera cam,
                   Spatial target)
Constructs the chase camera

Parameters:
cam - the application camera
target - the spatial to follow

ChaseCamera

public 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);

Parameters:
cam - the application camera

ChaseCamera

public 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);

Parameters:
cam - the application camera
inputManager - the inputManager of the application to register inputs

ChaseCamera

public ChaseCamera(Camera cam,
                   Spatial target,
                   InputManager inputManager)
Constructs 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 Detail

onAction

public void onAction(java.lang.String name,
                     boolean keyPressed,
                     float tpf)
Description copied from interface: ActionListener
Called when an input to which this listener is registered to is invoked.

Specified by:
onAction in 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.

onAnalog

public void onAnalog(java.lang.String name,
                     float value,
                     float tpf)
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 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.

registerWithInput

public final void registerWithInput(InputManager inputManager)
Registers inputs with the input manager

Parameters:
inputManager -

setToggleRotationTrigger

public void setToggleRotationTrigger(Trigger... triggers)
Sets custom triggers for toggleing the rotation of the cam deafult are new MouseButtonTrigger(MouseInput.BUTTON_LEFT) left mouse button new MouseButtonTrigger(MouseInput.BUTTON_RIGHT) right mouse button

Parameters:
triggers -

setZoomInTrigger

public void setZoomInTrigger(Trigger... triggers)
Sets custom triggers for zomming in the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true) mouse wheel up

Parameters:
triggers -

setZoomOutTrigger

public void setZoomOutTrigger(Trigger... triggers)
Sets custom triggers for zomming out the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false) mouse wheel down

Parameters:
triggers -

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


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

setMaxDistance

public void setMaxDistance(float maxDistance)
Sets the max zoom distance of the camera (default is 40)

Parameters:
maxDistance -

getMinDistance

public float getMinDistance()
Returns the min zoom distance of the camera (default is 1)

Returns:
minDistance

setMinDistance

public void setMinDistance(float minDistance)
Sets the min zoom distance of the camera (default is 1)


cloneForSpatial

public Control cloneForSpatial(Spatial spatial)
clone this camera for a spatial

Specified by:
cloneForSpatial in interface Control
Parameters:
spatial -
Returns:

setSpatial

public void setSpatial(Spatial spatial)
Sets the spacial for the camera control, should only be used internally

Specified by:
setSpatial in interface Control
Parameters:
spatial -

update

public void update(float tpf)
update the camera control, should only be used internally

Specified by:
update in interface Control
Parameters:
tpf -

render

public void render(RenderManager rm,
                   ViewPort vp)
renders the camera control, should only be used internally

Specified by:
render in interface Control
Parameters:
rm -
vp -

write

public void write(JmeExporter ex)
           throws java.io.IOException
Write the camera

Specified by:
write in interface Savable
Parameters:
ex - the exporter
Throws:
java.io.IOException

read

public void read(JmeImporter im)
          throws java.io.IOException
Read the camera

Specified by:
read in interface Savable
Parameters:
im -
Throws:
java.io.IOException

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 -

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 -

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 -

getChasingSensitivity

public float getChasingSensitivity()
returns the chasing sensitivity

Returns:

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 -

getRotationSensitivity

public float getRotationSensitivity()
Returns the rotation sensitivity

Returns:

setRotationSensitivity

public void setRotationSensitivity(float rotationSensitivity)
Sets the rotation sensitivity, the lower the value the slower the camera will rotates around the target when draging 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 -

isTrailingEnabled

public boolean isTrailingEnabled()
returns true if the trailing is enabled

Returns:

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 -

getTrailingRotationInertia

public float getTrailingRotationInertia()
returns the trailing rotation inertia

Returns:

setTrailingRotationInertia

public void setTrailingRotationInertia(float trailingRotationInertia)
Sets the trailing rotation inertia : default is 0.1. This prevent the camera to roughtly stop when the target stops moving before the camera reached the trail position. Only has an effect if smoothMotion is set to true and trailing is enabled

Parameters:
trailingRotationInertia -

getTrailingSensitivity

public float getTrailingSensitivity()
returns the trailing sensitivity

Returns:

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 -

getZoomSensitivity

public float getZoomSensitivity()
returns the zoom sensitivity

Returns:

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 5.

Parameters:
zoomSensitivity -

setDefaultDistance

public void setDefaultDistance(float defaultDistance)
Sets the default distance at start of applicaiton

Parameters:
defaultDistance -

setDefaultHorizontalRotation

public void setDefaultHorizontalRotation(float angleInRad)
sets the default horizontal rotation in radian of the camera at start of the application

Parameters:
angleInRad -

setDefaultVerticalRotation

public void setDefaultVerticalRotation(float angleInRad)
sets the default vertical rotation in radian of the camera at start of the application

Parameters:
angleInRad -

isDragToRotate

public boolean isDragToRotate()
Returns:
If drag to rotate feature is enabled.
See Also:
FlyByCamera.setDragToRotate(boolean)

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:

getHorizontalRotation

public float getHorizontalRotation()
returns the current horizontal rotation around the target in radians

Returns:

getVerticalRotation

public float getVerticalRotation()
returns the current vertical rotation around the target in radians.

Returns:

getLookAtOffset

public Vector3f getLookAtOffset()
returns the offset from the target's position where the camera looks at

Returns:

setLookAtOffset

public void setLookAtOffset(Vector3f lookAtOffset)
Sets the offset from the target's position where the camera looks at

Parameters:
lookAtOffset -

setUpVector

public void setUpVector(Vector3f up)
Sets the up vector of the camera used for the lookAt on the target

Parameters:
up -

getUpVector

public Vector3f getUpVector()
Returns the up vector of the camera used for the lookAt on the target

Returns:

setInvertVerticalAxis

public void setInvertVerticalAxis(boolean invertYaxis)
invert the vertical axis movement of the mouse

Parameters:
invertYaxis -

setInvertHorizontalAxis

public void setInvertHorizontalAxis(boolean invertXaxis)
invert the Horizontal axis movement of the mouse

Parameters:
invertXaxis -