Java Reference
In-Depth Information
Figure 46. Code segment and result of DiamondIndexedTriangleFanArray.java
1.
public class Diamond extends Shape3D
2.
{
3.
public Diamond()
4.
{
5.
this.setGeometry(DiamondGeometry());
6.
this.setAppearance(DiamondAppearance());
7.
}
8.
9.
private Geometry DiamondGeometry()
10.
{
11.
int N=5; //number of vertices in one fan
12.
int totalN = 2*(N+1); //total number of vertices
13.
int stripVertexCount[] = {N+1,N+1};
14.
IndexedTriangleFanArray Tri = new IndexedTriangleFanArray
15.
(totalN, IndexedGeometryArray.COORDINATES, 12, stripVertexCount);
16.
17. Tri.setCoordinate( 0, new Point3f(0f, 0.8f, 0f));
Tri.setCoordinate( 1, new Point3f(0f, 0f, 0.5f));
18. Tri.setCoordinate( 2, new Point3f(0.5f, 0f, 0f));
Tri.setCoordinate( 3, new Point3f(0f, 0f, -0.5f));
19. Tri.setCoordinate( 4, new Point3f(-0.5f, 0f, 0f));
Tri.setCoordinate( 5, new Point3f(0f, -0.8f, 0f));
20.
21. //Top Diamond
22. Tri.setCoordinateIndex( 0, 0); Tri.setCoordinateIndex( 1, 1);
Tri.setCoordinateIndex( 2, 2);
23. Tri.setCoordinateIndex( 3, 3); Tri.setCoordinateIndex( 4, 4);
Tri.setCoordinateIndex( 5, 1);
24.
25. //Bottom Diamond
26. Tri.setCoordinateIndex( 6, 5); Tri.setCoordinateIndex( 7, 4);
Tri.setCoordinateIndex( 8, 3);
27. Tri.setCoordinateIndex( 9, 2); Tri.setCoordinateIndex( 10, 1);
Tri.setCoordinateIndex( 11, 4);
28.
29.
return Tri;
30.
}
31. }
Specifically, the constructor for the Exhibit class shown in Figure 47 is an extension
of a Shape3D class. Line 3 invokes an Artefact() method which returns a geometry object
for the creation of the artifact, with the setGeometry method placing the created geometry
object as a geometry component at index 0. Similarly, the next line invokes a Glass_case()
Search WWH ::




Custom Search