Java Reference
In-Depth Information
and third strips and these give rise to the left and right faces of the prism. Lastly, a final
strip with a single line segment constructs the remaining top edge of the object.
Indexedtrianglestriparray
The relationship between IndexedTriangleStripArray and TriangleStripArray is the same
as that between IndexedLineStripArray and LineStripArray. The basic shape that can be
rendered under IndexedTriangleStripArray and TriangleStripArray is depicted in Figure
17. Essentially, both of these classes create a series of triangles based on a sequence of
vertices with facing set automatically to align, regardless of the actual sequence of vertices,
with that of the first triangle.
TirangleStripArray and its index version, IndexedTriangleStripArray, are very useful
for building structures with complex polygons. Specifically, the indexing ability of the latter
serves to save memory and time in programming at the expense of rendering speed.
Figure 43 illustrates a simple usage of IndexedTriangleStripArray to build a trapezoidal
object with eight vertices. Note that each of the six faces of the object is a 4-sided quadri-
lateral and is build by using two triangles. A total of 14 indices giving rise to 12 triangles
are used.
Figure 43. Code segment and result of Trapezium.java
1.
int[] strip = new int[1]; strip[0] = 14;
2.
3.
IndexedTriangleStripArray itsa = new IndexedTriangleStripArray
4.
( 8,GeometryArray.COORDINATES|GeometryArray.COLOR_3, 14, strip );
5.
6.
Point3f[] pts = new Point3f[8];
7.
pts[0] = new Point3f( 0.5f, 0.5f, 0.0f );
8.
pts[1] = new Point3f( 0.0f, 0.5f, -0.5f );
9.
pts[2] = new Point3f( -0.5f, 0.5f, 0.0f );
10. pts[3] = new Point3f( 0.0f, 0.5f, 0.5f );
11. pts[4] = new Point3f( 0.75f, -0.25f, 0.0f );
12. pts[5] = new Point3f( 0.0f, -0.25f, -0.75f );
13. pts[6] = new Point3f( -0.75f, -0.25f, 0.0f );
14. pts[7] = new Point3f( 0.0f, -0.25f, 0.75f );
15.
16. int[] indices = { 0,1,3,2,6,1,5,0,4,3,7,6,4,5 };
17. itsa.setCoordinates( 0, pts );
18. itsa.setCoordinateIndices( 0, indices );
Search WWH ::

Custom Search