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
FieldsModifier and TypeFieldDescriptionprotected CameraNodeprotected booleanprotected floatprotected booleanprotected booleanprotected floatprotected InputManagerprotected booleanprotected booleanprotected Vector3fprotected floatprotected floatprotected floatprotected floatprotected floatprotected Spatialprotected Nodeprotected Trigger[]protected Vector3fprotected floatprotected Trigger[]protected Trigger[]protected floatFields inherited from class com.jme3.app.state.AbstractAppState
initialized -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfloatReturns the max zoom distance of the camera (default is 40)floatfloatReturns the min zoom distance of the camera (default is 1)floatfloatReturns the rotation speed when the mouse is moved.floatreturns the zoom speedvoidinitialize(AppStateManager stateManager, Application app) Called byAppStateManagerwhen transitioning thisAppStatefrom initializing to running.
This will happen on the next iteration through the update loop afterAppStateManager.attach(com.jme3.app.state.AppState)was called.booleanvoidCalled when an input to which this listener is registered to is invoked.voidCalled to notify the implementation that an analog event has occurred.final voidRegisters inputs with the input managerprotected voidrotate the camera around the targetvoidsetDefaultDistance(float defaultDistance) Sets the default distance at start of applicationvoidsetDefaultHorizontalRotation(float angleInRad) sets the default horizontal rotation in radian of the camera at start of the applicationvoidsetDefaultVerticalRotation(float angleInRad) sets the default vertical rotation in radian of the camera at start of the applicationvoidsetDragToRotate(boolean dragToRotate) voidsetInvertHorizontalAxis(boolean invertXaxis) invert the Horizontal axis movement of the mousevoidsetInvertVerticalAxis(boolean invertYaxis) invert the vertical axis movement of the mousevoidsetMaxDistance(float maxDistance) Sets the max zoom distance of the camera (default is 40)voidsetMaxVerticalRotation(float maxVerticalRotation) Sets the maximal vertical rotation angle in radian of the camera around the target.voidsetMinDistance(float minDistance) Sets the min zoom distance of the camera (default is 1)voidsetMinVerticalRotation(float minHeight) Sets the minimal vertical rotation angle in radian of the camera around the target default is 0;voidsetRotationSpeed(float rotationSpeed) Sets the rotate amount when user moves his mouse.voidvoidsetToggleRotationTrigger(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 buttonvoidsetZoomInTrigger(Trigger... triggers) Sets custom triggers for zooming in the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true) mouse wheel upvoidsetZoomOutTrigger(Trigger... triggers) Sets custom triggers for zooming out the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false) mouse wheel downvoidsetZoomSpeed(float zoomSpeed) Sets the zoom speed, the lower the value, the slower the camera will zoom in and out.voidupdate(float tpf) Called to update theAppState.protected voidzoomCamera(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:AppStateCalled byAppStateManagerwhen transitioning thisAppStatefrom initializing to running.
This will happen on the next iteration through the update loop afterAppStateManager.attach(com.jme3.app.state.AppState)was called.AppStateManagerwill 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:
initializein interfaceAppState- Overrides:
initializein classAbstractAppState- Parameters:
stateManager- The state managerapp- The application
-
registerWithInput
public final void registerWithInput()Registers inputs with the input manager -
onAction
Description copied from interface:ActionListenerCalled when an input to which this listener is registered to is invoked.- Specified by:
onActionin 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:AnalogListenerCalled to notify the implementation that an analog event has occurred. The results of KeyTrigger and MouseButtonTrigger events will have tpf == value.- Specified by:
onAnalogin 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:AppStateCalled to update theAppState. This method will be called every render pass if theAppStateis both attached and enabled.- Specified by:
updatein interfaceAppState- Overrides:
updatein 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
-