Class FlyByCamera

java.lang.Object
com.jme3.input.FlyByCamera
All Implemented Interfaces:
ActionListener, AnalogListener, InputListener

public class FlyByCamera extends Object implements AnalogListener, ActionListener
A first-person camera controller. After creation, you (or FlyCamAppState) must register the controller using registerWithInput(com.jme3.input.InputManager). Controls: - Move (or, in drag-to-rotate mode, drag) the mouse to rotate the camera - Mouse wheel for zooming in or out - WASD keys for moving forward/backward and strafing - QZ keys raise or lower the camera
  • Field Details

    • cam

      protected Camera cam
      camera controlled by this controller (not null)
    • initialUpVec

      protected Vector3f initialUpVec
      normalized "up" direction (a unit vector)
    • rotationSpeed

      protected float rotationSpeed
      rotation-rate multiplier (1=default)
    • moveSpeed

      protected float moveSpeed
      translation speed (in world units per second)
    • zoomSpeed

      protected float zoomSpeed
      zoom-rate multiplier (1=default)
    • motionAllowed

      protected MotionAllowedListener motionAllowed
    • enabled

      protected boolean enabled
      enable flag for controller (false→ignoring input)
    • dragToRotate

      protected boolean dragToRotate
      drag-to-rotate mode flag
    • canRotate

      protected boolean canRotate
    • invertY

      protected boolean invertY
    • inputManager

      protected InputManager inputManager
  • Constructor Details

    • FlyByCamera

      public FlyByCamera(Camera cam)
      Creates a new FlyByCamera to control the specified camera.
      Parameters:
      cam - camera to be controlled (not null)
  • Method Details

    • setUpVector

      public void setUpVector(Vector3f upVec)
      Sets the up vector that should be used for the camera.
      Parameters:
      upVec - the desired direction (not null, unaffected)
    • setMotionAllowedListener

      public void setMotionAllowedListener(MotionAllowedListener listener)
    • setMoveSpeed

      public void setMoveSpeed(float moveSpeed)
      Set the translation speed.
      Parameters:
      moveSpeed - new speed (in world units per second)
    • getMoveSpeed

      public float getMoveSpeed()
      Read the translation speed.
      Returns:
      current speed (in world units per second)
    • setRotationSpeed

      public void setRotationSpeed(float rotationSpeed)
      Set the rotation-rate multiplier. The bigger the multiplier, the more rotation for a given movement of the mouse.
      Parameters:
      rotationSpeed - new rate multiplier (1=default)
    • getRotationSpeed

      public float getRotationSpeed()
      Read the rotation-rate multiplier. The bigger the multiplier, the more rotation for a given movement of the mouse.
      Returns:
      current rate multiplier (1=default)
    • setZoomSpeed

      public void setZoomSpeed(float zoomSpeed)
      Set the zoom-rate multiplier. The bigger the multiplier, the more zoom for a given movement of the mouse wheel.
      Parameters:
      zoomSpeed - new rate multiplier (1=default)
    • getZoomSpeed

      public float getZoomSpeed()
      Read the zoom-rate multiplier. The bigger the multiplier, the more zoom for a given movement of the mouse wheel.
      Returns:
      current rate multiplier (1=default)
    • setEnabled

      public void setEnabled(boolean enable)
      Enable or disable this controller. When disabled, the controller ignored input.
      Parameters:
      enable - true to enable, false to disable
    • isEnabled

      public boolean isEnabled()
      Test whether this controller is enabled.
      Returns:
      true if enabled, otherwise false
      See Also:
    • isDragToRotate

      public boolean isDragToRotate()
      Test whether drag-to-rotate mode is enabled.
      Returns:
      If drag to rotate feature is enabled.
      See Also:
    • setDragToRotate

      public void setDragToRotate(boolean dragToRotate)
      Enable or disable drag-to-rotate mode. When drag-to-rotate mode is enabled, the user must hold the mouse button and drag over the screen to rotate the camera, and the cursor is visible until dragged. When drag-to-rotate mode is disabled, the cursor is invisible at all times and holding the mouse button is not needed to rotate the camera. This mode is disabled by default.
      Parameters:
      dragToRotate - true to enable, false to disable
    • registerWithInput

      public void registerWithInput(InputManager inputManager)
      Register this controller to receive input events from the specified input manager.
      Parameters:
      inputManager - (not null, alias created)
    • mapJoystick

      protected void mapJoystick(Joystick joystick)
    • unregisterInput

      public void unregisterInput()
      Unregister this controller from its input manager.
    • rotateCamera

      protected void rotateCamera(float value, Vector3f axis)
      Rotate the camera by the specified amount around the specified axis.
      Parameters:
      value - rotation amount
      axis - direction of rotation (a unit vector)
    • zoomCamera

      protected void zoomCamera(float value)
      Zoom the camera by the specified amount.
      Parameters:
      value - zoom amount
    • riseCamera

      protected void riseCamera(float value)
      Translate the camera upward by the specified amount.
      Parameters:
      value - translation amount
    • moveCamera

      protected void moveCamera(float value, boolean sideways)
      Translate the camera left or forward by the specified amount.
      Parameters:
      value - translation amount
      sideways - true→left, false→forward
    • onAnalog

      public void onAnalog(String name, float value, float tpf)
      Callback to notify this controller of an analog input event.
      Specified by:
      onAnalog in interface AnalogListener
      Parameters:
      name - name of the input event
      value - value of the axis (from 0 to 1)
      tpf - time per frame (in seconds)
    • onAction

      public void onAction(String name, boolean value, float tpf)
      Callback to notify this controller of an action input event.
      Specified by:
      onAction in interface ActionListener
      Parameters:
      name - name of the input event
      value - true if the action is "pressed", false otherwise
      tpf - time per frame (in seconds)