C4 Engine
C4 Engine API Documentation


Defined in:  C4Computation.h
Triangulates a convex or concave polygon having genus zero (i.e., no holes).

int32 TriangulatePolygon(int32 vertexCount, const Point3D *vertex, const Vector3D& normal, Triangle16 *restrict triangle, int32 base = 0);

vertexCount The number of vertices used to specify the boundary of the polygon.
vertex An array of vertices, wound in counterclockwise order, of the size specified by the vertexCount parameter.
normal The normal direction of the polygon.
triangle An array to which the triangles are written. This must be large enough to hold n − 2 triangles, where n is the number of vertices specified by the vertexCount parameter.
base A base vertex index that is added to all of the indexes written to the triangle array.
The TriangulatePolygon function takes an arbitrary planar polygon specified by n vertices, triangulates it, and returns the number of triangles that were generated. Except in cases in which there are degenerate vertices, the number of triangles generated will be n − 2.

The input polygon is specified by the vertexCount and vertex parameters and may be any planar shape that is not self-intersecting. Convex polygons, concave polygons, and polygons containing sets of collinear vertices are all valid. The set of vertices must be specified in order and must be wound counterclockwise about the normal direction specified by the normal parameter. The minimum number of vertices is 3, in which case a single triangle is generated.

The results are undefined if the input polygon 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 the 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 polygon, indicated by the return value being less than n − 2.
See Also