Java Reference
In-Depth Information
Figure 10. Code segment and result of DemoColorInterpolator.java
1. public BranchGroup createSceneGraph()
2. {
3. BranchGroup objRoot = createBranchScene();
4. BoundingSphere bound = new BoundingSphere();
5. Alpha alpha = new Alpha(-1, Alpha.INCREASING_ENABLE|Alpha.DECREASING_ENABLE, 0,
6. 0, 4000, 2000, 1000, 4000, 2000, 1000);
7. Material objMaterial = new Material();
8. objMaterial.setCapability(Material.ALLOW_COMPONENT_WRITE);
9. ColorInterpolator colorInterpol = new ColorInterpolator(alpha, objMaterial);
10. colorInterpol.setStartColor(new Color3f(1f, 0f, 1f));
11. colorInterpol.setEndColor(new Color3f(0f, 1f, 0f));
12. colorInterpol.setSchedulingBounds(bound);
13. Shape3D quadColorObj = new Quad();
14. Appearance quadColorAppearance = new Appearance();
15. quadColorAppearance.setMaterial(objMaterial);
16. quadColorObj.setAppearance(quadColorAppearance);
17. TransformGroup objTilt = new TransformGroup();
18. Transform3D tiltX = new Transform3D();
19. Transform3D tiltY = new Transform3D();
20. tiltX.rotX(Math.PI/5.0d);
21. tiltY.rotY(Math.PI/5.0d);
22. tiltX.mul(tiltY);
23. objTilt.setTransform(tiltX);
24. objRoot.addChild(objTilt);
25. objTilt.addChild(colorInterpol);
26. objTilt.addChild(quadColorObj);
27. DirectionalLight light = new DirectionalLight(true, new Color3f(1f, 1f, 1f),
28. new Vector3f(-0.6f, -0.6f, -0.8f));
29. light.setInfluencingBounds(bound);
30. objRoot.addChild(light);
31. objRoot.compile();
32. return objRoot;
33. }
The object locations are set by inserting appropriate values into a Vector3f array.
A transform group is created and the translation of the Vector3f point is set.
The Billboard constructor is created and the scheduling bound is specified.
A transform group is added as a child to the object root.
Search WWH ::




Custom Search