com.jme.input
Class ThirdPersonHandler

java.lang.Object
  extended by com.jme.input.InputHandler
      extended by com.jme.input.ThirdPersonHandler

public class ThirdPersonHandler
extends InputHandler

ThirdPersonHandler defines an InputHandler that sets input to be controlled similar to games such as Zelda Windwaker and Mario 64, etc.

Version:
$Revision: 4131 $
Author:
Joshua Slack

Field Summary
protected  KeyInputAction actionBack
           
protected  KeyInputAction actionForward
           
protected  KeyInputAction actionLeft
           
protected  KeyInputAction actionRight
           
protected  KeyInputAction actionStrafeLeft
           
protected  KeyInputAction actionStrafeRight
           
static float angleEpsilon
           
protected  Vector3f calcVector
          An internal vector used for calculations to prevent object creation.
protected  Camera camera
          The camera this handler uses for determining action movement.
protected  boolean cameraAlignedMovement
          if true, movements of the character are in relation to the current camera view.
static float DEFAULT_TURNSPEED
          Default character turn speed is 1.5pi per sec.
protected  boolean doGradualRotation
          When true, the controlled target will do turns by moving forward and turning at the same time.
protected  float faceAngle
          The current facing direction of the controlled target in radians in terms of relationship to the world.
protected  Vector3f loc
          Stores the new location of the node after actions.
protected  boolean lockBackwards
          if true, backwards movement will not cause the target to rotate around to point backwards.
protected  boolean nowStrafing
          internally used boolean for denoting that a turning action is currently being performed.
protected  boolean nowTurning
          internally used boolean for denoting that a turning action is currently being performed.
protected  MovementPermitter permitter
          When not null, gives a means for denying movement to the controller.
protected  ThirdPersonJoystickPlugin plugin
           
protected  Vector3f prevLoc
          The previous location of the target node...
protected  Quaternion prevRot
          The previous rotation of the target node...
static java.lang.String PROP_CAMERAALIGNEDMOVE
           
static java.lang.String PROP_DOGRADUAL
           
static java.lang.String PROP_KEY_BACKWARD
           
static java.lang.String PROP_KEY_FORWARD
           
static java.lang.String PROP_KEY_LEFT
           
static java.lang.String PROP_KEY_RIGHT
           
static java.lang.String PROP_KEY_STRAFELEFT
           
static java.lang.String PROP_KEY_STRAFERIGHT
           
static java.lang.String PROP_LOCKBACKWARDS
           
static java.lang.String PROP_PERMITTER
           
static java.lang.String PROP_ROTATEONLY
           
static java.lang.String PROP_STRAFETARGETALIGN
           
static java.lang.String PROP_TURNSPEED
           
static java.lang.String PROP_UPVECTOR
           
protected  boolean rotateOnly
          if true, left and right keys will rotate the target instead of moving them.
protected  float speed
           
protected  boolean strafeAlignTarget
          if true, strafe movements will always be target aligned, even if other movement is camera aligned.
protected  Spatial targetSpatial
          The Spatial we are controlling with this handler.
protected  float turnSpeed
          How fast the character can turn per second.
protected  Vector3f upVector
          World up vector.
protected  boolean walkingBackwards
          internally used boolean for denoting that a backwards action is currently being performed.
protected  boolean walkingForward
          internally used boolean for denoting that a forward action is currently being performed.
 
Fields inherited from class com.jme.input.InputHandler
activeTriggers, allTriggers, AXIS_ALL, AXIS_NONE, BUTTON_ALL, BUTTON_NONE, DEVICE_ALL, DEVICE_KEYBOARD, DEVICE_MOUSE, event, mouse
 
Constructor Summary
ThirdPersonHandler(Spatial target, Camera cam)
          Basic constructor for the ThirdPersonHandler.
ThirdPersonHandler(Spatial target, Camera cam, java.util.HashMap<java.lang.String,java.lang.Object> props)
          Full constructor for the ThirdPersonHandler.
 
Method Summary
protected  void calcFaceAngle(float actAngle, float time)
          calcFaceAngle
