Java Reference
In-Depth Information
level of detaIl (lod)
This makes use of the DistanceLOD class to manage variation in the display as the distance
between the user and visual objects is changed. Specifically, if the distance is increased, the
Figure 16. First code segment of LOD.java
1. import java.applet.Applet;
2. import java.awt.BorderLayout;
3. import java.awt.Frame;
4. import com.sun.j3d.utils.applet.MainFrame;
5. import com.sun.j3d.utils.geometry.*;
6. import com.sun.j3d.utils.universe.*;
7. import javax.media.j3d.*;
8. import javax.vecmath.*;
9. public class LOD extends Applet
10. {
11. public BranchGroup createSceneGraph()
12. {
13. BranchGroup objRoot = new BranchGroup();
14. BoundingSphere bounds = new BoundingSphere();
15. TransformGroup objMove = new TransformGroup();
16. objMove.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
17. Alpha alpha = new Alpha (-1, Alpha.INCREASING_ENABLE + Alpha.DECREASING_ENABLE,
18. 0, 0, 5000, 1000, 1000, 5000, 1000, 1000);
19. AxisAngle4f axisTrans = new AxisAngle4f(0.0f,1.0f,0.0f,(float)Math.PI/-2.0f); // translation axis
20. Transform3D T3D= new Transform3D();
21. T3D.set(axisTrans);
22.
23. // create position interpolator
24. PositionInterpolator positionInt = new PositionInterpolator (alpha, objMove, T3D, -2.5f, -25.0f);
25. positionInt.setSchedulingBounds(bounds);
26.
27. // create DistanceLOD target object
28. Switch SwitchTarget = new Switch();
29. SwitchTarget.setCapability(Switch.ALLOW_SWITCH_WRITE);
30.
31. ColoringAttributes caA = new ColoringAttributes();
32. caA.setColor(1.0f,0.0f,0.0f);
33. Appearance appA = new Appearance();
34. appA.setColoringAttributes(caA);
35. ColoringAttributes caB = new ColoringAttributes();
36. caB.setColor(0.0f,0.0f,1.0f);
37. Appearance appB = new Appearance();
38. appB.setColoringAttributes(caB);
39. SwitchTarget.addChild(new Cylinder(0.9f,0.9f,appA));
40. SwitchTarget.addChild(new Cylinder(0.75f,0.75f,appB));
41. SwitchTarget.addChild(new Cylinder(0.5f,0.5f,appA));
42. SwitchTarget.addChild(new Cylinder(0.25f,0.25f,appB));
Search WWH ::




Custom Search