|
The TriangleFanArray© Justin Couch 2000 - 2004
The To describe the geometry for a single fan, you start with the common vertex. This is the first vertex of the fan. Next declare two more vertices to create your first triangle. To add another triangle to the fan, take the last vertex declared, the initial vertex and the new vertex triangle and that is now the new triangle. As with the strip version, each fan must consist of a minimum of 3 vertices and then an additional vertex for each triangle added after the first. Figure 13 illustrates 3 fans with 3, 4 and 6 vertices.
![]() Figure 13: A triangle fan array showing strips of length 3, 4 and 6 ConstructionTo create an instance ofTriangleFanArray you start with the same
basic setup as the LineStripArray and
TriangleStripArray. The third parameter, although it is called
stripVertexCounts in the documentation, defines the number of
vertices to use in each fan. As with the triangle strip, each value in this
array must be greater than or equal to three.
So, starting with a simple example that creates a fan with 2 triangles in
it, you'll need the following code:
int format = GeometryArray.COORDINATE |
GeometryArray.COLOR_3;
int[] fan_counts = { 4 };
TriangleFanArray tris = new TriangleFanArray(4, format, fan_counts);
The fan_count variable is an array of ints that describe how
many vertices to use from the array for the given triangle fan. Since each
fan 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 13.
In the example above, we are telling Java3D to create a single fan that has
two triangles - a starting triangle and a single additional point, to give you
the second 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);
Fans also follow the same rules for the individual triangles, quads and
triangle strips when determining what is front facing and what is not. Since
fans don't have any restriction on where you put vertices, it is possible for
the fan to create a situation where a triangle folds backwards on the fan
causing it to have the opposite winding as seen from the current viewpoint.
When you look at this fan from the front, that folded back triangle would
appear to be missing from the fan, as illustrated in Figure 14.
![]() Figure 14: A triangle fan 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 $ |