com.jme.animation
Class SpatialTransformer

java.lang.Object
  extended by com.jme.scene.Controller
      extended by com.jme.animation.SpatialTransformer
All Implemented Interfaces:
Savable, java.io.Serializable

public class SpatialTransformer
extends Controller

Started Date: Jul 9, 2004

This class animates spatials by interpolating between various transformations. The user defines objects to be transformed and what rotation/translation/scale to give each object at various points in time. The user must call interpolateMissing() before using the controller in order to interpolate unspecified translation/rotation/scale.

Author:
Jack Lindamood, Philip Wainwright (bugfixes)
See Also:
Serialized Form

Nested Class Summary
static class SpatialTransformer.PointInTime
          Defines a point in time where at time time, ohject toChange[i] will assume transformation look[i].
 
Field Summary
 java.util.ArrayList<SpatialTransformer.PointInTime> keyframes
          Interpolated array of keyframe states
 int[] parentIndexes
          parentIndexes[i] states that toChange[i]'s parent is toChange[parentIndex[i]].
 Spatial[] toChange
          Refrences to the objects that will be changed.
 
Fields inherited from class com.jme.scene.Controller
RT_CLAMP, RT_CYCLE, RT_WRAP
 
Constructor Summary
SpatialTransformer()
           
SpatialTransformer(int numObjects)
          Constructs a new SpatialTransformer that will operate on numObjects Spatials
 
Method Summary
(package private)  int[] findIndicesBeforeAfter(float giventime)
          Finds indices i in keyframes such that keyframes.get(i[0]).time < giventime <= keyframes.get(i[1]).time if no keyframe was found before or after giventime, the corresponding value will clamp to 0 resp.
 float getCurTime()
          Gets the current time in the animation
 int getNumObjects()
          Returns the number of Objects used by this SpatialTransformer
 void interpolateMissing()
          This must be called one time, once all translations/rotations/scales have been set.
 void read(JMEImporter e)
           
 void setCurTime(float time)
          Sets the current time in the animation
 void setMaxTime(float maxTime)
          overridden by SpatialTransformer to always set a time inside the first and the last keyframe's time in the animation
 void setMinTime(float minTime)
          overridden by SpatialTransformer to always set a time inside the first and the last keyframe's time in the animation.
 void setNewAnimationTimes(float newBeginTime, float newEndTime)
          Sets the new animation boundaries for this controller.
 void setObject(Spatial objChange, int index, int parentIndex)
          Sets an object to animate.
 void setPosition(int indexInST, float time, Vector3f position)
          Sets object with index indexInST to translate by position at time time.
 void setRotation(int indexInST, float time, Quaternion rot)
          Sets object with index indexInST to rotate by rot at time time.
 void setScale(int indexInST, float time, Vector3f scale)
          Sets object with index indexInST to scale by scale at time time.
 void update(float time)
          Defined by extending classes, update is a signal to Controller that it should update whatever object(s) it is controlling.
 void write(JMEExporter e)
           
 
Methods inherited from class com.jme.scene.Controller
getClassTag, getControllerValues, getMaxTime, getMinTime, getRepeatType, getSpeed, isActive, setActive, setControllerValues, setRepeatType, setSpeed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

toChange

public Spatial[] toChange
Refrences to the objects that will be changed.


parentIndexes

public int[] parentIndexes
parentIndexes[i] states that toChange[i]'s parent is toChange[parentIndex[i]].


keyframes

public java.util.ArrayList<SpatialTransformer.PointInTime> keyframes
Interpolated array of keyframe states

Constructor Detail

SpatialTransformer

public SpatialTransformer()

SpatialTransformer

public SpatialTransformer(int numObjects)
Constructs a new SpatialTransformer that will operate on numObjects Spatials

Parameters:
numObjects - The number of spatials to change
Method Detail

update

public void update(float time)
Description copied from class: Controller
Defined by extending classes, update is a signal to Controller that it should update whatever object(s) it is controlling.

Specified by:
update in class Controller
Parameters:
time - The time in seconds between the last call to update and the current one

setMinTime

public void setMinTime(float minTime)
overridden by SpatialTransformer to always set a time inside the first and the last keyframe's time in the animation.

Overrides:
setMinTime in class Controller
Parameters:
minTime - The new minimum time.

setMaxTime

public void setMaxTime(float maxTime)
overridden by SpatialTransformer to always set a time inside the first and the last keyframe's time in the animation

Overrides:
setMaxTime in class Controller
Parameters:
maxTime - The new maximum time

setNewAnimationTimes

public void setNewAnimationTimes(float newBeginTime,
                                 float newEndTime)
Sets the new animation boundaries for this controller. This will start at newBeginTime and proceed in the direction of newEndTime (either forwards or backwards). If both are the same, then the animation is set to their time and turned off, otherwise the animation is turned on to start the animation acording to the repeat type. If either BeginTime or EndTime are invalid times (less than 0 or greater than the maximum set keyframe time) then a warning is set and nothing happens.
It is suggested that this function be called if new animation boundaries need to be set, instead of setMinTime and setMaxTime directly.

Parameters:
newBeginTime - The starting time
newEndTime - The ending time

getCurTime

public float getCurTime()
Gets the current time in the animation


setCurTime

public void setCurTime(float time)
Sets the current time in the animation

Parameters:
time - The time this Controller should continue at

findIndicesBeforeAfter

int[] findIndicesBeforeAfter(float giventime)
Finds indices i in keyframes such that keyframes.get(i[0]).time < giventime <= keyframes.get(i[1]).time if no keyframe was found before or after giventime, the corresponding value will clamp to 0 resp. keyframes.size() - 1


setObject

public void setObject(Spatial objChange,
                      int index,
                      int parentIndex)
Sets an object to animate. The object's index is index and it's parent index is parentIndex. A parent index of -1 indicates it has no parent.

Parameters:
objChange - The spatial that will be updated by this SpatialTransformer.
index - The index of that spatial in this transformer's array
parentIndex - The parentIndex in this transformer's array for this Spatial

setRotation

public void setRotation(int indexInST,
                        float time,
                        Quaternion rot)
Sets object with index indexInST to rotate by rot at time time.

Parameters:
indexInST - The index of the spatial to change
time - The time for the spatial to take this rotation
rot - The rotation to take

setPosition

public void setPosition(int indexInST,
                        float time,
                        Vector3f position)
Sets object with index indexInST to translate by position at time time.

Parameters:
indexInST - The index of the spatial to change
time - The time for the spatial to take this translation
position - The position to take

setScale

public void setScale(int indexInST,
                     float time,
                     Vector3f scale)
Sets object with index indexInST to scale by scale at time time.

Parameters:
indexInST - The index of the spatial to change
time - The time for the spatial to take this scale
scale - The scale to take

interpolateMissing

public void interpolateMissing()
This must be called one time, once all translations/rotations/scales have been set. It will interpolate unset values to make the animation look correct. Tail and head values are assumed to be the identity.


getNumObjects

public int getNumObjects()
Returns the number of Objects used by this SpatialTransformer

Returns:
The number of objects.

write

public void write(JMEExporter e)
           throws java.io.IOException
Specified by:
write in interface Savable
Overrides:
write in class Controller
Throws:
java.io.IOException

read

public void read(JMEImporter e)
          throws java.io.IOException
Specified by:
read in interface Savable
Overrides:
read in class Controller
Throws:
java.io.IOException