Java Reference
In-Depth Information
5 shows an example code segment on this where an object of interest is made to translate
and rotate along a set of knot/position and knot/orientation pairs. In this example, lines 15
to 20 define 5 translational positions for the object, while lines 9 to 14 specify 5 rotational
movements.
Figure 5. Code segment and result of DemoRotPosPathInterpolator.java
1. public BranchGroup createSceneGraph()
2. {
3. BranchGroup objRoot = createBranchScene();
4. TransformGroup motion = new TransformGroup();
5. motion.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
8. Transform3D someAxis = new Transform3D();
9. Quat4f[] quats = new Quat4f[5];
10. quats[0] = new Quat4f(1.0f,0.0f,0.0f,1.0f);
11. quats[1] = new Quat4f(1.0f,0.0f,1.0f,0.0f);
12. quats[2] = new Quat4f(0.0f,1.0f,1.0f,0.0f);
13. quats[3] = new Quat4f(0.0f,0.0f,0.0f,1.0f);
14. quats[4] = quats[0];
15. Point3f[] positions = new Point3f[5];
16. positions[0] = new Point3f(-0.75f, 0.75f, -0.75f);
17. positions[1] = new Point3f( 0.75f, 0.75f, -0.75f);
18. positions[2] = new Point3f(-0.75f, -0.75f, -0.25f);
19. positions[3] = new Point3f( 0.75f, -0.75f, -0.25f);
20. positions[4] = positions[0];
21. Alpha alpha = new Alpha(-1,10000);
22. float[] knots = {0.0f, 0.25f, 0.5f, 0.75f, 1.0f};
23. RotPosPathInterpolator rotpos =
24. new RotPosPathInterpolator(alpha, motion, someAxis, knots, quats, positions);
25. rotpos.setSchedulingBounds(new BoundingSphere());