Skip to content
bmenke92 edited this page Nov 5, 2011 · 1 revision

Creates a triangulation of the given polygon using ear-clipping. It stores each triangle as a set indices to the vertices that make it up. Runs in O(n^2)

Public members

Triangulator(Shape & shape)

Constructor takes in the shape that will be triangulated.

void process()

Creates the triangulation.

int indexCount()

Returns the number of indices created.

void getIndices(unsigned short* outIndices)

outIndices should be an array of unsigned shorts. getIndices fills outIndices with the triangle indices.

Description

The triangulator uses the ear-clipping algorithm to triangulate the shape. It begins at the first vertex in the shape. If the vertex is part of a convex corner of the shape a triangle is created from it, the point before it, and the point after. The corner is then removed from the list of points and the process is repeated on the next. All triangles are stored using indices into the shape, so a triangle made of indices 0,1,2 is made of up the points shape[0], shape[1], and shape[2].

Clone this wiki locally