Java Reference
In-Depth Information
Figure 45. Code segment and result of Pyramid.java
1.
int[] strip = new int[2]; strip[0] = 6; strip[1] = 4;
2.
3.
IndexedTriangleFanArray itfa = new IndexedTriangleFanArray
4.
( 5, GeometryArray.COORDINATES|GeometryArray.COLOR_3, 10, strip );
5.
6. Point3f[] pts = new Point3f[5];
7. pts[0] = new Point3f( 0.0f, 0.75f, 0.0f );
8. pts[1] = new Point3f( 0.75f, -0.25f, 0.0f );
9. pts[2] = new Point3f( 0.0f, -0.25f, 0.75f );
10. pts[3] = new Point3f( -0.75f, -0.25f, 0.0f );
11. pts[4] = new Point3f( 0.0f, -0.25f, -0.75f );
12.
13. int[] indices = { 0,2,1,4,3,2, 1,2,3,4 };
45 gives an example for constructing a pyramid using IndexedTriangleFanArray. Note that
the object has five vertices and two fanning strips are used. The first strip involves five
vertices and six indices to construct the four slanting triangular faces of the object, while
the second strip uses two fanning triangles to construct the bottom square surface.
The next example, illustrated in Figure 46, constructs a diamond shaped object. Note
that since two fanning strips, one for the top and one for the bottom part of the object, are
used, the array VertexCount is now a two element array with both elements set to N, the
number of vertices used in each fan.
creatInG an obJect usInG multIple Geometry
classes
After discussing the various important geometry array classes individually, we will now
show a slightly more complicated example where appropriate combinations of geometry
classes are used to create a visual Shape3D object.
Figure 47 shows the constructor and result for the example, illustrating a scene where
an artifact is housed inside a glass case. The artifact is created using IndexedTriangleFa-
nArray and the glass case is built using IndexedQuadArray. Both belong to the geometry
of a single Shape3D node.
Search WWH ::

Custom Search