|
The TriangleStripArray© Justin Couch 2000-2004
A
![]() Figure 11: A triangle strip array showing strips of length 3, 4 and 6 ConstructionTo create an instance ofTriangleStripArray you start with a
combination of the TriangleArray and LineStripArray
classes. You'll be needing the same vertex format and vertex count information
suitable for triangles, and you'll need an extra variable that describes the
number of vertices in the strip. Note that it is asking for the number of
vertices, not the number of triangles in each strip, which means the minimum
number for each count in the array will need to be at least 3 (ie 3 vertices to
form a single triangle, more for each subsequent triangle added to the strip).
So, starting with a simple example that creates a strip with 2 triangles in it, you'll need the following code:
int format = GeometryArray.COORDINATE |
GeometryArray.COLOR_3;
int[] strip_counts = { 4 };
TriangleStripArray tris = new TriangleStripArray(4, format, strip_counts);
The strip_count variable is an array of ints that describe how
many vertices to use from the array for the given triangle strip. Since each
strip must have at least a one triangle, the values in this array should always
be greater than or equal to 3. Each additional value in the array indicates a
new triangle to be added onto the previous, as showing in Figure 11.
In the example above, we are telling Java3D to create a single strip that has
two triangles - a starting triangle and a single additional point, to give you
the second triangle (vertices 1 and 2 are reused for the base of the additional
triangle).
After creating the basic primitive, all you need to do is fill in the vertex
values through the usual
float[] vertices =
{
0, 0, 0, // v1
1, 5, -3, // v2
0, 2, 0, // v3
-1, 3, 1, // v4
};
lines.setCoordinates(0, vertices);
Just remember that the number of vertices provided must be at least equivalent
to the sum of the lengths of all the strips. For example, if you provided a
strip count array with the values { 3, 5, 4 } your coordinate array must have
at least 11 vertices declared. More than that really doesn't matter as Java3D
will ignore the extras, but it must have at least the minimum amount.
Strips also follow the same rules for the individual triangles and quads when determining what is front facing and what is not. Since strips don't have any restriction on where you put vertices, it is possible for the strip to create a situation where a triangle folds backwards on the strip causing it to have the opposite winding as seen from the current viewpoint. When you look at this strip from the front, that folded back triangle would appear to be missing from the strip, as illustrated in Figure 12.
![]() Figure 12: A triangle strip with a "missing" triangle due to winding rules to determine front facing for culling purposes |
|
[ j3d.org ]
[ Aviatrix3D ]
[ Code Repository ]
[ Java3D ]
[ OpenGL ]
[ Books ]
[ Contact Us ]
Hosted by Yumetech Last Updated: $Date: 2006/04/18 18:20:11 $ |