Class CustomChaseCamera

  • All Implemented Interfaces:
    com.jme3.export.Savable, com.jme3.input.controls.ActionListener, com.jme3.input.controls.AnalogListener, com.jme3.input.controls.InputListener, com.jme3.scene.control.Control

    public class CustomChaseCamera
    extends java.lang.Object
    implements com.jme3.input.controls.ActionListener, com.jme3.input.controls.AnalogListener, com.jme3.scene.control.Control
    A camera that follows a spatial and can turn around it by dragging the mouse
    • Constructor Summary

      Constructors 
      Constructor Description
      CustomChaseCamera​(com.jme3.renderer.Camera cam)
      Constructs the chase camera if you use this constructor you have to attach the cam later to a spatial doing spatial.addControl(chaseCamera);
      CustomChaseCamera​(com.jme3.renderer.Camera cam, com.jme3.input.InputManager inputManager)
      Constructs the chase camera, and registers inputs if you use this constructor you have to attach the cam later to a spatial doing spatial.addControl(chaseCamera);
      CustomChaseCamera​(com.jme3.renderer.Camera cam, com.jme3.scene.Spatial target)
      Constructs the chase camera
      CustomChaseCamera​(com.jme3.renderer.Camera cam, com.jme3.scene.Spatial target, com.jme3.input.InputManager inputManager)
      Constructs the chase camera, and registers inputs
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.jme3.scene.control.Control cloneForSpatial​(com.jme3.scene.Spatial spatial)
      clone this camera for a spatial
      float getChasingSensitivity()
      returns the chasing sensitivity
      float getDistanceToTarget()
      return the current distance from the camera to the target
      float getHorizontalRotation()
      returns the current horizontal rotation around the target in radians
      com.jme3.math.Vector3f getLookAtOffset()  
      float getMaxDistance()
      Returns the max zoom distance of the camera (default is 40)
      float getMaxVerticalRotation()
      returns the maximal vertical rotation angle of the camera around the target
      float getMinDistance()
      Returns the min zoom distance of the camera (default is 1)
      float getMinVerticalRotation()
      returns the minimal vertical rotation angle of the camera around the target
      float getRotationSensitivity()
      Returns the rotation sensitivity
      float getTrailingRotationInertia()
      returns the trailing rotation inertia
      float getTrailingSensitivity()
      returns the trailing sensitivity
      com.jme3.math.Vector3f getUpVector()
      Returns the up vector of the camera used for the lookAt on the target
      float getVerticalRotation()
      returns the current vertical rotation around the target in radians.
      float getZoomSensitivity()
      returns the zoom sensitivity
      boolean isDragToRotate()  
      boolean isEnabled()
      Return the enabled/disabled state of the camera
      boolean isSmoothMotion()
      returns true is smmoth motion is enabled for this chase camera
      boolean isTrailingEnabled()
      returns true if the trailing is enabled
      void onAction​(java.lang.String name, boolean keyPressed, float tpf)  
      void onAnalog​(java.lang.String name, float value, float tpf)  
      void read​(com.jme3.export.JmeImporter im)
      Read the camera
      void registerWithInput​(com.jme3.input.InputManager inputManager)
      Registers inputs with the input manager
      void render​(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp)
      renders the camera control, should only be used internally
      void setChasingSensitivity​(float chasingSensitivity)
      Sets the chasing sensitivity, the lower the value the slower the camera will follow the target when it moves default is 5 Only has an effect if smoothMotion is set to true and trailing is enabled
      void setDefaultDistance​(float defaultDistance)
      Sets the default distance at start of applicaiton
      void setDefaultHorizontalRotation​(float angle)
      sets the default horizontal rotation of the camera at start of the application
      void setDefaultVerticalRotation​(float angle)
      sets the default vertical rotation of the camera at start of the application
      void setDragToRotate​(boolean dragToRotate)  
      void setEnabled​(boolean enabled)
      Enable or disable the camera
      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 setLookAtOffset​(com.jme3.math.Vector3f lookAtOffset)
      Sets the offset from the target's position where the camera looks at
      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 of the camera around the target default is Pi/2;
      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 of the camera around the target default is 0;
      void setRotationSensitivity​(float rotationSensitivity)
      Sets the rotation sensitivity, the lower the value the slower the camera will rotates around the target when draging with the mouse default is 5, values over 5 should have no effect.
      void setSmoothMotion​(boolean smoothMotion)
      Enables smooth motion for this chase camera
      void setSpatial​(com.jme3.scene.Spatial spatial)
      Sets the spacial for the camera control, should only be used internally
      void setToggleRotationTrigger​(com.jme3.input.controls.Trigger... triggers)
      Sets custom triggers for toggleing the rotation of the cam deafult are new MouseButtonTrigger(MouseInput.BUTTON_LEFT) left mouse button new MouseButtonTrigger(MouseInput.BUTTON_RIGHT) right mouse button
      void setTrailingEnabled​(boolean trailingEnabled)
      Enable the camera trailing : The camera smoothly go in the targets trail when it moves.
      void setTrailingRotationInertia​(float trailingRotationInertia)
      Sets the trailing rotation inertia : default is 0.1.
      void setTrailingSensitivity​(float trailingSensitivity)
      Only has an effect if smoothMotion is set to true and trailing is enabled Sets the trailing sensitivity, the lower the value, the slower the camera will go in the target trail when it moves.
      void setUpVector​(com.jme3.math.Vector3f up)
      Sets the up vector of the camera used for the lookAt on the target
      void setZoomInTrigger​(com.jme3.input.controls.Trigger... triggers)
      Sets custom triggers for zomming in the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true) mouse wheel up
      void setZoomOutTrigger​(com.jme3.input.controls.Trigger... triggers)
      Sets custom triggers for zomming out the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false) mouse wheel down
      void setZoomSensitivity​(float zoomSensitivity)
      Sets the zoom sensitivity, the lower the value, the slower the camera will zoom in and out.
      void update​(float tpf)
      update the camera control, should only be used internally
      protected void updateCamera​(float tpf)
      Updates the camera, should only be called internally
      void write​(com.jme3.export.JmeExporter ex)
      Write the camera
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • target

        protected com.jme3.scene.Spatial target
      • minVerticalRotation

        protected float minVerticalRotation
      • maxVerticalRotation

        protected float maxVerticalRotation
      • minDistance

        protected float minDistance
      • maxDistance

        protected float maxDistance
      • distance

        protected float distance
      • zoomSpeed

        protected float zoomSpeed
      • rotationSpeed

        protected float rotationSpeed
      • rotation

        protected float rotation
      • trailingRotationInertia

        protected float trailingRotationInertia
      • zoomSensitivity

        protected float zoomSensitivity
      • rotationSensitivity

        protected float rotationSensitivity
      • chasingSensitivity

        protected float chasingSensitivity
      • trailingSensitivity

        protected float trailingSensitivity
      • vRotation

        protected float vRotation
      • smoothMotion

        protected boolean smoothMotion
      • trailingEnabled

        protected boolean trailingEnabled
      • rotationLerpFactor

        protected float rotationLerpFactor
      • trailingLerpFactor

        protected float trailingLerpFactor
      • rotating

        protected boolean rotating
      • vRotating

        protected boolean vRotating
      • targetRotation

        protected float targetRotation
      • inputManager

        protected com.jme3.input.InputManager inputManager
      • initialUpVec

        protected com.jme3.math.Vector3f initialUpVec
      • targetVRotation

        protected float targetVRotation
      • vRotationLerpFactor

        protected float vRotationLerpFactor
      • targetDistance

        protected float targetDistance
      • distanceLerpFactor

        protected float distanceLerpFactor
      • zooming

        protected boolean zooming
      • trailing

        protected boolean trailing
      • chasing

        protected boolean chasing
      • canRotate

        protected boolean canRotate
      • offsetDistance

        protected float offsetDistance
      • prevPos

        protected com.jme3.math.Vector3f prevPos
      • targetMoves

        protected boolean targetMoves
      • enabled

        protected boolean enabled
      • cam

        protected com.jme3.renderer.Camera cam
      • targetDir

        protected final com.jme3.math.Vector3f targetDir
      • previousTargetRotation

        protected float previousTargetRotation
      • pos

        protected final com.jme3.math.Vector3f pos
      • targetLocation

        protected com.jme3.math.Vector3f targetLocation
      • dragToRotate

        protected boolean dragToRotate
      • lookAtOffset

        protected com.jme3.math.Vector3f lookAtOffset
      • leftClickRotate

        protected boolean leftClickRotate
      • rightClickRotate

        protected boolean rightClickRotate
      • temp

        protected com.jme3.math.Vector3f temp
      • invertYaxis

        protected boolean invertYaxis
      • invertXaxis

        protected boolean invertXaxis
      • ChaseCamZoomOut

        protected static final java.lang.String ChaseCamZoomOut
        See Also:
        Constant Field Values
      • ChaseCamMoveLeft

        protected static final java.lang.String ChaseCamMoveLeft
        See Also:
        Constant Field Values
      • ChaseCamMoveRight

        protected static final java.lang.String ChaseCamMoveRight
        See Also:
        Constant Field Values
      • ChaseCamToggleRotate

        protected static final java.lang.String ChaseCamToggleRotate
        See Also:
        Constant Field Values
    • Constructor Detail

      • CustomChaseCamera

        public CustomChaseCamera​(com.jme3.renderer.Camera cam,
                                 com.jme3.scene.Spatial target)
        Constructs the chase camera
        Parameters:
        cam - the application camera
        target - the spatial to follow
      • CustomChaseCamera

        public CustomChaseCamera​(com.jme3.renderer.Camera cam)
        Constructs the chase camera if you use this constructor you have to attach the cam later to a spatial doing spatial.addControl(chaseCamera);
        Parameters:
        cam - the application camera
      • CustomChaseCamera

        public CustomChaseCamera​(com.jme3.renderer.Camera cam,
                                 com.jme3.input.InputManager inputManager)
        Constructs the chase camera, and registers inputs if you use this constructor you have to attach the cam later to a spatial doing spatial.addControl(chaseCamera);
        Parameters:
        cam - the application camera
        inputManager - the inputManager of the application to register inputs
      • CustomChaseCamera

        public CustomChaseCamera​(com.jme3.renderer.Camera cam,
                                 com.jme3.scene.Spatial target,
                                 com.jme3.input.InputManager inputManager)
        Constructs the chase camera, and registers inputs
        Parameters:
        cam - the application camera
        target - the spatial to follow
        inputManager - the inputManager of the application to register inputs
    • Method Detail

      • onAction

        public void onAction​(java.lang.String name,
                             boolean keyPressed,
                             float tpf)
        Specified by:
        onAction in interface com.jme3.input.controls.ActionListener
      • onAnalog

        public void onAnalog​(java.lang.String name,
                             float value,
                             float tpf)
        Specified by:
        onAnalog in interface com.jme3.input.controls.AnalogListener
      • registerWithInput

        public final void registerWithInput​(com.jme3.input.InputManager inputManager)
        Registers inputs with the input manager
        Parameters:
        inputManager -
      • setToggleRotationTrigger

        public void setToggleRotationTrigger​(com.jme3.input.controls.Trigger... triggers)
        Sets custom triggers for toggleing the rotation of the cam deafult are new MouseButtonTrigger(MouseInput.BUTTON_LEFT) left mouse button new MouseButtonTrigger(MouseInput.BUTTON_RIGHT) right mouse button
        Parameters:
        triggers -
      • setZoomInTrigger

        public void setZoomInTrigger​(com.jme3.input.controls.Trigger... triggers)
        Sets custom triggers for zomming in the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true) mouse wheel up
        Parameters:
        triggers -
      • setZoomOutTrigger

        public void setZoomOutTrigger​(com.jme3.input.controls.Trigger... triggers)
        Sets custom triggers for zomming out the cam default is new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false) mouse wheel down
        Parameters:
        triggers -
      • updateCamera

        protected void updateCamera​(float tpf)
        Updates the camera, should only be called internally
      • isEnabled

        public boolean isEnabled()
        Return the enabled/disabled state of the camera
        Returns:
        true if the camera is enabled
      • setEnabled

        public void setEnabled​(boolean enabled)
        Enable or disable the camera
        Parameters:
        enabled - true to enable
      • 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 -
      • getMinDistance

        public float getMinDistance()
        Returns the min zoom distance of the camera (default is 1)
        Returns:
        minDistance
      • setMinDistance

        public void setMinDistance​(float minDistance)
        Sets the min zoom distance of the camera (default is 1)
      • cloneForSpatial

        public com.jme3.scene.control.Control cloneForSpatial​(com.jme3.scene.Spatial spatial)
        clone this camera for a spatial
        Specified by:
        cloneForSpatial in interface com.jme3.scene.control.Control
        Parameters:
        spatial -
      • setSpatial

        public void setSpatial​(com.jme3.scene.Spatial spatial)
        Sets the spacial for the camera control, should only be used internally
        Specified by:
        setSpatial in interface com.jme3.scene.control.Control
        Parameters:
        spatial -
      • update

        public void update​(float tpf)
        update the camera control, should only be used internally
        Specified by:
        update in interface com.jme3.scene.control.Control
        Parameters:
        tpf -
      • render

        public void render​(com.jme3.renderer.RenderManager rm,
                           com.jme3.renderer.ViewPort vp)
        renders the camera control, should only be used internally
        Specified by:
        render in interface com.jme3.scene.control.Control
        Parameters:
        rm -
        vp -
      • write

        public void write​(com.jme3.export.JmeExporter ex)
                   throws java.io.IOException
        Write the camera
        Specified by:
        write in interface com.jme3.export.Savable
        Parameters:
        ex - the exporter
        Throws:
        java.io.IOException
      • read

        public void read​(com.jme3.export.JmeImporter im)
                  throws java.io.IOException
        Read the camera
        Specified by:
        read in interface com.jme3.export.Savable
        Parameters:
        im -
        Throws:
        java.io.IOException
      • getMaxVerticalRotation

        public float getMaxVerticalRotation()
        returns the maximal vertical rotation angle of the camera around the target
      • setMaxVerticalRotation

        public void setMaxVerticalRotation​(float maxVerticalRotation)
        sets the maximal vertical rotation angle of the camera around the target default is Pi/2;
        Parameters:
        maxVerticalRotation -
      • getMinVerticalRotation

        public float getMinVerticalRotation()
        returns the minimal vertical rotation angle of the camera around the target
      • setMinVerticalRotation

        public void setMinVerticalRotation​(float minHeight)
        sets the minimal vertical rotation angle of the camera around the target default is 0;
        Parameters:
        minHeight -
      • isSmoothMotion

        public boolean isSmoothMotion()
        returns true is smmoth motion is enabled for this chase camera
      • setSmoothMotion

        public void setSmoothMotion​(boolean smoothMotion)
        Enables smooth motion for this chase camera
        Parameters:
        smoothMotion -
      • getChasingSensitivity

        public float getChasingSensitivity()
        returns the chasing sensitivity
      • setChasingSensitivity

        public void setChasingSensitivity​(float chasingSensitivity)
        Sets the chasing sensitivity, the lower the value the slower the camera will follow the target when it moves default is 5 Only has an effect if smoothMotion is set to true and trailing is enabled
        Parameters:
        chasingSensitivity -
      • getRotationSensitivity

        public float getRotationSensitivity()
        Returns the rotation sensitivity
      • setRotationSensitivity

        public void setRotationSensitivity​(float rotationSensitivity)
        Sets the rotation sensitivity, the lower the value the slower the camera will rotates around the target when draging with the mouse default is 5, values over 5 should have no effect. If you want a significant slow down try values below 1. Only has an effect if smoothMotion is set to true
        Parameters:
        rotationSensitivity -
      • isTrailingEnabled

        public boolean isTrailingEnabled()
        returns true if the trailing is enabled
      • setTrailingEnabled

        public void setTrailingEnabled​(boolean trailingEnabled)
        Enable the camera trailing : The camera smoothly go in the targets trail when it moves. Only has an effect if smoothMotion is set to true
        Parameters:
        trailingEnabled -
      • getTrailingRotationInertia

        public float getTrailingRotationInertia()
        returns the trailing rotation inertia
      • setTrailingRotationInertia

        public void setTrailingRotationInertia​(float trailingRotationInertia)
        Sets the trailing rotation inertia : default is 0.1. This prevent the camera to roughtly stop when the target stops moving before the camera reached the trail position. Only has an effect if smoothMotion is set to true and trailing is enabled
        Parameters:
        trailingRotationInertia -
      • getTrailingSensitivity

        public float getTrailingSensitivity()
        returns the trailing sensitivity
      • setTrailingSensitivity

        public void setTrailingSensitivity​(float trailingSensitivity)
        Only has an effect if smoothMotion is set to true and trailing is enabled Sets the trailing sensitivity, the lower the value, the slower the camera will go in the target trail when it moves. default is 0.5;
        Parameters:
        trailingSensitivity -
      • getZoomSensitivity

        public float getZoomSensitivity()
        returns the zoom sensitivity
      • setZoomSensitivity

        public void setZoomSensitivity​(float zoomSensitivity)
        Sets the zoom sensitivity, the lower the value, the slower the camera will zoom in and out. default is 5.
        Parameters:
        zoomSensitivity -
      • setDefaultDistance

        public void setDefaultDistance​(float defaultDistance)
        Sets the default distance at start of applicaiton
        Parameters:
        defaultDistance -
      • setDefaultHorizontalRotation

        public void setDefaultHorizontalRotation​(float angle)
        sets the default horizontal rotation of the camera at start of the application
        Parameters:
        angle -
      • setDefaultVerticalRotation

        public void setDefaultVerticalRotation​(float angle)
        sets the default vertical rotation of the camera at start of the application
        Parameters:
        angle -
      • isDragToRotate

        public boolean isDragToRotate()
        Returns:
        If drag to rotate feature is enabled.
        See Also:
        FlyByCamera.setDragToRotate(boolean)
      • 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.
      • getDistanceToTarget

        public float getDistanceToTarget()
        return the current distance from the camera to the target
      • getHorizontalRotation

        public float getHorizontalRotation()
        returns the current horizontal rotation around the target in radians
      • getVerticalRotation

        public float getVerticalRotation()
        returns the current vertical rotation around the target in radians.
      • getLookAtOffset

        public com.jme3.math.Vector3f getLookAtOffset()
      • setLookAtOffset

        public void setLookAtOffset​(com.jme3.math.Vector3f lookAtOffset)
        Sets the offset from the target's position where the camera looks at
        Parameters:
        lookAtOffset -
      • setUpVector

        public void setUpVector​(com.jme3.math.Vector3f up)
        Sets the up vector of the camera used for the lookAt on the target
        Parameters:
        up -
      • getUpVector

        public com.jme3.math.Vector3f getUpVector()
        Returns the up vector of the camera used for the lookAt on the target
      • setInvertVerticalAxis

        public void setInvertVerticalAxis​(boolean invertYaxis)
        invert the vertical axis movement of the mouse
        Parameters:
        invertYaxis -
      • setInvertHorizontalAxis

        public void setInvertHorizontalAxis​(boolean invertXaxis)
        invert the Horizontal axis movement of the mouse
        Parameters:
        invertXaxis -