Java Reference
In-Depth Information
As can be seen, the tetrahedral has four vertices and is made up of four triangular faces.
Since each face requires the drawing of a triangle with three vertices, three indices are
needed for every face, and the total number of indices needed or the index count is 12.
After declaring this index count in the creation of the IndexedTriangleArray named
array in the code segment, an integer array named indices is declared to store the indices
to the vertex coordinates in groups of three, with each group defining a triangle. This is
similar to when IndexedLineArray is used, where the indices are group in pairs for draw-
ing a line between two vertices.
Figure 39. Code segment and result of DiamondIndexedTriangleArray.java
1.
public class DiamondIndexedTriangleArray extends Applet
2.
{
3.
public class Diamond extends Shape3D
4.
{
5.
public Diamond() //constructor
6.
{
7.
this.setGeometry(DiamondGeometry());
8.
this.setAppearance(DiamondAppearance());
9.
}
10.
11. private Geometry DiamondGeometry()
12. {
13. IndexedTriangleArray Tri = new IndexedTriangleArray (6, GeometryArray.COORDINATES,24);
14. Tri.setCoordinate( 0,new Point3f(0f, 0.8f, 0f)); Tri.setCoordinate(1,new Point3f(0.0f,0.0f,-0.5f));
15. Tri.setCoordinate( 2,new Point3f(0.5f, 0f, 0f)); Tri.setCoordinate(3,new Point3f(-0.5f,0.0f,0.0f));
16. Tri.setCoordinate( 4,new Point3f(0f, 0f, 0.5f)); Tri.setCoordinate(5, new Point3f(0f, -0.8f, 0.0f));
17.
18. //Top Diamond
19. Tri.setCoordinateIndex( 0, 0 ); Tri.setCoordinateIndex( 1, 4 );
20. Tri.setCoordinateIndex( 2, 2 ); Tri.setCoordinateIndex( 3, 0 );
21. Tri.setCoordinateIndex( 4, 2 ); Tri.setCoordinateIndex( 5, 1 );
22. Tri.setCoordinateIndex( 6, 0 ); Tri.setCoordinateIndex( 7, 1 );
23. Tri.setCoordinateIndex( 8, 3 ); Tri.setCoordinateIndex( 9, 0 );
24. Tri.setCoordinateIndex( 10,3 ); Tri.setCoordinateIndex( 11,4 );
25.
26. //Bottom Diamond
27. Tri.setCoordinateIndex( 12,5 ); Tri.setCoordinateIndex( 13,4 );
28. Tri.setCoordinateIndex( 14,2 ); Tri.setCoordinateIndex( 15,5 );
29. Tri.setCoordinateIndex( 16,2 ); Tri.setCoordinateIndex( 17,1 );
30.
Tri.setCoordinateIndex( 18,5 ); Tri.setCoordinateIndex( 19,1 );
31.
Tri.setCoordinateIndex( 20,3 ); Tri.setCoordinateIndex( 21,5 );
32.
Tri.setCoordinateIndex( 22,3 ); Tri.setCoordinateIndex( 23,4 );
33.
34. return Tri;
35. }//end of GeometryDiamond method
36. }//end of Diamond class
Search WWH ::




Custom Search