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

public class ChaseCameraAppState extends AbstractAppState implements ActionListener, AnalogListener
This class is a camera controller that allow the camera to follow a target Spatial.
  • Field Details

    • spatial

      protected Spatial spatial
    • target

      protected Node target
    • camNode

      protected CameraNode camNode
    • inputManager

      protected InputManager 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

      protected Vector3f upVector
    • leftVector

      protected Vector3f leftVector
    • zoomOutTrigger

      protected Trigger[] zoomOutTrigger
    • zoomInTrigger

      protected Trigger[] zoomInTrigger
    • toggleRotateTrigger

      protected Trigger[] toggleRotateTrigger
  • Constructor Details

    • ChaseCameraAppState

      public ChaseCameraAppState()
  • Method Details

    • initialize

      public void initialize(AppStateManager stateManager, Application app)
      Description copied from interface: AppState
      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.

      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 interface AppState
      Overrides:
      initialize in class AbstractAppState
      Parameters:
      stateManager - The state manager
      app - The application
    • registerWithInput

      public final void registerWithInput()
      Registers inputs with the input manager
    • onAction

      public void onAction(String name, boolean keyPressed, float tpf)
      Description copied from interface: ActionListener
      Called when an input to which this listener is registered to is invoked.
      Specified by:
      onAction in interface ActionListener
      Parameters:
      name - The name of the mapping that was invoked
      keyPressed - True if the action is "pressed", false otherwise
      tpf - The time per frame value.
    • onAnalog

      public void onAnalog(String name, float value, float tpf)
      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 interface AnalogListener
      Parameters:
      name - The name of the mapping that was invoked
      value - 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

      public void setTarget(Spatial targetSpatial)
    • update

      public void update(float tpf)
      Description copied from interface: AppState
      Called to update the AppState. This method will be called every render pass if the AppState is both attached and enabled.
      Specified by:
      update in interface AppState
      Overrides:
      update in class AbstractAppState
      Parameters:
      tpf - Time since the last call to update(), in seconds.
    • setToggleRotationTrigger

      public 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
      Parameters:
      triggers - the desired triggers
    • setZoomInTrigger

      public void setZoomInTrigger(Trigger... triggers)
      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

      public void setZoomOutTrigger(Trigger... triggers)
      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