|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jme.input.InputHandler
com.jme.input.ChaseCamera
public class ChaseCamera
Camera handler that will smoothly follow a set scene element, allowing for rotation about and zoom on that element.
see the javadoc for update(float time) for information on how positioning works.
Field Summary | |
---|---|
protected Camera |
cam
|
protected Vector3f |
compVect
|
protected float |
dampingK
|
static float |
DEFAULT_DAMPINGK
|
static boolean |
DEFAULT_ENABLESPRING
|
static boolean |
DEFAULT_MAINTAINAZIMUTH
|
static float |
DEFAULT_MAXDISTANCE
|
static float |
DEFAULT_MINDISTANCE
|
static float |
DEFAULT_SPRINGK
|
static boolean |
DEFAULT_STAYBEHINDTARGET
|
static Vector3f |
DEFAULT_WORLDUPVECTOR
|
protected Vector3f |
dirVec
|
protected boolean |
enableSpring
|
protected boolean |
forceAzimuthUpdate
|
protected Vector3f |
idealPosition
|
protected Vector3f |
idealSphereCoords
|
protected Vector3f |
leftVec
|
protected boolean |
looking
|
protected boolean |
maintainAzimuth
|
protected float |
maxDistance
|
protected float |
minDistance
|
protected ThirdPersonMouseLook |
mouseLook
The ThirdPersonMouseLook action, kept as a field to allow easy access to setting speeds and y axis flipping. |
protected Vector3f |
oldCameraDir
|
static java.lang.String |
PROP_DAMPINGK
|
static java.lang.String |
PROP_ENABLESPRING
|
static java.lang.String |
PROP_INITIALSPHERECOORDS
|
static java.lang.String |
PROP_MAINTAINAZIMUTH
|
static java.lang.String |
PROP_MAXDISTANCE
|
static java.lang.String |
PROP_MINDISTANCE
|
static java.lang.String |
PROP_SPRINGK
|
static java.lang.String |
PROP_STAYBEHINDTARGET
|
static java.lang.String |
PROP_TARGETOFFSET
|
static java.lang.String |
PROP_WORLDUPVECTOR
|
protected float |
speed
|
protected float |
springK
|
protected boolean |
stayBehindTarget
|
protected Spatial |
target
|
protected Vector3f |
targetOffset
|
protected Vector3f |
targetPos
|
protected Vector3f |
upVec
|
protected Vector3f |
velocity
|
protected Vector3f |
worldUpVec
|
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 | |
---|---|
ChaseCamera(Camera cam,
Spatial target)
Simple constructor that accepts a Camera and a target and sets all properties to their defaults. |
|
ChaseCamera(Camera cam,
Spatial target,
java.util.Map<java.lang.String,java.lang.Object> props)
More involved constructor allowing the setting of all member fields in ChaseCamera and its associated ThirdPersonMouseLook object via a Map of properties. |
Method Summary | |
---|---|
protected void |
convertIdealSphereToCartesian()
|
protected void |
enforceMinMaxDistance(Vector3f camPos)
|
Camera |
getCamera()
|
float |
getDampingK()
|
Vector3f |
getIdealPosition()
|
Vector3f |
getIdealSphereCoords()
|
float |
getMaxDistance()
|
float |
getMinDistance()
|
ThirdPersonMouseLook |
getMouseLook()
|
float |
getSpeed()
|
float |
getSpringK()
|
Spatial |
getTarget()
|
Vector3f |
getTargetOffset()
|
boolean |
isEnableSpring()
|
boolean |
isForceAzimuthUpdate()
|
boolean |
isLooking()
|
boolean |
isMaintainAzimuth()
|
boolean |
isStayBehindTarget()
|
void |
setActionSpeed(float speed)
Sets the speed of all actions currently registered with this handler to the given value. |
void |
setCamera(Camera cam)
|
void |
setDampingK(float dampingK)
|
void |
setEnableSpring(boolean disableSpring)
|
void |
setForceAzimuthUpdate(boolean forceAzimuthUpdate)
|
void |
setIdealSphereCoords(Vector3f idealSphereCoords)
|
void |
setLooking(boolean b)
|
void |
setMaintainAzimuth(boolean b)
|
void |
setMaxDistance(float maxDistance)
|
void |
setMinDistance(float distance)
|
void |
setSpringK(float springK)
|
void |
setStayBehindTarget(boolean stayBehind)
|
void |
setTarget(Spatial target)
|
void |
setTargetOffset(Vector3f targetOffset)
|
protected void |
setupMouse()
Set up a relative mouse and the ThirdPersonMouseLook used in this camera's control. |
void |
setWorldUpVec(Vector3f worldUpVec)
|
void |
update(float time)
update repositions the camera based on the current
position and an ideal position using spherical coordinates. |
protected void |
updateCameraPosition(float time,
Vector3f camPos)
|
protected void |
updateIdealAzimuth(float time,
Vector3f camPos)
|
void |
updateProperties(java.util.Map<java.lang.String,java.lang.Object> props)
updateProperties allows you to update all properties of
this chase camera and its related mouse look class. |
protected void |
updateTargetPosition(Vector3f camPos)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String PROP_INITIALSPHERECOORDS
public static final java.lang.String PROP_DAMPINGK
public static final java.lang.String PROP_SPRINGK
public static final java.lang.String PROP_TARGETOFFSET
public static final java.lang.String PROP_WORLDUPVECTOR
public static final java.lang.String PROP_ENABLESPRING
public static final java.lang.String PROP_STAYBEHINDTARGET
public static final java.lang.String PROP_MAINTAINAZIMUTH
public static final java.lang.String PROP_MAXDISTANCE
public static final java.lang.String PROP_MINDISTANCE
public static final float DEFAULT_DAMPINGK
public static final float DEFAULT_SPRINGK
public static final float DEFAULT_MAXDISTANCE
public static final float DEFAULT_MINDISTANCE
public static final boolean DEFAULT_ENABLESPRING
public static final boolean DEFAULT_STAYBEHINDTARGET
public static final boolean DEFAULT_MAINTAINAZIMUTH
public static final Vector3f DEFAULT_WORLDUPVECTOR
protected Vector3f idealSphereCoords
protected Vector3f idealPosition
protected Camera cam
protected Vector3f velocity
protected Spatial target
protected float dampingK
protected float springK
protected float maxDistance
protected float minDistance
protected boolean enableSpring
protected boolean stayBehindTarget
protected boolean looking
protected boolean maintainAzimuth
protected boolean forceAzimuthUpdate
protected Vector3f dirVec
protected Vector3f worldUpVec
protected Vector3f upVec
protected Vector3f leftVec
protected Vector3f targetOffset
protected Vector3f targetPos
protected Vector3f oldCameraDir
protected Vector3f compVect
protected ThirdPersonMouseLook mouseLook
protected float speed
Constructor Detail |
---|
public ChaseCamera(Camera cam, Spatial target)
cam
- Camera to controltarget
- the target node to chasepublic ChaseCamera(Camera cam, Spatial target, java.util.Map<java.lang.String,java.lang.Object> props)
cam
- Camera to controltarget
- the target node to chaseprops
- a hashmap of properties to set this camera up with. keys are
from the statics ChaseCamera.PROP_XXXX and
ThirdPersonMouseLook.PROP_XXXXMethod Detail |
---|
protected void setupMouse()
public void updateProperties(java.util.Map<java.lang.String,java.lang.Object> props)
updateProperties
allows you to update all properties of
this chase camera and its related mouse look class.
props
- public void setCamera(Camera cam)
public Camera getCamera()
public void update(float time)
update
repositions the camera based on the current
position and an ideal position using spherical coordinates.
The new position is determined by checking where the target has moved to and getting an offset in relation to the XZ plane. Using this, the ideal spherical coordiantes for the camera are updated for the angle around the up axis (azimuth). Thus, ideal height and distance from the target are still the same regardless of how far the target has moved.
Next, we using a spring system to move from the camera's current position to the calculated "ideal position". This is done by accelerating towards the ideal position using the amount of that distance and the springK factor. This acceleration is damped by the dampingK factor amplified by the magnitude of the current velocity of the camera.
The springK and dampingK factors can be expressed as a damping ratio:
ratio = dampingK / (2 * sqrt(springK))
Typically you want the ratio to come out equal to 1. Values less than 1 will ocillate before coming to rest. Values over 1 will take longer than necessary to come to equilibrium.
Note that if disableSpring is true, the currentPosition is always set to the idealPosition.
See Game programming Gems #4 pgs 303-307 for more in-depth information on the technique.
update
in class InputHandler
time
- amount of time since last update (in seconds)InputHandler.update(float)
protected void updateCameraPosition(float time, Vector3f camPos)
protected void updateTargetPosition(Vector3f camPos)
protected void enforceMinMaxDistance(Vector3f camPos)
protected void convertIdealSphereToCartesian()
protected void updateIdealAzimuth(float time, Vector3f camPos)
public Vector3f getIdealSphereCoords()
public Vector3f getIdealPosition()
public float getMaxDistance()
public void setMaxDistance(float maxDistance)
maxDistance
- The maxDistance to set. If <= 0 (default is 0) then
maxDistance is ignored.public float getMinDistance()
public void setMinDistance(float distance)
distance
- The minDistance to set. If <= 0 (default is 0) then
minDistance is ignored.public float getDampingK()
public void setDampingK(float dampingK)
dampingK
- The dampingK to set.public float getSpringK()
public void setSpringK(float springK)
springK
- The springK to set.public Spatial getTarget()
public void setTarget(Spatial target)
target
- The target to setpublic Vector3f getTargetOffset()
public void setTargetOffset(Vector3f targetOffset)
targetOffset
- The targetOffset to set (as copy)public void setWorldUpVec(Vector3f worldUpVec)
worldUpVec
- The worldUpVec to set (as copy)public ThirdPersonMouseLook getMouseLook()
public boolean isEnableSpring()
public void setEnableSpring(boolean disableSpring)
disableSpring
- The disableSpring to set.public boolean isStayBehindTarget()
public void setStayBehindTarget(boolean stayBehind)
stayBehind
- true if we want the camera to stay behind the targetpublic void setActionSpeed(float speed)
InputHandler
setActionSpeed
in class InputHandler
speed
- The new speed for all currently registered actions.InputAction.setSpeed(float)
public float getSpeed()
public void setLooking(boolean b)
public boolean isLooking()
public void setMaintainAzimuth(boolean b)
public boolean isMaintainAzimuth()
public boolean isForceAzimuthUpdate()
public void setForceAzimuthUpdate(boolean forceAzimuthUpdate)
public void setIdealSphereCoords(Vector3f idealSphereCoords)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |