Package com.jme3.cinematic.events
Class MotionEvent
java.lang.Object
com.jme3.cinematic.events.AbstractCinematicEvent
com.jme3.cinematic.events.MotionEvent
- All Implemented Interfaces:
CinematicEvent
,Savable
,Control
,JmeCloneable
,Cloneable
- Direct Known Subclasses:
MotionTrack
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enum for the different type of target direction behavior. -
Field Summary
Modifier and TypeFieldDescriptionprotected float
protected int
protected Vector3f
protected MotionEvent.Direction
protected Vector3f
protected MotionPath
protected Quaternion
protected Spatial
protected float
the distance traveled by the spatial on the pathprotected Vector3f
Fields inherited from class com.jme3.cinematic.events.AbstractCinematicEvent
initialDuration, listeners, loopMode, playState, resuming, speed, time
-
Constructor Summary
ConstructorDescriptionCreate MotionEvent, when using this constructor don't forget to assign spatial and path.MotionEvent
(Spatial spatial, MotionPath path) Creates a MotionPath for the given spatial on the given motion path.MotionEvent
(Spatial spatial, MotionPath path, float initialDuration) Creates a MotionPath for the given spatial on the given motion path.MotionEvent
(Spatial spatial, MotionPath path, float initialDuration, LoopMode loopMode) Creates a MotionPath for the given spatial on the given motion path.MotionEvent
(Spatial spatial, MotionPath path, LoopMode loopMode) Creates a MotionPath for the given spatial on the given motion path. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cloneFields
(Cloner cloner, Object original) Implemented to perform deep cloning for this object, resolving local cloned references using the specified cloner.cloneForSpatial
(Spatial spatial) Deprecated.float
This method is meant to be called by the motion path only.int
This method is meant to be called by the motion path only.Returns the direction the spatial is moving.Returns the direction type of the target.getPath()
Return the motion path this control follows.Returns the rotation of the target.float
Return the distance traveled by the spatial on the path.void
initEvent
(Application app, Cinematic cinematic) Initialize this event (called internally only).void
internalUpdate
(float tpf) Used internally only.boolean
jmeClone()
Performs a regular shallow clone of the object.boolean
This method is meant to be called by the motion path only.void
onPause()
Implement this method with code that you want to execute when the event is paused.void
onPlay()
Implement this method with code that you want to execute when the event is started.void
onStop()
Implement this method with code that you want to execute when the event is stopped.void
onUpdate
(float tpf) Implement this method with the code that you want to execute on update (only called when the event is playing).void
read
(JmeImporter im) Used for serialization only.void
render
(RenderManager rm, ViewPort vp) Should be called prior to queuing the spatial by the RenderManager.void
setCurrentValue
(float currentValue) This method is meant to be called by the motion path only.void
setCurrentWayPoint
(int currentWayPoint) This method is meant to be called by the motion path only.void
setDirection
(Vector3f direction) Sets the direction of the spatial, using the Y axis as the up vector.void
setDirection
(Vector3f direction, Vector3f upVector) Sets the direction of the spatial with the given up vector.void
setDirectionType
(MotionEvent.Direction directionType) Sets the direction type of the target.void
setEnabled
(boolean enabled) void
Set the lookAt for the target.void
setPath
(MotionPath path) Sets the motion path to follow.void
setRotation
(Quaternion rotation) Sets the rotation of the target.void
setSpatial
(Spatial spatial) void
setTime
(float time) Fast-forwards the event to the given timestamp.void
update
(float tpf) Updates the control.void
write
(JmeExporter ex) Used for serialization only.Methods inherited from class com.jme3.cinematic.events.AbstractCinematicEvent
addListener, dispose, forceStop, getDuration, getInitialDuration, getLoopMode, getPlayState, getSpeed, getTime, pause, play, removeListener, setInitialDuration, setLoopMode, setSpeed, stop
-
Field Details
-
spatial
-
currentWayPoint
protected int currentWayPoint -
currentValue
protected float currentValue -
direction
-
lookAt
-
upVector
-
rotation
-
directionType
-
path
-
traveledDistance
protected float traveledDistancethe 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
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
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
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
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. -
internalUpdate
public void internalUpdate(float tpf) Description copied from class:AbstractCinematicEvent
Used internally only.- Specified by:
internalUpdate
in interfaceCinematicEvent
- Overrides:
internalUpdate
in classAbstractCinematicEvent
- Parameters:
tpf
- time per frame.
-
initEvent
Description copied from class:AbstractCinematicEvent
Initialize this event (called internally only).- Specified by:
initEvent
in interfaceCinematicEvent
- Overrides:
initEvent
in classAbstractCinematicEvent
- Parameters:
app
- ignoredcinematic
- 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 interfaceCinematicEvent
- Overrides:
setTime
in classAbstractCinematicEvent
- 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 classAbstractCinematicEvent
- Parameters:
tpf
- time per frame
-
write
Description copied from class:AbstractCinematicEvent
Used for serialization only.- Specified by:
write
in interfaceSavable
- Overrides:
write
in classAbstractCinematicEvent
- Parameters:
ex
- exporter- Throws:
IOException
- from the exporter
-
read
Description copied from class:AbstractCinematicEvent
Used for serialization only.- Specified by:
read
in interfaceSavable
- Overrides:
read
in classAbstractCinematicEvent
- 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.Clone this control for the given spatial.- Specified by:
cloneForSpatial
in interfaceControl
- Parameters:
spatial
- ignored- Returns:
- never
-
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 interfaceJmeCloneable
- Returns:
- a new instance
-
cloneFields
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 interfaceJmeCloneable
- 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 classAbstractCinematicEvent
-
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 classAbstractCinematicEvent
-
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 classAbstractCinematicEvent
-
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
Returns the direction the spatial is moving.- Returns:
- the pre-existing vector
-
setDirection
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
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
Returns the direction type of the target.- Returns:
- the direction type.
-
setDirectionType
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
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
Returns the rotation of the target.- Returns:
- the rotation quaternion.
-
setRotation
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
Return the motion path this control follows.- Returns:
- the pre-existing instance
-
setPath
Sets the motion path to follow.- Parameters:
path
- the desired path (alias created)
-
setEnabled
public void setEnabled(boolean enabled) -
isEnabled
public boolean isEnabled() -
render
Description copied from interface:Control
Should be called prior to queuing the spatial by the RenderManager. This should not be called from user code. -
setSpatial
- Specified by:
setSpatial
in interfaceControl
- Parameters:
spatial
- the spatial to be controlled. This should not be called from user code.
-
getSpatial
-
getTraveledDistance
public float getTraveledDistance()Return the distance traveled by the spatial on the path.- Returns:
- the distance
-