protected  void doInputUpdate(float time)
           
 Camera getCamera()
           
 float getFaceAngle()
           
 ThirdPersonJoystickPlugin getJoystickPlugin()
           
 MovementPermitter getPermitter()
           
 float getSpeed()
           
 Spatial getTarget()
           
 float getTurnSpeed()
           
 Vector3f getUpVector()
           
 boolean isCameraAlignedMovement()
           
 boolean isDoGradualRotation()
           
 boolean isLockBackwards()
           
 boolean isNowTurning()
           
 boolean isRotateOnly()
           
 boolean isStrafeAlignTarget()
           
 boolean isStrafing()
           
 boolean isWalkingBackwards()
           
 boolean isWalkingForward()
           
protected  void setActions()
          setActions sets the keyboard actions with the corresponding key command.
 void setActionSpeed(float speed)
          Sets the speed of all actions currently registered with this handler to the given value.
 void setCameraAlignedMovement(boolean b)
           
 void setDoGradualRotation(boolean doGradualRotation)
           
 void setGoingBackwards(boolean backwards)
          Internal method used to let the handler know that the target is currently moving backwards (via use of the back key.)
 void setGoingForward(boolean forward)
          Internal method used to let the handler know that the target is currently moving forward (via use of the forward key.)
 void setJoystickPlugin(ThirdPersonJoystickPlugin plugin)
           
 void setLockBackwards(boolean b)
           
 void setRotateOnly(boolean b)
           
 void setStrafeAlignTarget(boolean b)
           
 void setStrafing(boolean strafe)
          Internal method used to let the handler know that the target is currently strafing left/right (via use of the strafe left/right keys.)
 void setTarget(Spatial target)
           
 void setTurning(boolean turning)
          Internal method used to let the handler know that the target is currently turning/moving left/right (via use of the left/right keys.)
 void setTurnSpeed(float turnSpeed)
           
 void setUpVector(Vector3f upAngle)
           
 void update(float time)
          update updates the position and rotation of the target based on the movement requested by the user.
protected  void updateFromJoystick(float time)
           
 void updateKeyBindings(java.util.HashMap<java.lang.String,java.lang.Object> props)
          updateKeyBindings allows a user to update the keys mapped to the various actions.
 void updateProperties(java.util.HashMap<java.lang.String,java.lang.Object> props)
          setProperties sets up class fields from the given hashmap.
 
Methods inherited from class com.jme.input.InputHandler
addAction, addAction, addAction, addAction, addAction, addAction, addDevice, addToAttachedHandlers, clearActions, getBooleanProp, getDevices, getFloatProp, getFromAttachedHandlers, getIntProp, getObjectProp, getParent, isEnabled, processTriggers, removeAction, removeAction, removeAllActions, removeAllFromAttachedHandlers, removeFromAttachedHandlers, setActionSpeed, setEnabled, setEnabledOfAttachedHandlers, setParent, sizeOfAttachedHandlers, updateAttachedHandlers
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_TURNSPEED

public static final java.lang.String PROP_TURNSPEED
See Also:
Constant Field Values

PROP_DOGRADUAL

public static final java.lang.String PROP_DOGRADUAL
See Also:
Constant Field Values

PROP_ROTATEONLY

public static final java.lang.String PROP_ROTATEONLY
See Also:
Constant Field Values

PROP_PERMITTER

public static final java.lang.String PROP_PERMITTER
See Also:
Constant Field Values

PROP_UPVECTOR

public static final java.lang.String PROP_UPVECTOR
See Also:
Constant Field Values

PROP_LOCKBACKWARDS

public static final java.lang.String PROP_LOCKBACKWARDS
See Also:
Constant Field Values

PROP_CAMERAALIGNEDMOVE

public static final java.lang.String PROP_CAMERAALIGNEDMOVE
See Also:
Constant Field Values

PROP_STRAFETARGETALIGN

public static final java.lang.String PROP_STRAFETARGETALIGN
See Also:
Constant Field Values

PROP_KEY_FORWARD

public static final java.lang.String PROP_KEY_FORWARD
See Also:
Constant Field Values

PROP_KEY_BACKWARD

public static final java.lang.String PROP_KEY_BACKWARD
See Also:
Constant Field Values

PROP_KEY_LEFT

public static final java.lang.String PROP_KEY_LEFT
See Also:
Constant Field Values

