Java Reference
In-Depth Information
Figure 40. Code segment and result of Quad.java
Index 1
Index 2
Surface B
(Inward facing)
Surface A
(Outward facing)
Index 3
Index 4
1.
public class Axis
2.
{
3.
private BranchGroup axisBG;
4.
5.
public Axis()
6.
{
7.
axisBG = new BranchGroup();
8.
IndexedQuadArray array =
9.
new IndexedQuadArray(8, QuadArray.COORDINATES|QuadArray.COLOR_3,24);
10.
11.
Point3f []pts = new Point3f[8];
12.
pts[0] = new Point3f(0.25f, 0.25f, 0.25f);
pts[1] = new Point3f(-0.25f, 0.25f, 0.25f);
13.
pts[2] = new Point3f(0.25f, 0.25f, -0.25f);
pts[3] = new Point3f(-0.25f, 0.25f, -0.25f);
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.
int []indices = {0,2,3,1,4,5,7,6,0,4,6,2,1,3,7,5,1,5,4,0,2,6,7,3};
17.
array.setCoordinates(0,pts);
18.
array.setCoordinateIndices(0, indices);
19.
20.
Color3f []color = new Color3f[8];
21.
color[0] = new Color3f(1f, 0f, 1f);
color[1] = new Color3f(1f, 0f, 0f);
22.
color[2] = new Color3f(0f, 1f, 0f);
color[3] = new Color3f(0f, 0f, 1f);
23.
color[4] = new Color3f(0f, 1f, 1f);
color[5] = new Color3f(1f, 1f, 0f);
24.
color[6] = new Color3f(0.5f, 0.5f,0f);
color[7] = new Color3f(1f, 1f, 1f);
25.
int []colorIndices = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5};
26.
array.setColors(0,color);
27.
array.setColorIndices(0, colorIndices);
28.
}
29.
30.
public BranchGroup getBG() return axisBG;
31. }
Indexedlinestriparray
The disadvantage of LineStripArray is, of course, that it is often necessary to repeat some
vertices as when a complicated solid object is to be rendered. This disadvantage is over-
 
Search WWH ::




Custom Search