Using Interpolator and Alpha Objects

Recipe for Using an Interpolator and Alpha Objects for Animation.

The recipe for using Interpolator and Alpha objects is very similar to using any behavior object. The major difference from the behavior usage recipe is to include the Alpha object.

  1. create the target object with the appropriate capability

  2. create the Alpha object

  3. create the Interpolator object referencing the Alpha object and target object

  4. add scheduling bounds to the Interpolator object

  5. add Interpolator object to the scene graph

public BranchGroup createSceneGraph() {
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();

// 1. create target TransformGroup with Capabilities
TransformGroup objSpin = new TransformGroup();
objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
// 2. create Alpha that continuously rotates with a period of 1 minute Alpha alpha = new Alpha (-1, 60000);

// 3. create interpolator object; by default: full rotation about y-axis RotationInterpolator rotInt = new RotationInterpolator(alpha, objSpin); // 4. add scheduling bounds rotInt.setSchedulingBounds(new BoundingSphere());

// 5. assemble scene graph
objRoot.addChild(objSpin);
objSpin.addChild(new Clock());
objRoot.addChild(rotInt);

// Let Java 3D perform optimizations on this scene graph.
objRoot.compile();

return objRoot;
} // end of CreateSceneGraph method of ClockApp