Skip to main content

Combine two tranform group?

1 reply [Last post]
it2512
Offline
Joined: 2010-10-16

i was reading the tutorial, and saw an exmple:

3. BranchGroup objRoot = new BranchGroup();
4.
5. // rotate object has composite transformation matrix
6. Transform3D rotate = new Transform3D();
7. Transform3D tempRotate = new Transform3D();
8.
9. rotate.rotX(Math.PI/4.0d);
10. tempRotate.rotY(Math.PI/5.0d);
11. rotate.mul(tempRotate);
12.
13. TransformGroup objRotate = new TransformGroup(rotate);
14.
15. // Create the transform group node and initialize it to the
16. // identity. Enable the TRANSFORM_WRITE capability so that
17. // our behavior code can modify it at runtime. Add it to the
18. // root of the subgraph.
19. TransformGroup objSpin = new TransformGroup();
20. objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
21.
22. objRoot.addChild(objRotate);
23. objRotate.addChild(objSpin);
24.
25. // Create a simple shape leaf node, add it to the scene graph.
26. // ColorCube is a Convenience Utility class
27. objSpin.addChild(new ColorCube(0.4));
28.
29. // Create a new Behavior object that performs the desired
30. // operation on the specified transform object and add it into
31. // the scene graph.
32. Transform3D yAxis = new Transform3D();
33. Alpha rotationAlpha = new Alpha(-1, 4000);
34.
35. RotationInterpolator rotator =
36. new RotationInterpolator(rotationAlpha, objSpin, yAxis,
37. 0.0f, (float) Math.PI*2.0f);
38.
39. // a bounding sphere specifies a region a behavior is active
40. // create a sphere centered at the origin with radius of 1
41. BoundingSphere bounds = new BoundingSphere();
42. rotator.setSchedulingBounds(bounds);
43. objSpin.addChild(rotator);
44.
45. return objRoot;
46. } // end of createSceneGraph method of HelloJava3Dd

so , the scene graph tree is like : BG -> TG1 -> TG2 -> cube
TG1 contain rotation
TG2 contain behaviour

i was thinking it is possible combine this 2 TG together? like: BG -> TG1 -> cube
TG1 contain rotation and behaviour.

i tried to run the program, and found that rotation disappear.
ah, anyone can solve my confusion? thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
it2512
Offline
Joined: 2010-10-16

some more, if i changed:

objRoot.addChild(objRotate);
objRotate.addChild(objSpin);

---->>

objRoot.addChild(objSpin);
objSpin.addChild(objRotate);

i found that the cube will just spin without rotate. and i thought because the spin will execute unlimited time ( because alpha = -1) , so i change alpha to a reachable value and execute again. and i found that, when the cube stop spin, the angle still remain same.

any idea?