Class MotionEvent

All Implemented Interfaces:
CinematicEvent, Savable, Control, JmeCloneable, Cloneable
Direct Known Subclasses:
MotionTrack

public class MotionEvent extends AbstractCinematicEvent implements Control, JmeCloneable
A MotionEvent is a control over the spatial that manages the position and direction of the spatial while following a motion Path. You must first create a MotionPath and then create a MotionEvent to associate a spatial and the path.
  • Field Details

    • spatial

      protected Spatial spatial
    • currentWayPoint

      protected int currentWayPoint
    • currentValue

      protected float currentValue
    • direction

      protected Vector3f direction
    • lookAt

      protected Vector3f lookAt
    • upVector

      protected Vector3f upVector
    • rotation

      protected Quaternion rotation
    • directionType

      protected MotionEvent.Direction directionType
    • path

      protected MotionPath path
    • traveledDistance

      protected float traveledDistance
      the distance traveled by the spatial on the path
  • Constructor Details

    • MotionEvent

      public MotionEvent()
      Create MotionEvent, when using this constructor don't forget to assign spatial and path.
    • MotionEvent

      public MotionEvent(Spatial spatial, MotionPath path)
      Creates a MotionPath for the given spatial on the given motion path.
      Parameters:
      spatial - the Spatial to move (not null)
      path - the path to be taken (alias created)
    • MotionEvent

      public MotionEvent(Spatial spatial, MotionPath path, float initialDuration)
      Creates a MotionPath for the given spatial on the given motion path.
      Parameters:
      spatial - the Spatial to move (not null)
      path - the path to be taken (alias created)
      initialDuration - the desired duration (in seconds, default=10)
    • MotionEvent

      public MotionEvent(Spatial spatial, MotionPath path, LoopMode loopMode)
      Creates a MotionPath for the given spatial on the given motion path.
      Parameters:
      spatial - the Spatial to move (not null)
      path - the path to be taken (alias created)
      loopMode - (default=DontLoop)
    • MotionEvent

      public MotionEvent(Spatial spatial, MotionPath path, float initialDuration, LoopMode loopMode)
      Creates a MotionPath for the given spatial on the given motion path.
      Parameters:
      spatial - the Spatial to move (not null)
      path - the path to be taken (alias created)
      initialDuration - the desired duration (in seconds, default=10)
      loopMode - (default=DontLoop)
  • Method Details

    • update

      public void update(float tpf)
      Description copied from interface: Control
      Updates the control. This should not be called from user code.
      Specified by:
      update in interface Control
      Parameters:
      tpf - Time per frame.
    • internalUpdate

      public void internalUpdate(float tpf)
      Description copied from class: AbstractCinematicEvent
      Used internally only.
      Specified by:
      internalUpdate in interface CinematicEvent
      Overrides:
      internalUpdate in class AbstractCinematicEvent
      Parameters:
      tpf - time per frame.
    • initEvent

      public void initEvent(Application app, Cinematic cinematic)
      Description copied from class: AbstractCinematicEvent
      Initialize this event (called internally only).
      Specified by:
      initEvent in interface CinematicEvent
      Overrides:
      initEvent in class AbstractCinematicEvent
      Parameters:
      app - ignored
      cinematic - ignored
    • setTime

      public void setTime(float time)
      Description copied from class: AbstractCinematicEvent
      Fast-forwards the event to the given timestamp. Time=0 is the start of the event.
      Specified by:
      setTime in interface CinematicEvent
      Overrides:
      setTime in class AbstractCinematicEvent
      Parameters:
      time - the time to fast-forward to.
    • onUpdate

      public void onUpdate(float tpf)
      Description copied from class: AbstractCinematicEvent
      Implement this method with the code that you want to execute on update (only called when the event is playing).
      Specified by:
      onUpdate in class AbstractCinematicEvent
      Parameters:
      tpf - time per frame
    • write

      public void write(JmeExporter ex) throws IOException
      Description copied from class: AbstractCinematicEvent
      Used for serialization only.
      Specified by:
      write in interface Savable
      Overrides:
      write in class AbstractCinematicEvent
      Parameters:
      ex - exporter
      Throws:
      IOException - from the exporter
    • read

      public void read(JmeImporter im) throws IOException
      Description copied from class: AbstractCinematicEvent
      Used for serialization only.
      Specified by:
      read in interface Savable
      Overrides:
      read in class AbstractCinematicEvent
      Parameters:
      im - importer
      Throws:
      IOException - from the importer
    • needsDirection

      public boolean needsDirection()
      This method is meant to be called by the motion path only.
      Returns:
      true if needed, otherwise false
    • cloneForSpatial

      @Deprecated public Control cloneForSpatial(Spatial spatial)
      Deprecated.
      Clone this control for the given spatial.
      Specified by:
      cloneForSpatial in interface Control
      Parameters:
      spatial - ignored
      Returns:
      never
    • jmeClone

      public Object jmeClone()
      Description copied from interface: JmeCloneable
      Performs a regular shallow clone of the object. Some fields may also be cloned but generally only if they will never be shared with other objects. (For example, local Vector3fs and so on.)

      This method is separate from the regular clone() method so that objects might still maintain their own regular java clone() semantics (perhaps even using Cloner for those methods). However, because Java's clone() has specific features in the sense of Object's clone() implementation, it's usually best to have some path for subclasses to bypass the public clone() method that might be cloning fields and instead get at the superclass protected clone() methods. For example, through super.jmeClone() or another protected clone method that some base class eventually calls super.clone() in.

      Specified by:
      jmeClone in interface JmeCloneable
      Returns:
      a new instance
    • cloneFields

      public void cloneFields(Cloner cloner, Object original)
      Description copied from interface: JmeCloneable
      Implemented to perform deep cloning for this object, resolving local cloned references using the specified cloner. The object can call cloner.clone(fieldValue) to deep clone any of its fields.

      Note: during normal clone operations the original object will not be needed as the clone has already had all of the fields shallow copied.

      Specified by:
      cloneFields in interface JmeCloneable
      Parameters:
      cloner - The cloner that is performing the cloning operation. The cloneFields method can call back into the cloner to make clones of its subordinate fields.
      original - The original object from which this object was cloned. This is provided for the very rare case that this object needs to refer to its original for some reason. In general, all of the relevant values should have been transferred during the shallow clone, and this object need only clone what it wants.
    • onPlay

      public void onPlay()
      Description copied from class: AbstractCinematicEvent
      Implement this method with code that you want to execute when the event is started.
      Specified by:
      onPlay in class AbstractCinematicEvent
    • onStop

      public void onStop()
      Description copied from class: AbstractCinematicEvent
      Implement this method with code that you want to execute when the event is stopped.
      Specified by:
      onStop in class AbstractCinematicEvent
    • onPause

      public void onPause()
      Description copied from class: AbstractCinematicEvent
      Implement this method with code that you want to execute when the event is paused.
      Specified by:
      onPause in class AbstractCinematicEvent
    • getCurrentValue

      public float getCurrentValue()
      This method is meant to be called by the motion path only.
      Returns:
      the value
    • setCurrentValue

      public void setCurrentValue(float currentValue)
      This method is meant to be called by the motion path only.
      Parameters:
      currentValue - the desired value
    • getCurrentWayPoint

      public int getCurrentWayPoint()
      This method is meant to be called by the motion path only.
      Returns:
      the waypoint index
    • setCurrentWayPoint

      public void setCurrentWayPoint(int currentWayPoint)
      This method is meant to be called by the motion path only.
      Parameters:
      currentWayPoint - the desired waypoint index
    • getDirection

      public Vector3f getDirection()
      Returns the direction the spatial is moving.
      Returns:
      the pre-existing vector
    • setDirection

      public void setDirection(Vector3f direction)
      Sets the direction of the spatial, using the Y axis as the up vector. Use MotionEvent#setDirection((Vector3f direction,Vector3f upVector) if you want a custom up vector. This method is used by the motion path.
      Parameters:
      direction - the desired forward direction (not null, unaffected)
    • setDirection

      public void setDirection(Vector3f direction, Vector3f upVector)
      Sets the direction of the spatial with the given up vector. This method is used by the motion path.
      Parameters:
      direction - the desired forward direction (not null, unaffected)
      upVector - the up vector to consider for this direction.
    • getDirectionType

      public MotionEvent.Direction getDirectionType()
      Returns the direction type of the target.
      Returns:
      the direction type.
    • setDirectionType

      public void setDirectionType(MotionEvent.Direction directionType)
      Sets the direction type of the target. On each update the direction given to the target can have different behavior. See the Direction Enum for explanations.
      Parameters:
      directionType - the direction type.
    • setLookAt

      public void setLookAt(Vector3f lookAt, Vector3f upVector)
      Set the lookAt for the target. This can be used only if direction Type is Direction.LookAt.
      Parameters:
      lookAt - the position to look at.
      upVector - the up vector.
    • getRotation

      public Quaternion getRotation()
      Returns the rotation of the target.
      Returns:
      the rotation quaternion.
    • setRotation

      public void setRotation(Quaternion rotation)
      Sets the rotation of the target. This can be used only if direction Type is Direction.PathAndRotation or Direction.Rotation. With PathAndRotation the target will face the direction of the path multiplied by the given Quaternion. With Rotation the rotation of the target will be set with the given Quaternion.
      Parameters:
      rotation - the rotation quaternion.
    • getPath

      public MotionPath getPath()
      Return the motion path this control follows.
      Returns:
      the pre-existing instance
    • setPath

      public void setPath(MotionPath path)
      Sets the motion path to follow.
      Parameters:
      path - the desired path (alias created)
    • setEnabled

      public void setEnabled(boolean enabled)
    • isEnabled

      public boolean isEnabled()
    • render

      public void render(RenderManager rm, ViewPort vp)
      Description copied from interface: Control
      Should be called prior to queuing the spatial by the RenderManager. This should not be called from user code.
      Specified by:
      render in interface Control
      Parameters:
      rm - the caller (not null)
      vp - the relevant ViewPort (not null)
    • setSpatial

      public void setSpatial(Spatial spatial)
      Specified by:
      setSpatial in interface Control
      Parameters:
      spatial - the spatial to be controlled. This should not be called from user code.
    • getSpatial

      public Spatial getSpatial()
    • getTraveledDistance

      public float getTraveledDistance()
      Return the distance traveled by the spatial on the path.
      Returns:
      the distance