Java Reference
In-Depth Information
enough. Apart from the number of points used, the drawCircle method also has the radius,
color and center of the circle as input parameters. Its makes use of an IndexedLineArray
named linearray and created with n+1 vertices and 2(n+1) indices. Following the creation of
IndexedLineArray, a Point3f array is created and filled to store vertex coordinates, before
using another loop to fill up an appropriate indexing array on the lines to be drawn.
Indexedtrianglearray
Figure 38 gives an example on the use of IndexedTriangleArray to construct a solid tetra-
hedral. While the code is similar to that when IndexedLineArray is used, there are some
important differences.
Figure 38. Code segment and result of Triangle.java
1
public class Axis
2
{
3
private BranchGroup axisBG;
4
5
public Axis()
6
{
7
axisBG = new BranchGroup();
8
IndexedTriangleArray array = new
9
IndexedTriangleArray(4, TriangleArray.COORDINATES|TriangleArray.COLOR_3, 12);
10
11
Point3f []pts = new Point3f[4];
12
pts[0] = new Point3f(0f, -0.5f, 0f);
pts[1] = new Point3f(1f, -0.5f, 0f);
13
pts[2] = new Point3f(0f, 1f, 0f);
pts[3] = new Point3f(0f, -0.5f, 1f);
14
int []indices = {0,3,2,0,2,1,0,1,3,2,3,1};
15
array.setCoordinates(0,pts);
16
array.setCoordinateIndices(0, indices);
17
18
Color3f []color = new Color3f[4];
19
color[0] = new Color3f(1f, 0f, 1f);
20
color[1] = new Color3f(1f, 0f, 0f);
21
color[2] = new Color3f(0f, 1f, 0f);
22
color[3] = new Color3f(0f, 0f, 1f);
23
int []colorIndices = {2,2,2,1,1,1,0,0,0,3,3,3};
24
array.setColors(0,color);
25
array.setColorIndices(0, colorIndices);
Index 1
Surface B
(Inward facing)
26
27
28
}
29
30
public BranchGroup getBG()
31
{
Surface A
(Outward facing)
32
return axisBG;
33
}
34
}
Index 3
Index 2
Search WWH ::

Custom Search