Java Reference
In-Depth Information
Figure 33. First Code segment and result of Point.java
1.
public class Axis
2.
{
3.
private BranchGroup axisBG;
4.
5.
public Axis()
6.
{
7.
axisBG = new BranchGroup();
8.
IndexedPointArray array =
9.
new IndexedPointArray(11, PointArray.COORDINATES|PointArray.COLOR_3,11);
10.
11.
Point3f []pts = new Point3f[11];
12.
pts[0] = new Point3f(0.5f, 0.5f, 0.5f);
pts[1] = new Point3f(-0.5f, 0.5f, 0.5f);
13.
pts[2] = new Point3f(0.5f, 0.5f, -0.5f);
pts[3] = new Point3f(-0.5f, 0.5f, -0.5f);
14.
pts[4] = new Point3f(0.5f, -0.5f, 0.5f);
pts[5] = new Point3f(-0.5f, -0.5f, 0.5f);
15.
pts[6] = new Point3f(0.5f, -0.5f, -0.5f);
pts[7] = new Point3f(-0.5f, -0.5f, -0.5f);
16.
pts[8] = new Point3f(0f, 0.5f, 0f);
pts[9] = new Point3f(0f, -0.5f, 0f);
17.
pts[10] = new Point3f(0f, 0f, 0f);
18.
19. int []indices = {0,1,2,3,4,5,6,7,8,9,10};
20. array.setCoordinates(0,pts);
21. array.setCoordinateIndices(0, indices);
Figure 34. Second code segment and result of Point.java
22. Color3f []color = new Color3f[8];
color[0] = new Color3f(1f, 0f, 1f);
23.
color[1] = new Color3f(1f, 0f, 0f);
color[2] = new Color3f(0f, 1f, 0f);
24.
color[3] = new Color3f(0f, 0f, 1f);
color[4] = new Color3f(0f, 1f, 1f);
25.
color[5] = new Color3f(1f, 1f, 0f);
color[6] = new Color3f(0.5f, 0.5f,0f);
26. color[7] = new Color3f(1f, 1f, 1f);
27. int []colorIndices = {0,1,2,3,4,5,6,7,8,9,10};
28.
array.setColors(0,color);
29.
array.setColorIndices(0, colorIndices);
30.
31.
axisBG.addChild(new Shape3D(array));
32.
}
33.
34.
35.
public BranchGroup getBG()
36.
{
37.
return axisBG;
38.
}
39. }
Search WWH ::




Custom Search