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
Nested ClassesModifier and TypeClassDescriptionstatic enumEnum for the different type of target direction behavior. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected floatprotected intprotected Vector3fprotected MotionEvent.Directionprotected Vector3fprotected MotionPathprotected Quaternionprotected Spatialprotected floatthe distance traveled by the spatial on the pathprotected Vector3fFields inherited from class com.jme3.cinematic.events.AbstractCinematicEvent
initialDuration, listeners, loopMode, playState, resuming, speed, time -
Constructor Summary
ConstructorsConstructorDescriptionCreate 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 TypeMethodDescriptionvoidcloneFields(Cloner cloner, Object original) Implemented to perform deep cloning for this object, resolving local cloned references using the specified cloner.cloneForSpatial(Spatial spatial) Deprecated.floatThis method is meant to be called by the motion path only.intThis 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.floatReturn the distance traveled by the spatial on the path.voidinitEvent(Application app, Cinematic cinematic) Initialize this event (called internally only).voidinternalUpdate(float tpf) Used internally only.booleanjmeClone()Performs a regular shallow clone of the object.booleanThis method is meant to be called by the motion path only.voidonPause()Implement this method with code that you want to execute when the event is paused.voidonPlay()Implement this method with code that you want to execute when the event is started.voidonStop()Implement this method with code that you want to execute when the event is stopped.voidonUpdate(float tpf) Implement this method with the code that you want to execute on update (only called when the event is playing).voidread(JmeImporter im) Used for serialization only.voidrender(RenderManager rm, ViewPort vp) Should be called prior to queuing the spatial by the RenderManager.voidsetCurrentValue(float currentValue) This method is meant to be called by the motion path only.voidsetCurrentWayPoint(int currentWayPoint) This method is meant to be called by the motion path only.voidsetDirection(Vector3f direction) Sets the direction of the spatial, using the Y axis as the up vector.voidsetDirection(Vector3f direction, Vector3f upVector) Sets the direction of the spatial with the given up vector.voidsetDirectionType(MotionEvent.Direction directionType) Sets the direction type of the target.voidsetEnabled(boolean enabled) voidSet the lookAt for the target.voidsetPath(MotionPath path) Sets the motion path to follow.voidsetRotation(Quaternion rotation) Sets the rotation of the target.voidsetSpatial(Spatial spatial) voidsetTime(float time) Fast-forwards the event to the given timestamp.voidupdate(float tpf) Updates the control.voidwrite(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:ControlUpdates the control. This should not be called from user code. -
internalUpdate
public void internalUpdate(float tpf) Description copied from class:AbstractCinematicEventUsed internally only.- Specified by:
internalUpdatein interfaceCinematicEvent- Overrides:
internalUpdatein classAbstractCinematicEvent- Parameters:
tpf- time per frame.
-
initEvent
Description copied from class:AbstractCinematicEventInitialize this event (called internally only).- Specified by:
initEventin interfaceCinematicEvent- Overrides:
initEventin classAbstractCinematicEvent- Parameters:
app- ignoredcinematic- ignored
-
setTime
public void setTime(float time) Description copied from class:AbstractCinematicEventFast-forwards the event to the given timestamp. Time=0 is the start of the event.- Specified by:
setTimein interfaceCinematicEvent- Overrides:
setTimein classAbstractCinematicEvent- Parameters:
time- the time to fast-forward to.
-
onUpdate
public void onUpdate(float tpf) Description copied from class:AbstractCinematicEventImplement this method with the code that you want to execute on update (only called when the event is playing).- Specified by:
onUpdatein classAbstractCinematicEvent- Parameters:
tpf- time per frame
-
write
Description copied from class:AbstractCinematicEventUsed for serialization only.- Specified by:
writein interfaceSavable- Overrides:
writein classAbstractCinematicEvent- Parameters:
ex- exporter- Throws:
IOException- from the exporter
-
read
Description copied from class:AbstractCinematicEventUsed for serialization only.- Specified by:
readin interfaceSavable- Overrides:
readin 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:
cloneForSpatialin interfaceControl- Parameters:
spatial- ignored- Returns:
- never
-
jmeClone
Description copied from interface:JmeCloneablePerforms 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:
jmeClonein interfaceJmeCloneable- Returns:
- a new instance
-
cloneFields
Description copied from interface:JmeCloneableImplemented 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:
cloneFieldsin 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:AbstractCinematicEventImplement this method with code that you want to execute when the event is started.- Specified by:
onPlayin classAbstractCinematicEvent
-
onStop
public void onStop()Description copied from class:AbstractCinematicEventImplement this method with code that you want to execute when the event is stopped.- Specified by:
onStopin classAbstractCinematicEvent
-
onPause
public void onPause()Description copied from class:AbstractCinematicEventImplement this method with code that you want to execute when the event is paused.- Specified by:
onPausein 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:ControlShould be called prior to queuing the spatial by the RenderManager. This should not be called from user code. -
setSpatial
- Specified by:
setSpatialin 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
-