CUGL 2.0
Cornell University Game Library
Public Member Functions | List of all members
cugl::SimpleTriangulator Class Reference

#include <CUSimpleTriangulator.h>

Public Member Functions

 SimpleTriangulator ()
 
 SimpleTriangulator (const std::vector< Vec2 > &points)
 
 SimpleTriangulator (const Poly2 &poly)
 
 ~SimpleTriangulator ()
 
void set (const Poly2 &poly)
 
void set (const std::vector< Vec2 > &points)
 
void reset ()
 
void clear ()
 
void calculate ()
 
std::vector< Uint32 > getTriangulation () const
 
size_t getTriangulation (std::vector< Uint32 > &buffer) const
 
Poly2 getPolygon () const
 
Poly2getPolygon (Poly2 *buffer) const
 

Detailed Description

This class is a factory for producing solid Poly2 objects from a set of vertices.

For all but the simplist of shapes, it is important to have a triangulator that can divide up the polygon into triangles for drawing. This is a straight forward implementation of the the ear cutting algorithm to triangulate simple polygons. It will not handle polygons with holes or with self intersections. All triangles produced are guaranteed to be counter-clockwise.

As with all factories, the methods are broken up into three phases: initialization, calculation, and materialization. To use the factory, you first set the data (in this case a set of vertices or another Poly2) with the initialization methods. You then call the calculation method. Finally, you use the materialization methods to access the data in several different ways.

This division allows us to support multithreaded calculation if the data generation takes too long. However, note that this factory is not thread safe in that you cannot access data while it is still in mid-calculation.

Constructor & Destructor Documentation

◆ SimpleTriangulator() [1/3]

cugl::SimpleTriangulator::SimpleTriangulator ( )
inline

Creates a triangulator with no vertex data.

◆ SimpleTriangulator() [2/3]

cugl::SimpleTriangulator::SimpleTriangulator ( const std::vector< Vec2 > &  points)
inline

Creates a triangulator with the given vertex data.

The vertex data is copied. The triangulator does not retain any references to the original data.

Parameters
pointsThe vertices to triangulate

◆ SimpleTriangulator() [3/3]

cugl::SimpleTriangulator::SimpleTriangulator ( const Poly2 poly)
inline

Creates a triangulator with the given vertex data.

The triangulator assumes that the polygon represents a polyline. If the polygon represents a solid shape, it will be ignored.

The vertex data is copied. The triangulator does not retain any references to the original data.

Parameters
polyThe vertices to triangulate

◆ ~SimpleTriangulator()

cugl::SimpleTriangulator::~SimpleTriangulator ( )
inline

Deletes this triangulator, releasing all resources.

Member Function Documentation

◆ calculate()

void cugl::SimpleTriangulator::calculate ( )

Performs a triangulation of the current vertex data.

◆ clear()

void cugl::SimpleTriangulator::clear ( )
inline

Clears all internal data, the initial vertex data.

When this method is called, you will need to set a new vertices before calling calculate.

◆ getPolygon() [1/2]

Poly2 cugl::SimpleTriangulator::getPolygon ( ) const

Returns a polygon representing the triangulation.

The polygon contains the original vertices together with the new indices defining a solid shape. The triangulator does not maintain references to this polygon and it is safe to modify it.

If the calculation is not yet performed, this method will return the empty polygon.

Returns
a polygon representing the triangulation.

◆ getPolygon() [2/2]

Poly2* cugl::SimpleTriangulator::getPolygon ( Poly2 buffer) const

Stores the triangulation in the given buffer.

This method will add both the original vertices, and the corresponding indices to the new buffer. If the buffer is not empty, the indices will be adjusted accordingly. You should clear the buffer first if you do not want to preserve the original data.

If the calculation is not yet performed, this method will do nothing.

Parameters
bufferThe buffer to store the triangulated polygon
Returns
a reference to the buffer for chaining.

◆ getTriangulation() [1/2]

std::vector<Uint32> cugl::SimpleTriangulator::getTriangulation ( ) const

Returns a list of indices representing the triangulation.

The indices represent positions in the original vertex list. If you have modified that list, these indices may no longer be valid.

The triangulator does not retain a reference to the returned list; it is safe to modify it.

If the calculation is not yet performed, this method will return the empty list.

Returns
a list of indices representing the triangulation.

◆ getTriangulation() [2/2]

size_t cugl::SimpleTriangulator::getTriangulation ( std::vector< Uint32 > &  buffer) const

Stores the triangulation indices in the given buffer.

The indices represent positions in the original vertex list. If you have modified that list, these indices may no longer be valid.

The indices will be appended to the provided vector. You should clear the vector first if you do not want to preserve the original data.

If the calculation is not yet performed, this method will do nothing.

Returns
the number of elements added to the buffer

◆ reset()

void cugl::SimpleTriangulator::reset ( )
inline

Clears all internal data, but still maintains the initial vertex data.

◆ set() [1/2]

void cugl::SimpleTriangulator::set ( const Poly2 poly)

Sets the vertex data for this triangulator..

The triangulator assumes that the polygon represents a polyline. If the polygon represents a solid shape, it will be ignored.

The vertex data is copied. The triangulator does not retain any references to the original data.

This method resets all interal data. You will need to reperform the calculation before accessing data.

Parameters
polyThe vertices to triangulate

◆ set() [2/2]

void cugl::SimpleTriangulator::set ( const std::vector< Vec2 > &  points)
inline

Sets the vertex data for this triangulator..

The vertex data is copied. The triangulator does not retain any references to the original data.

This method resets all interal data. You will need to reperform the calculation before accessing data.

Parameters
pointsThe vertices to triangulate

The documentation for this class was generated from the following file: