CUGL 2.0
Cornell University Game Library
|
#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 |
Poly2 * | getPolygon (Poly2 *buffer) const |
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.
|
inline |
Creates a triangulator with no vertex data.
|
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.
points | The vertices to triangulate |
|
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.
poly | The vertices to triangulate |
|
inline |
Deletes this triangulator, releasing all resources.
void cugl::SimpleTriangulator::calculate | ( | ) |
Performs a triangulation of the current vertex data.
|
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.
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.
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.
buffer | The buffer to store the triangulated polygon |
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.
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.
|
inline |
Clears all internal data, but still maintains the initial vertex data.
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.
poly | The vertices to triangulate |
|
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.
points | The vertices to triangulate |