Java Reference
In-Depth Information
Figure 4. Code segment and result of RotPathInter.java
1.
public BranchGroup createSceneGraph()
2.
{
3.
BranchGroup objRoot = new BranchGroup();
4.
5.
TransformGroup objTrans = new TransformGroup();
6.
objTrans.setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE );
7.
// this is essential for transformation in a live scene graph
8.
objRoot.addChild( objTrans );
9.
10. Transform3D coordRot = new Transform3D(); //local coordinate system is set to default
11.
12. float[] knots = { 0.0f, 0.25f, 0.5f, 0.75f, 1.0f }; //knot values to determine animation
13.
14. Quat4f[] quats = new Quat4f[5]; // quaternions values needed to determine the rotation
15. quats[0] = new Quat4f( 0.0f, -1.0f, 0.0f, 1.0f );
16. quats[1] = new Quat4f( 0.0f, 1.0f, 0.0f, 1.0f );
17. quats[2] = new Quat4f( 1.0f, 0.0f, 0.0f, 1.0f );
18. quats[3] = new Quat4f( -1.0f, 0.0f, 0.0f, 1.0f );
19. quats[4] = new Quat4f( 0.0f, -1.0f, 0.0f, 1.0f );
20.
21. Alpha rotationAlpha = new Alpha( -1, 4000 ); //continuous loop of period 4000 miliseconds
22. RotationPathInterpolator rotator =
23. new RotationPathInterpolator( rotationAlpha, objTrans, coordRot, knots, quats );
24.
25. BoundingSphere bounds = new BoundingSphere();
26. rotator.setSchedulingBounds( bounds );
27. objTrans.addChild ( rotator );
28.
// being a node leaf object, rotator have to be added to the appropriate group node.
29.
30. objTrans.addChild( new createRotPathInter() ); //a RotPathInter shape node is added.
31.
32. objRoot.compile();
33.
34. return objRoot;
35. }
rotpospathInterpolator
Combining the effects of both translation and rotation, the class RotPosPathInterpolator
allows a visual object to undergo both translation and rotation along a specified path. Figure
Search WWH ::




Custom Search