Java Reference
In-Depth Information
Figure 35. Code segment and result of LineTrapez.java
1.
public class Axis
2.
{
3.
private BranchGroup axisBG;
4.
5.
public Axis()
6.
{
7.
axisBG = new BranchGroup();
8.
IndexedLineArray array =
9.
new IndexedLineArray(8,LineArray.COORDINATES|LineArray.COLOR_3,24);
10.
11.
Point3f []pts = new Point3f[8];
12.
pts[0] = new Point3f(0.5f, 0.75f, 0.5f);
pts[1] = new Point3f(-0.5f, 0.75f, 0.5f);
13.
pts[2] = new Point3f(0.5f, 0.75f, -0.5f);
pts[3] = new Point3f(-0.5f, 0.75f, -0.5f);
14.
pts[4] = new Point3f(0.75f, -0.25f, 0.75f);
pts[5] = new Point3f(-0.75f, -0.25f, 0.75f);
15.
pts[6] = new Point3f(0.75f, -0.25f, -0.75f);
pts[7] = new Point3f(-0.75f, -0.25f, -0.75f);
16.
17.
int []indices = {0,1,0,2,2,3,1,3,4,5,4,6,6,7,5,7,0,4,2,6,3,7,1,5};
18.
array.setCoordinates(0,pts);
19.
array.setCoordinateIndices(0, indices);
20.
21.
Color3f []color = new Color3f[8];
22.
color[0] = new Color3f(1f, 0f, 1f);
color[1] = new Color3f(1f, 0f, 0f);
23.
color[2] = new Color3f(0f, 1f, 0f);
color[3] = new Color3f(0f, 0f, 1f);
24.
color[4] = new Color3f(0f, 1f, 1f);
color[5] = new Color3f(0.5f, 0.5f, 0.5f);
25.
color[6] = new Color3f(0.5f, 0.5f,0f);
color[7] = new Color3f(1f, 1f, 1f);
26.
27.
int []colorIndices = {0,1,0,2,2,3,1,3,4,5,4,6,6,7,5,7,0,4,2,6,3,7,1,5};
28.
array.setColors(0,color);
29.
array.setColorIndices(0, colorIndices);
30.
31.
axisBG.addChild(new Shape3D(array));
32.
}
33.
34.
public BranchGroup getBG() return axisBG;
35.
36.
vertices, and joining two appropriate vertices will give a line forming one side of the object
which has a total of 12 sides.
When the constructor of Axis is invoked, a BranchGroup object axisBG will be created
in line 7. Lines 8 and 9 then create an IndexedLineArray object named array in the code
segment. This object has a vertex count of eight and an index count of 24 to construct the
Search WWH ::




Custom Search