|
Adding Animation Behavior to the Cube |
|
|
When the proper capability is set,the content of virtual world can be modified
at runtime. So if we can change the content continuously with time lapsing, we
can add the animation behavior to the virtual object.
Java3D provides some Interpolator classes to do this work.Through using the
subclasses of Interpolator class, we can add many animation behaviors to the
virtual object.
This program illustrates how to add the rotation behavior to the Cube by
RotationInterpolator class.
public class RotationBehavior extends JFrame {
public RotationBehavior() {
...
}
public BranchGroup createSceneGraph() {
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();
// Create the transform group node with the proper capiability
TransformGroup objSpin=new TransformGroup();
objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(objSpin);
objSpin.addChild(new ColorCube(0.4));
// Create time varying function to drive the animation
Alpha rotationAlpha=new Alpha(-1,4000);
// Create a new Behavior object that performs the desired
// operation on the specified transform object and add it into
// the scene graph.
RotationInterpolator rotator=new RotationInterpolator(rotationAlpha,objSpin);
//a bounding sphere specifies a region a behavior is active
BoundingSphere bounds=new BoundingSphere();
rotator.setSchedulingBounds(bounds);
objSpin.addChild(rotator);
return objRoot;
}
public static void main(String[] args){
...
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.