visual trapezoidal object. The vertex format specified corresponds to the use of both co-
ordinates for vertex positions and per vertex color. Since joining two appropriate vertices
will produce a side and the visual object has 12 sides, a total of 24 indices for an index
count of 24 are needed to render the object.
A Point3f array named pts with eight elements is created to store the eight coordinates
of the vertices. This is followed by declaring an integer array named indices for storing the
vertices in pairs, with each pair forming a line of the visual object. Next, the codes segment
uses array.setCoordinates(0,pts) and array.setCoordinateIndices(0, indices) to set the coor-
dinates associated with the vertices and the index array for accessing these coordinates.
The colors of the vertices, which influence the colors of the lines drawn in the manner
as shown in the result in Figure 35, is set in the same way as that for the vertex coordinates.
Specifically, a Color3f array is created with each element initiated to the colors needed. Note
that this Color3f array need not have the same size as the Point3f array for the vertices. As
an example, if only three colors are needed, the Color3f array will only be of size three and
the colorIndices array declared subsequently will have values that are between 0 and 2.
Figure 36. First code segment of DemoSphere.java
public class Axis
private BranchGroup axisBG;
axisBG = new BranchGroup();
int n=200; float z=0.5f; Color3f color = new Color3f(0.2f, 0.3f, 0.2f);
axisBG = drawSphere(n, z, color);
public BranchGroup drawSphere(int n, float size, Color3f color)
BranchGroup axisBG = new BranchGroup();
IndexedLineArray array = new IndexedLineArray[n];
for(int i=0; i<n; i++)
float radius = (float)(Math.sin(Math.PI*i/n));
float dist = (float)(Math.cos(Math.PI*i/n));
array[i] = drawCircle(100,(float)(radius*size),0f,0f,(float)(dist*size), color);
Search WWH ::