Java Reference
In-Depth Information
come in IndexedLineStripArray by having an integer indexing array to point to the some
unique coordinates on the object vertices that need to be used in the rendering process.
However, as pointed out earlier, this may increase rendering time, and the issue is basically
a memory vs. speed one.
Figure 41 shows the code segment and result of using IndexedLineStripArray to create
a prism. The first three lines of the code segment create an integer array to be passed to
IndexedLineStripArray. Basically, with two elements, there will be two strips. The first
element has a value of six, indicating that the first strip will be made up of six vertices or
five line segments. Similarly, the second element is assigned a value of two, specifying
that the second strip will have two vertices or just one line segment.
Lines 6 and 7 creates an IndexedLineStripArray object through its constructor. The
first argument passed to this constructor is the number of vertices the prism has, which is
equal to four. The second parameter gives the vertex format. For this case, the indication
is that it is the vertex coordinates and colors that will be supplied subsequently. The third
argument is on the total number of indices used for rendering the object. In this scenario,
eight is used as six indices are needed for the first strip and another two are required for
the second strip. The fourth parameter is the name of the strip array set up earlier and
described in the last paragraph.
Figure 41. Code segment and result of TertahedralMesh.java
1.
int[] strip = new int[2];
2.
strip[0] = 6;
3.
strip[1] = 2;
4.
5.
//creating a line array using indexed and strip method. 4 vertices and 8 index present.
6.
IndexedLineStripArray ilsa = new
7.
IndexedLineStripArray( 4, GeometryArray.COORDINATES|GeometryArray.COLOR_3, 8, strip );
8.
9. Point3f[] pts = new Point3f[4];
10. pts[0] = new Point3f( 0.0f, -0.5f, 0.0f );
11. pts[1] = new Point3f( 0.75f, -0.5f, 0.0f );
12. pts[2] = new Point3f( 0.0f, 0.75f, 0.0f );
13. pts[3] = new Point3f( 0.0f, -0.5f, 0.75f );
14.
15. int[] indices = { 0,1,2,3,0,2,1,3 };
16. ilsa.setCoordinates( 0, pts );
17. ilsa.setCoordinateIndices( 0, indices );
Search WWH ::




Custom Search