PROP_KEY_RIGHT

public static final java.lang.String PROP_KEY_RIGHT
See Also:
Constant Field Values

PROP_KEY_STRAFELEFT

public static final java.lang.String PROP_KEY_STRAFELEFT
See Also:
Constant Field Values

PROP_KEY_STRAFERIGHT

public static final java.lang.String PROP_KEY_STRAFERIGHT
See Also:
Constant Field Values

DEFAULT_TURNSPEED

public static final float DEFAULT_TURNSPEED
Default character turn speed is 1.5pi per sec.

See Also:
Constant Field Values

angleEpsilon

public static float angleEpsilon

speed

protected float speed

targetSpatial

protected Spatial targetSpatial
The Spatial we are controlling with this handler.


prevLoc

protected Vector3f prevLoc
The previous location of the target node... used to maintain where the node is before actions are run. This allows a comparison to see where the node wants to be taken.


prevRot

protected Quaternion prevRot
The previous rotation of the target node... used to maintain the node's rotation before actions are run. This is used when target aligned movement is used and strafing is done.


loc

protected Vector3f loc
Stores the new location of the node after actions. used internally by update method


faceAngle

protected float faceAngle
The current facing direction of the controlled target in radians in terms of relationship to the world.


turnSpeed

protected float turnSpeed
How fast the character can turn per second. Used when doGradualRotation is set to true.


doGradualRotation

protected boolean doGradualRotation
When true, the controlled target will do turns by moving forward and turning at the same time. When false, a turn will cause immediate rotation to the given angle.


permitter

protected MovementPermitter permitter
When not null, gives a means for denying movement to the controller. See MovementPermitter javadoc for more.


upVector

protected Vector3f upVector
World up vector. Currently 0,1,0 is the only guarenteed value to work.


calcVector

protected Vector3f calcVector
An internal vector used for calculations to prevent object creation.


camera

protected Camera camera
The camera this handler uses for determining action movement.


lockBackwards

protected boolean lockBackwards
if true, backwards movement will not cause the target to rotate around to point backwards. (useful for vehicle movement) Default is false.


strafeAlignTarget

protected boolean strafeAlignTarget
if true, strafe movements will always be target aligned, even if other movement is camera aligned. Default is false.


rotateOnly

protected boolean rotateOnly
if true, left and right keys will rotate the target instead of moving them. Default is false.


cameraAlignedMovement

protected boolean cameraAlignedMovement
if true, movements of the character are in relation to the current camera view. If false, they are in relation to the current target's facing vector. Default is true.


walkingBackwards

protected boolean walkingBackwards
internally used boolean for denoting that a backwards action is currently being performed.


walkingForward

protected boolean walkingForward
internally used boolean for denoting that a forward action is currently being performed.


nowTurning

protected boolean nowTurning
internally used boolean for denoting that a turning action is currently being performed.


nowStrafing

protected boolean nowStrafing
internally used boolean for denoting that a turning action is currently being performed.


plugin

protected ThirdPersonJoystickPlugin plugin

actionForward

protected KeyInputAction actionForward

actionBack

protected KeyInputAction actionBack

actionRight

protected KeyInputAction actionRight

actionLeft

protected KeyInputAction actionLeft

actionStrafeRight

protected KeyInputAction actionStrafeRight

actionStrafeLeft

protected KeyInputAction actionStrafeLeft
Constructor Detail

ThirdPersonHandler

public ThirdPersonHandler(Spatial target,
                          Camera cam)
Basic constructor for the ThirdPersonHandler. Sets all non specified args to their defaults.

Parameters:
target - the target to move
cam - the camera for movements to be in relation to

ThirdPersonHandler

public ThirdPersonHandler(Spatial target,
                          Camera cam,
                          java.util.HashMap<java.lang.String,java.lang.Object> props)
Full constructor for the ThirdPersonHandler. Properties in the props arg will be used to set handler fields if set, otherwise default values are used.

Parameters:
target - the target to move
cam - the camera for movements to be in relation to
props - a hashmap of properties used to set handler characteristics where the key is one of this class's static PROP_XXXX fields.
Method Detail

updateProperties

