Package com.jme3.app
Class ChaseCameraAppState
java.lang.Object
com.jme3.app.state.AbstractAppState
com.jme3.app.ChaseCameraAppState
- All Implemented Interfaces:
AppState
,ActionListener
,AnalogListener
,InputListener
This class is a camera controller that allow the camera to follow a target
Spatial.
-
Field Summary
Modifier and TypeFieldDescriptionprotected CameraNode
protected boolean
protected float
protected boolean
protected boolean
protected float
protected InputManager
protected boolean
protected boolean
protected Vector3f
protected float
protected float
protected float
protected float
protected float
protected Spatial
protected Node
protected Trigger[]
protected Vector3f
protected float
protected Trigger[]
protected Trigger[]
protected float
Fields inherited from class com.jme3.app.state.AbstractAppState
initialized
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfloat
Returns the max zoom distance of the camera (default is 40)float
float
Returns the min zoom distance of the camera (default is 1)float
float
Returns the rotation speed when the mouse is moved.float
returns the zoom speedvoid
initialize
(AppStateManager stateManager, Application app) Called byAppStateManager
when transitioning thisAppState
from initializing to running.
This will happen on the next iteration through the update loop afterAppStateManager.attach(com.jme3.app.state.AppState)
was called.boolean
void
Called when an input to which this listener is registered to is invoked.void
Called to notify the implementation that an analog event has occurred.final void
Registers inputs with the input managerprotected void
rotate the camera around the targetvoid
setDefaultDistance
(float defaultDistance) Sets the default distance at start of applicationvoid
setDefaultHorizontalRotation
(float angleInRad) sets the default horizontal rotation in radian of the camera at start of the applicationvoid
setDefaultVerticalRotation
(float angleInRad) sets the default vertical rotation in radian of the camera at start of the applicationvoid
setDragToRotate
(boolean dragToRotate) void
setInvertHorizontalAxis
(boolean invertXaxis) invert the Horizontal axis movement of the mousevoid
setInvertVerticalAxis
(boolean invertYaxis) invert the vertical axis movement of the mousevoid
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.void
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 buttonvoid
setZoomInTrigger
(Trigger... triggers) Sets custom triggers for zooming in the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true) mouse wheel upvoid
setZoomOutTrigger
(Trigger... triggers) Sets custom triggers for zooming out the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false) mouse wheel downvoid
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 theAppState
.protected void
zoomCamera
(float value) move the camera toward or away the targetMethods inherited from class com.jme3.app.state.AbstractAppState
cleanup, getId, isEnabled, isInitialized, postRender, render, setEnabled, setId, stateAttached, stateDetached
-
Field Details
-
spatial
-
target
-
camNode
-
inputManager
-
invertYaxis
protected boolean invertYaxis -
invertXaxis
protected boolean invertXaxis -
hideCursorOnRotate
protected boolean hideCursorOnRotate -
canRotate
protected boolean canRotate -
dragToRotate
protected boolean dragToRotate -
rotationSpeed
protected float rotationSpeed -
zoomSpeed
protected float zoomSpeed -
minDistance
protected float minDistance -
maxDistance
protected float maxDistance -
distance
protected float distance -
maxVerticalRotation
protected float maxVerticalRotation -
verticalRotation
protected float verticalRotation -
minVerticalRotation
protected float minVerticalRotation -
horizontalRotation
protected float horizontalRotation -
upVector
-
leftVector
-
zoomOutTrigger
-
zoomInTrigger
-
toggleRotateTrigger
-
-
Constructor Details
-
ChaseCameraAppState
public ChaseCameraAppState()
-
-
Method Details
-
initialize
Description copied from interface:AppState
Called byAppStateManager
when transitioning thisAppState
from initializing to running.
This will happen on the next iteration through the update loop afterAppStateManager.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.- Specified by:
initialize
in interfaceAppState
- Overrides:
initialize
in classAbstractAppState
- Parameters:
stateManager
- The state managerapp
- The application
-
registerWithInput
public final void registerWithInput()Registers inputs with the input manager -
onAction
Description copied from interface:ActionListener
Called when an input to which this listener is registered to is invoked.- Specified by:
onAction
in interfaceActionListener
- Parameters:
name
- The name of the mapping that was invokedkeyPressed
- True if the action is "pressed", false otherwisetpf
- The time per frame value.
-
onAnalog
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 interfaceAnalogListener
- Parameters:
name
- The name of the mapping that was invokedvalue
- Value of the axis, from 0 to 1.tpf
- The time per frame value.
-
rotateCamera
protected void rotateCamera()rotate the camera around the target -
zoomCamera
protected void zoomCamera(float value) move the camera toward or away the target- Parameters:
value
- the distance to move
-
setTarget
-
update
public void update(float tpf) Description copied from interface:AppState
Called to update theAppState
. This method will be called every render pass if theAppState
is both attached and enabled.- Specified by:
update
in interfaceAppState
- Overrides:
update
in classAbstractAppState
- Parameters:
tpf
- Time since the last call to update(), in seconds.
-
setToggleRotationTrigger
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- Parameters:
triggers
- the desired triggers
-
setZoomInTrigger
Sets custom triggers for zooming in the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true) mouse wheel up- Parameters:
triggers
- the desired triggers
-
setZoomOutTrigger
Sets custom triggers for zooming out the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false) mouse wheel down- Parameters:
triggers
- the desired triggers
-
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
- the desired maximum distance (in world units, default=40)
-
getMinDistance
public float getMinDistance()Returns the min zoom distance of the camera (default is 1)- Returns:
- the minimum distance (in world units)
-
setMinDistance
public void setMinDistance(float minDistance) Sets the min zoom distance of the camera (default is 1)- Parameters:
minDistance
- the desired minimum distance (in world units, default=1)
-
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
- the desired maximum angle (in radians, default=Pi/2)
-
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
- the desired minimum angle (in radians, default=0)
-
getZoomSpeed
public float getZoomSpeed()returns the zoom speed- Returns:
- the speed
-
setZoomSpeed
public void setZoomSpeed(float zoomSpeed) Sets the zoom speed, the lower the value, the slower the camera will zoom in and out. default is 2.- Parameters:
zoomSpeed
- the speed
-
getRotationSpeed
public float getRotationSpeed()Returns the rotation speed when the mouse is moved.- Returns:
- the rotation speed when the mouse is moved.
-
setRotationSpeed
public void setRotationSpeed(float rotationSpeed) Sets the rotate amount when user moves his mouse. The lower the value, the slower the camera will rotate. Default is 1.- Parameters:
rotationSpeed
- Rotation speed on mouse movement, default is 1.
-
setDefaultDistance
public void setDefaultDistance(float defaultDistance) Sets the default distance at start of application- Parameters:
defaultDistance
- the desired distance (in world units, default=20)
-
setDefaultHorizontalRotation
public void setDefaultHorizontalRotation(float angleInRad) sets the default horizontal rotation in radian of the camera at start of the application- Parameters:
angleInRad
- the desired rotation (in radians, default=0)
-
setDefaultVerticalRotation
public void setDefaultVerticalRotation(float angleInRad) sets the default vertical rotation in radian of the camera at start of the application- Parameters:
angleInRad
- the desired rotation (in radians, default=0)
-
isDragToRotate
public boolean isDragToRotate()- Returns:
- If drag to rotate feature is enabled.
- See Also:
-
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.
-
setInvertVerticalAxis
public void setInvertVerticalAxis(boolean invertYaxis) invert the vertical axis movement of the mouse- Parameters:
invertYaxis
- true→inverted, false→not inverted
-
setInvertHorizontalAxis
public void setInvertHorizontalAxis(boolean invertXaxis) invert the Horizontal axis movement of the mouse- Parameters:
invertXaxis
- true→inverted, false→not inverted
-