edu.cmu.sun.animation
Class AnimationPlan

java.lang.Object
  extended by edu.cmu.sun.animation.AnimationPlan

public class AnimationPlan
extends java.lang.Object

Schedules animation on Component3D objects. When the user interacts with a system, the response should be a smooth animation. However, not all animations can start right away. Sometimes we need to start an animation later on in the scene, and sometiems we need to run many animations at the same time so that components appear to be moving in relation to one another. This class allows the user to schdule animations to happen at specified times. AnimationPlan then calls methods on Component3D at the time requested to produce the entire animation.

Author:
Braden Kowitz
See Also:
TransitionManager

Field Summary
(package private)  java.util.List<ScheduledAnimation> animations
          A list of animations that will be executed when the plan is run.
(package private)  java.util.List<CleanupAction> cleanupActions
          A list of cleanup actions for this plan.
 
Constructor Summary
AnimationPlan()
          Create a new animation plan which is initially empty.
 
Method Summary
 void add(ScheduledAnimation sa)
          Add a ScheduledAnimation object to the plan.
 void addAnimationAction(Component3D target, int start, int duration, AnimationAction action)
          Allows for custom animations to be added to the plan.
 void addCleanup(Component3D itemToCleanup, Component3D parentOfItem)
          Adds a cleanup action to ths animaion.
 void addComponent(Component3D target, int msec, Component3D parent)
          Adds a component to the scene at the specified time.
 void addComponent(Component3D target, int msec, Component3D parent, boolean visible)
          Adds a component to the scene as invisible, later the visiblity is set.
 void changeRotation(Component3D target, int start, int duration, javax.vecmath.Vector3f axis, double angle)
          Convenience method to change (animate) the rotation of a component.
 void changeScale(Component3D target, int start, int duration, float scale)
          Convenience method to change (animate) the scale of a component.
 void changeScale(Component3D target, int start, int duration, javax.vecmath.Vector3f vec)
          Convenience method to change (animate) the scale of a component.
 void changeTranslation(Component3D target, int start, int duration, javax.vecmath.Vector3f vec)
          Convenience method to change (animate) the translation of a component.
 void doCleanup()
          Performs all of the cleanup actions, leaving them in the list.
private  void doZeroTimedAnimations()
          Performs all animations with a startTime of zero.
 void execute()
          Runs each ScheduledAnimation and all CleanupActions.
 void removeComponent(Component3D target, int msec, Component3D parent)
          Removes a component from the scene graph at the specified time.
 void setScale(Component3D target, int start, javax.vecmath.Vector3f vec)
          Convenience method to set (no animation) the scale of a component.
 void setTranslation(Component3D target, int start, javax.vecmath.Vector3f vec)
          Convenience method to set (no animation) the translation of a component.
 void setVisible(Component3D target, int start, boolean visibility)
          Convenience method to set (no animation) the visibility of a component.
private  void waitTill(long time, long startTime)
          Causes this thread to sleep until time provided matched the elapsed time since the provided start time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

animations

java.util.List<ScheduledAnimation> animations
A list of animations that will be executed when the plan is run.


cleanupActions

java.util.List<CleanupAction> cleanupActions
A list of cleanup actions for this plan. After the plan is executed, cleanup actions are taken.

Constructor Detail

AnimationPlan

public AnimationPlan()
Create a new animation plan which is initially empty.

Method Detail

add

public void add(ScheduledAnimation sa)
Add a ScheduledAnimation object to the plan. The plan will execute the animations with the same time in the order they are added. That is, processing is done FIFO.

Parameters:
sa -

execute

public void execute()
Runs each ScheduledAnimation and all CleanupActions. Runs through the list of SchdueledAnimations, calling doAnimation() on each one. All animations with start times of zero are animated first. Then, the list of ScheduledAnimations is sorted by start time and called in order. Finally, the function waits till the end of the animtion to return. This is a blocking function call. Also, this fucntion leaves the AnimationPlan object in a unknown state. This function should only be called once for each AnimationPlan.


waitTill

private void waitTill(long time,
                      long startTime)
Causes this thread to sleep until time provided matched the elapsed time since the provided start time.

Parameters:
time - Time to wait till, in msec
startTime - the currentTimeMillis() on the clock at the start of the animation.

doZeroTimedAnimations

private void doZeroTimedAnimations()
Performs all animations with a startTime of zero. Removes these animations from the animations list.


doCleanup

public void doCleanup()
Performs all of the cleanup actions, leaving them in the list.

