public class ChaseCameraAppState extends AbstractAppState implements ActionListener, AnalogListener
Modifier and Type | Field and Description |
---|---|
protected CameraNode |
camNode |
protected boolean |
canRotate |
protected float |
distance |
protected boolean |
dragToRotate |
protected boolean |
hideCursorOnRotate |
protected float |
horizontalRotation |
protected InputManager |
inputManager |
protected boolean |
invertXaxis |
protected boolean |
invertYaxis |
protected Vector3f |
leftVector |
protected float |
maxDistance |
protected float |
maxVerticalRotation |
protected float |
minDistance |
protected float |
minVerticalRotation |
protected float |
rotationSpeed |
protected Spatial |
spatial |
protected Node |
target |
protected Trigger[] |
toggleRotateTrigger |
protected Vector3f |
upVector |
protected float |
verticalRotation |
protected Trigger[] |
zoomInTrigger |
protected Trigger[] |
zoomOutTrigger |
protected float |
zoomSpeed |
initialized
Constructor and Description |
---|
ChaseCameraAppState() |
Modifier and Type | Method and Description |
---|---|
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 |
getRotationSpeed()
Returns the rotation speed when the mouse is moved.
|
float |
getZoomSpeed()
returns the zoom speed
|
void |
initialize(AppStateManager stateManager,
Application app)
Called by
AppStateManager when transitioning this AppState
from initializing to running.This will happen on the next iteration through the update loop after AppStateManager.attach(com.jme3.app.state.AppState) was called. |
boolean |
isDragToRotate() |
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 |
registerWithInput()
Registers inputs with the input manager
|
protected void |
rotateCamera()
rotate the camera around the target
|
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 |
setDragToRotate(boolean dragToRotate) |
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 |
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 |
setRotationSpeed(float rotationSpeed)
Sets the rotate amount when user moves his mouse, the lower the value,
the slower the camera will rotate.
|
void |
setTarget(Spatial targetSpatial) |
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 |
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 |
setZoomSpeed(float zoomSpeed)
Sets the zoom speed, the lower the value, the slower the camera will zoom
in and out.
|
void |
update(float tpf)
Called to update the
AppState . |
protected void |
zoomCamera(float value)
move the camera toward or away the target
|
cleanup, getId, isEnabled, isInitialized, postRender, render, setEnabled, setId, stateAttached, stateDetached
protected Spatial spatial
protected Node target
protected CameraNode camNode
protected InputManager inputManager
protected boolean invertYaxis
protected boolean invertXaxis
protected boolean hideCursorOnRotate
protected boolean canRotate
protected boolean dragToRotate
protected float rotationSpeed
protected float zoomSpeed
protected float minDistance
protected float maxDistance
protected float distance
protected float maxVerticalRotation
protected float verticalRotation
protected float minVerticalRotation
protected float horizontalRotation
protected Vector3f upVector
protected Vector3f leftVector
protected Trigger[] zoomOutTrigger
protected Trigger[] zoomInTrigger
protected Trigger[] toggleRotateTrigger
public void initialize(AppStateManager stateManager, Application app)
AppState
AppStateManager
when transitioning this AppState
from initializing to running.AppStateManager.attach(com.jme3.app.state.AppState)
was called.
AppStateManager
will call this only from the update loop
inside the rendering thread. This means is it safe to modify the scene
graph from this method.
initialize
in interface AppState
initialize
in class AbstractAppState
stateManager
- The state managerapp
- The applicationpublic final void registerWithInput()
public 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.protected void rotateCamera()
protected void zoomCamera(float value)
value
- the distance to movepublic void setTarget(Spatial targetSpatial)
public void update(float tpf)
AppState
AppState
. This method will be called
every render pass if the AppState
is both attached and enabled.update
in interface AppState
update
in class AbstractAppState
tpf
- Time since the last call to update(), in seconds.public void setToggleRotationTrigger(Trigger... triggers)
triggers
- the desired triggerspublic void setZoomInTrigger(Trigger... triggers)
triggers
- the desired triggerspublic void setZoomOutTrigger(Trigger... triggers)
triggers
- the desired triggerspublic float getMaxDistance()
public void setMaxDistance(float maxDistance)
maxDistance
- the desired maximum distance (in world units,
default=40)public float getMinDistance()
public void setMinDistance(float minDistance)
minDistance
- the desired minimum distance (in world units,
default=1)public float getMaxVerticalRotation()
public void setMaxVerticalRotation(float maxVerticalRotation)
maxVerticalRotation
- the desired maximum angle (in radians,
default=Pi/2)public float getMinVerticalRotation()
public void setMinVerticalRotation(float minHeight)
minHeight
- the desired minimum angle (in radians, default=0)public float getZoomSpeed()
public void setZoomSpeed(float zoomSpeed)
zoomSpeed
- the speedpublic float getRotationSpeed()
public void setRotationSpeed(float rotationSpeed)
rotationSpeed
- Rotation speed on mouse movement, default is 1.public void setDefaultDistance(float defaultDistance)
defaultDistance
- the desired distance (in world units, default=20)public void setDefaultHorizontalRotation(float angleInRad)
angleInRad
- the desired rotation (in radians, default=0)public void setDefaultVerticalRotation(float angleInRad)
angleInRad
- the desired rotation (in radians, default=0)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 setInvertVerticalAxis(boolean invertYaxis)
invertYaxis
- true→inverted, false→not invertedpublic void setInvertHorizontalAxis(boolean invertXaxis)
invertXaxis
- true→inverted, false→not inverted