C4 Engine
C4 Engine API Documentation

Calc::TriangulatePolygonalComplex

Defined in:  C4Computation.h
Triangulates a convex or concave polygon having nonzero genus.
Prototype

int32 TriangulatePolygonalComplex(int32 windingCount, const int32 *vertexCount, const uint16 *const *vertexIndex,

const Point3D *vertex, const Vector3D& normal, Point3D *restrict result, Triangle16 *restrict triangle);

Parameters
windingCount The number of closed loops defining the shape of the polygonal complex. The first winding specifies the outside boundary of the positive polygon and should be wound counterclockwise. The remaining windings specify the boundaries of negative polygons representing holes that are cut out of the positive polygon and should be wound clockwise.
vertexCount An array of vertex counts specifying the number of vertices in each winding.
vertexIndex An array of pointers to arrays containing the vertex indexes of the vertices used by each winding. For each winding, there is one pointer in this array that points to an array of indexes whose size is equal to the number of vertices belonging to the winding, as specified by the corresponding entry in the vertexCount array. The vertex indexes refer to entries in the vertex array specified by the vertex parameter.
vertex An array containing all of the vertices belonging to all of the windings. The entries of the vertexCount and vertexIndex arrays specify the number and first index of the vertices belong to each winding.
normal The normal direction of the polygonal complex.
result An array that receives the vertex positions in the final triangulation. This array should be large enough to hold the number of vertices equal to the sum of the values in the vertexCount array.
triangle An array to which the triangles are written. This must be large enough to hold n − 2 + 2g triangles, where n is the sum of the values in the vertexCount array, and g is the genus of the complex (which is one less than the value given by the windingCount parameter).
Description
The TriangulatePolygonalComplex function takes an arbitrary planar polygon having any number of polygonal holes cut out of it, triangulates it, and returns the number of triangles that were generated. The polygonal complex is specified by one or more windings representing the boundary of the interior area. Except in cases in which there are degenerate vertices, the number of triangles generated will be n − 2 + 2g, where n is the sum of the values in the vertexCount array, and g is the genus of the complex, equal to one less than the value of the windingCount parameter.

Each of the windings may be convex or concave and may contain sets of collinear vertices. The first winding, whose vertices are specified by the first entries of the vertexCount and vertexIndex arrays, represents the (positive) outer boundary of the complex. It should be wound counterclockwise about the normal direction specified by the normal parameter. The remaining windings represent the boundaries of the (negative) holes that are cut out of the complex. These windings should be wound clockwise (so that the interior of the complex is always on the left-hand side when travelling along any winding). The negative windings must not intersect or enclose any other winding, and each must be completely contained within the positive winding. If these requirements are not met, then the results are undefined.

The results are undefined if any input winding is self-intersecting or if the vertices do not lie in a plane that is perpendicular to the normal direction specified by the normal parameter. If any array of vertices contains degenerate entries (a pair of vertices that are very close to each other), then the result may be a subset of the fully triangulated polygonal complex, indicated by the return value being less than n − 2 + 2g.

The resulting triangles are returned in the array specified by the triangle parameter. The input vertices are reordered and stored in the array specified by the result parameter. The indexes contained in the triangle array refer to vertices in the result array.

If the windingCount parameter is 1 (the minimum value), then this function behaves exactly like the Calc::TriangulatePolygon function.
See Also

Calc::TriangulatePolygon