See Also:
CleanupAction

changeTranslation

public void changeTranslation(Component3D target,
                              int start,
                              int duration,
                              javax.vecmath.Vector3f vec)
Convenience method to change (animate) the translation of a component.

Parameters:
target - Component to be affected by this animation
start - Start time of the animation, in milliseconds from the start.
duration - Duration of the animation, in milliseconds
vec - Translation vector to be applied to the component

changeScale

public void changeScale(Component3D target,
                        int start,
                        int duration,
                        javax.vecmath.Vector3f vec)
Convenience method to change (animate) the scale of a component.

Parameters:
target - Component to be affected by this animation
start - Start time of the animation, in milliseconds from the start.
duration - Duration of the animation, in milliseconds
vec - Scale vector to be applied to the component

changeScale

public void changeScale(Component3D target,
                        int start,
                        int duration,
                        float scale)
Convenience method to change (animate) the scale of a component.

Parameters:
target - Component to be affected by this animation
start - Start time of the animation, in milliseconds from the start.
duration - Duration of the animation, in milliseconds
scale - A uniform scaling factor.

setTranslation

public void setTranslation(Component3D target,
                           int start,
                           javax.vecmath.Vector3f vec)
Convenience method to set (no animation) the translation of a component.

Parameters:
target - Component to be affected by this animation
start - Start time of the animation, in milliseconds from the start.
vec - Translation vector to be applied to the component

setScale

public void setScale(Component3D target,
                     int start,
                     javax.vecmath.Vector3f vec)
Convenience method to set (no animation) the scale of a component.

Parameters:
target - Component to be affected by this animation
start - Start time of the animation, in milliseconds from the start.
vec - Scale vector to be applied to the component

setVisible

public void setVisible(Component3D target,
                       int start,
                       boolean visibility)
Convenience method to set (no animation) the visibility of a component.

Parameters:
target - Component to be affected by this animation
start - Start time of the animation, in milliseconds from the start.
visibility - True for visible, False for invisible.

changeRotation

public void changeRotation(Component3D target,
                           int start,
                           int duration,
                           javax.vecmath.Vector3f axis,
                           double angle)
Convenience method to change (animate) the rotation of a component.

Parameters:
target - Component to be affected by this animation
start - Start time of the animation, in milliseconds from the start.
duration - Duration of the animation, in milliseconds
axis - the axis of rotation (Yaw, Pitch, Roll) in Radians from X-axis
angle - the angle of rotation in radians.

addCleanup

public void addCleanup(Component3D itemToCleanup,
                       Component3D parentOfItem)
Adds a cleanup action to ths animaion. After the animation is done executing, all of the cleanup actions are called. TODO can ths be made private?

Parameters:
itemToCleanup -
parentOfItem -

addComponent

public void addComponent(Component3D target,
                         int msec,
                         Component3D parent)
Adds a component to the scene at the specified time. First, it makes the component invisible. Then it adds the component to the scene graph. Finally, at the specified time in the animation, the component is made visible again. This way all component added as the result of a user action will appear on the scereen at the same time.

Parameters:
target - Component to be added to the scene graph
msec - Starrt time, in msec, that the component should become visible
parent - Component to which the target is added.

addComponent

public void addComponent(Component3D target,
                         int msec,
                         Component3D parent,
                         boolean visible)
Adds a component to the scene as invisible, later the visiblity is set. First, this makes the target component invisible and adds it to the scenegraph. Then, at the specifeid time the visibility is set as specified. (the component may remain invisible)

Parameters:
target - Component to be added to the scene graph
msec - Starrt time, in msec, that the component should become visible
parent - Component to which the target is added.
visible -

removeComponent

public void removeComponent(Component3D target,
                            int msec,
                            Component3D parent)
Removes a component from the scene graph at the specified time. First, the component is made invisible at the specified time. Then, after the animation is complete, the component is removed from the scene graph.

Parameters:
target - Component to be removed from the scene graph
msec - Starrt time, in msec, that the component should become invisible
parent - Component to which the target is removed.

addAnimationAction

public void addAnimationAction(Component3D target,
                               int start,
                               int duration,
                               AnimationAction action)
Allows for custom animations to be added to the plan. Any object that provides an AnimationAction interface can be called to perform an animation at the specifeid time.

Parameters:
target - Component to be animated
start - Star time of the animation, in msec
duration - Duration of the animation, in msec
action - AnimationAction to be performed on the target.