Java Reference
In-Depth Information
amount of details that need to be rendered for the object can be reduced. This will reduce
rendering time and complexity (Hu & Di, & Li, 2005).
In the example program in Figures 16 to 18, we have four switch objects. The object
in the middle will change its color between blue and red as it moves towards and away
from the user, respectively. Each of the switch objects must have its distances between the
previous and the next switch objects specified.
In this scenario, a cone object from the utility class is used along with appropriate color
attributes. Furthermore, the appearance attributes must be defined. Since PositionInterpo-
Figure 17. Second code segment of LOD.java
43. float[] distances = { 5.0f, 10.0f, 15.0f};
44. DistanceLOD distanceLOD = new DistanceLOD(distances, new Point3f());
45. distanceLOD.addSwitch(SwitchTarget);
46. distanceLOD.setSchedulingBounds(bounds);
47.
48. if((SwitchTarget.numChildren()-1) != distanceLOD.numDistances())
49. {
50. System.out.println("Error in creating LOD ");
51. }
52.
53. objRoot.addChild(objMove);
54. objRoot.addChild(positionInt);
55. objMove.addChild(distanceLOD);
56. objMove.addChild(SwitchTarget);
57.
58. // show the object at a nearer distance
59. Transform3D sCylinder = new Transform3D();
60. sCylinder.set(new Vector3f(0.7f, 0.0f, 0.0f));
61. TransformGroup smallCylinder = new TransformGroup(sCylinder);
62. objRoot.addChild(smallCylinder);
63. smallCylinder.addChild(new Cylinder(0.25f,0.25f,appB));
64.
65. // show the object at a further distance
66. sCylinder.set(new Vector3f(-10.0f, 0.0f, -30.0f));
67. TransformGroup smallCylinder1 = new TransformGroup(sCylinder);
68. objRoot.addChild(smallCylinder1);
69. smallCylinder1.addChild(new Cylinder(0.9f,0.9f,appA));
70.
71. // a white background is better for printing images in tutorial
72. Background background = new Background();
73. background.setColor(1.0f, 1.0f, 1.0f);
74. background.setApplicationBounds(new BoundingSphere());
75. objRoot.addChild(background);
76. objRoot.compile();
77. return objRoot;
78. }
Search WWH ::




Custom Search