public void updateProperties(java.util.HashMap<java.lang.String,java.lang.Object> props)
setProperties sets up class fields from the given hashmap. It also calls updateKeyBindings for you.

Parameters:
props -

updateKeyBindings

public void updateKeyBindings(java.util.HashMap<java.lang.String,java.lang.Object> props)
updateKeyBindings allows a user to update the keys mapped to the various actions.

Parameters:
props -

setActions

protected void setActions()
setActions sets the keyboard actions with the corresponding key command.


update

public void update(float time)
update updates the position and rotation of the target based on the movement requested by the user.

Overrides:
update in class InputHandler
Parameters:
time -
See Also:
InputHandler.update(float)

doInputUpdate

protected void doInputUpdate(float time)

updateFromJoystick

protected void updateFromJoystick(float time)

calcFaceAngle

protected void calcFaceAngle(float actAngle,
                             float time)
calcFaceAngle

Parameters:
actAngle -
time -

getTurnSpeed

public float getTurnSpeed()
Returns:
Returns the turnSpeed.

setTurnSpeed

public void setTurnSpeed(float turnSpeed)
Parameters:
turnSpeed - The turnSpeed to set.

getUpVector

public Vector3f getUpVector()
Returns:
Returns the upAngle.

setUpVector

public void setUpVector(Vector3f upAngle)
Parameters:
upAngle - The upAngle to set (as copy)

getFaceAngle

public float getFaceAngle()
Returns:
Returns the faceAngle (in radians)

isDoGradualRotation

public boolean isDoGradualRotation()
Returns:
Returns the doGradualRotation.

setDoGradualRotation

public void setDoGradualRotation(boolean doGradualRotation)
Parameters:
doGradualRotation - The doGradualRotation to set.

getPermitter

public MovementPermitter getPermitter()

getTarget

public Spatial getTarget()

setTarget

public void setTarget(Spatial target)

getCamera

public Camera getCamera()

setStrafeAlignTarget

public void setStrafeAlignTarget(boolean b)

isStrafeAlignTarget

public boolean isStrafeAlignTarget()

setLockBackwards

public void setLockBackwards(boolean b)

isLockBackwards

public boolean isLockBackwards()

setRotateOnly

public void setRotateOnly(boolean b)

isRotateOnly

public boolean isRotateOnly()

setCameraAlignedMovement

public void setCameraAlignedMovement(boolean b)

isCameraAlignedMovement

public boolean isCameraAlignedMovement()

setGoingForward

public void setGoingForward(boolean forward)
Internal method used to let the handler know that the target is currently moving forward (via use of the forward key.)

Parameters:
forward -

setGoingBackwards

public void setGoingBackwards(boolean backwards)
Internal method used to let the handler know that the target is currently moving backwards (via use of the back key.)

Parameters:
backwards -

setTurning

public void setTurning(boolean turning)
Internal method used to let the handler know that the target is currently turning/moving left/right (via use of the left/right keys.)

Parameters:
turning -

setStrafing

public void setStrafing(boolean strafe)
Internal method used to let the handler know that the target is currently strafing left/right (via use of the strafe left/right keys.)

Parameters:
strafe -

isNowTurning

public boolean isNowTurning()
Returns:
true if last update of handler included a turn left/right action.

isWalkingBackwards

public boolean isWalkingBackwards()
Returns:
true if last update of handler included a walk backwards action.

isWalkingForward

public boolean isWalkingForward()
Returns:
true if last update of handler included a walk forward action.

isStrafing

public boolean isStrafing()
Returns:
true if last update of handler included a walk forward action.

setActionSpeed

public void setActionSpeed(float speed)
Description copied from class: InputHandler
Sets the speed of all actions currently registered with this handler to the given value.

Overrides:
setActionSpeed in class InputHandler
Parameters:
speed - The new speed for all currently registered actions.
See Also:
InputAction.setSpeed(float)

getSpeed

public float getSpeed()

getJoystickPlugin

public ThirdPersonJoystickPlugin getJoystickPlugin()
Returns:
Returns the joystick plugin or null if not set.

setJoystickPlugin

public void setJoystickPlugin(ThirdPersonJoystickPlugin plugin)
Parameters:
plugin - The joystick plugin to set.