CUGL
Cornell University Game Library
|
#include <CUPoly2.h>
Public Types | |
enum | Type { Type::UNDEFINED, Type::SOLID, Type::PATH } |
Public Member Functions | |
Poly2 () | |
Poly2 (const std::vector< Vec2 > &vertices) | |
Poly2 (const std::vector< Vec2 > &vertices, const std::vector< unsigned short > &indices) | |
Poly2 (const std::vector< float > &vertices) | |
Poly2 (const std::vector< float > &vertices, const std::vector< unsigned short > &indices) | |
Poly2 (Vec2 *vertices, int vertsize, int voffset=0) | |
Poly2 (float *vertices, int vertsize, int voffset=0) | |
Poly2 (Vec2 *vertices, int vertsize, unsigned short *indices, int indxsize, int voffset=0, int ioffset=0) | |
Poly2 (float *vertices, int vertsize, unsigned short *indices, int indxsize, int voffset=0, int ioffset=0) | |
Poly2 (const Poly2 &poly) | |
Poly2 (const Rect &rect, bool solid=true) | |
~Poly2 () | |
Poly2 & | operator= (const Poly2 &other) |
Poly2 & | operator= (const Rect &rect) |
Poly2 & | set (const std::vector< Vec2 > &vertices) |
Poly2 & | set (const std::vector< Vec2 > &vertices, const std::vector< unsigned short > &indices) |
Poly2 & | set (const std::vector< float > &vertices) |
Poly2 & | set (const std::vector< float > &vertices, const std::vector< unsigned short > &indices) |
Poly2 & | set (Vec2 *vertices, int vertsize, int voffset=0) |
Poly2 & | set (float *vertices, int vertsize, int voffset=0) |
Poly2 & | set (Vec2 *vertices, int vertsize, unsigned short *indices, int indxsize, int voffset=0, int ioffset=0) |
Poly2 & | set (float *vertices, int vertsize, unsigned short *indices, int indxsize, int voffset=0, int ioffset=0) |
Poly2 & | set (const Poly2 &poly) |
Poly2 & | set (const Rect &rect, bool solid=true) |
Poly2 & | clear () |
Poly2 & | setIndices (const std::vector< unsigned short > &indices) |
Poly2 & | setIndices (unsigned short *indices, int indxsize, int ioffset=0) |
bool | isStandardized () |
bool | isValid () |
Vec2 & | at (int index) |
const std::vector< Vec2 > & | getVertices () const |
const std::vector< unsigned short > & | getIndices () const |
std::vector< unsigned short > & | getIndices () |
const Rect & | getBounds () const |
Type | getType () const |
void | setType (Type type) |
Poly2 & | operator*= (float scale) |
Poly2 & | operator*= (const Vec2 &scale) |
Poly2 & | operator*= (const Affine2 &transform) |
Poly2 & | operator*= (const Mat4 &transform) |
Poly2 & | operator/= (float scale) |
Poly2 & | operator/= (const Vec2 &scale) |
Poly2 & | operator+= (float offset) |
Poly2 & | operator+= (const Vec2 &offset) |
Poly2 & | operator-= (float offset) |
Poly2 & | operator-= (const Vec2 &offset) |
Poly2 | operator* (float scale) const |
Poly2 | operator* (const Vec2 &scale) const |
Poly2 | operator*= (const Affine2 &transform) const |
Poly2 | operator* (const Mat4 &transform) const |
Poly2 | operator/ (float scale) const |
Poly2 | operator/ (const Vec2 &scale) const |
Poly2 | operator+ (float offset) const |
Poly2 | operator+ (const Vec2 &offset) const |
Poly2 | operator- (float offset) |
Poly2 | operator- (const Vec2 &offset) |
std::vector< Vec2 > | convexHull () const |
bool | contains (const Vec2 &point) const |
bool | incident (const Vec2 &point, float variance=CU_MATH_EPSILON) const |
Static Public Member Functions | |
static Poly2 | createLine (const Vec2 &origin, const Vec2 &dest) |
static Poly2 * | createLine (const Vec2 &origin, const Vec2 &dest, Poly2 *dst) |
static Poly2 | createTriangle (const Vec2 &a, const Vec2 &b, const Vec2 &c, bool solid=true) |
static Poly2 * | createTriangle (const Vec2 &a, const Vec2 &b, const Vec2 &c, Poly2 *dst, bool solid=true) |
static Poly2 | createEllipse (const Vec2 ¢er, const Size &size, unsigned int segments, bool solid=true) |
static Poly2 * | createEllipse (const Vec2 ¢er, const Size &size, unsigned int segments, Poly2 *dst, bool solid=true) |
Friends | |
class | CubicSplineApproximator |
class | SimpleTriangulator |
class | PathOutliner |
class | PathExtruder |
Poly2 | operator* (float scale, const Poly2 &poly) |
Poly2 | operator* (const Vec2 &scale, const Poly2 &poly) |
Class to represent a simple polygon.
This class is intended to represent any polygon (including non-convex polygons) that does not have holes or self-interections. This class performs no verification. It will not check for holes or self-intersections; those are the responsibility of the programmer.
When instantiating this class, the user should provide a set of indices which will be used in rendering. These indices can either represent a triangulation of the polygon, or they can represent a traversal (for a wireframe). Provided that these indices are in "normal" form, it can provide support a for basic geometry queries, such as wether a point is inside the polygon.
There are two normal forms, depending on the value of the type attribute. If the polygon is SOLID, then the indices are a set of triangles. That is, there are three times as many indices as triangles, and a point is in the polygon if it is contained in any one of the triangles. Solid polygons do not support triangle fans or strips.
If the polygon is a PATH, then the indices are a set of lines. That is, there are two times as many indices as triangles, and a point is in the polygon if it is incident on any of the lines. Non-solid (or path) polygons do not support line strips.
Generating indices for a Poly2 can be nontrivial. While this class has standard constructors, allowing the programmer full control, most Poly2 objects are created through alternate means. For simple shapes, like lines, triangles, and ellipses, this class has several static constructors.
For more complex shapes, we have several Poly2 factories. These factories allow for delegating index computation to a separate thread, if it takes too long. These factories are as follows:
SimpleTriangulator: This is a simple earclipping-triangulator for tesselating simple, solid polygons (e.g. no holes or self-intersections).
ComplexTriangulator: This is a wrapper for the advanced Poly2Tri triangulator. This triangulator can tesselate complex solid polygons (e.g. those with holes or self-intersections).
PathOutliner: This is a tool is used to generate indices for a path polygon. It has several options, that allow it to make useful wireframes for debugging.
CubicSplineApproximator: This is a tool is used to generate a Poly2 object from a Cubic Bezier curve.
PathExtruder: This is a tool can take a path polygon and convert it into a solid polygon. This solid polygon is the same as the path, except that the path now has a width and a mitre at the joints. This tool is different from the other tools in that it generates new vertices in addition to the indices.
PolygonClipper: This is a wrapper for the Clipper package, which provides 2d constructive area geometry support. It allows you to compute the intersection or union of multiple solid polygons. Like PathExtruder, it also generates new vertices in addition to the indices.
|
strong |
This enum is used to determine the normal form for the indices. Any rendering classes should use this type as a hint for how to render the polygon.
|
inline |
Creates an empty polygon.
The created polygon has no vertices and no triangulation. The bounding box is trivial.
|
inline |
Creates a polygon with the given vertices
The new polygon has no indices and the type is UNDEFINED.
vertices | The vector of vertices (as Vec2) in this polygon |
|
inline |
Creates a polygon with the given vertices and indices.
A valid list of indices must only refer to vertices in the vertex array. That is, the indices should all be non-negative, and each value should be less than the number of vertices.
This constructor will assign a type accoring to the multiplicity of the indices. If the number of indices n is correct for a closed or open path of all vertices (e.g. 2n or 2n-2), then the type will be PATH. Otherwise, if n is divisible by 3 it will be SOLID. All other values will be UNDEFINED, and the user must manually set the type.
vertices | The vector of vertices (as Vec2) in this polygon |
indices | The vector of indices for the rendering |
|
inline |
Creates a polygon with the given vertices
The new polygon has no indices.
The float array should have an even number of elements. The number of vertices is half of the size of the array. For each value ii, 2*ii and 2*ii+1 are the coordinates of a single vertex.
The new polygon has no indices and the type is UNDEFINED.
vertices | The vector of vertices (as floats) in this polygon |
|
inline |
Creates a polygon with the given vertices and indices.
The float array should have an even number of elements. The number of vertices is half of the size of the array. For each value ii, 2*ii and 2*ii+1 are the coordinates of a single vertex.
A valid list of indices must only refer to vertices in the vertex array. That is, the indices should all be non-negative, and each value should be less than the number of vertices.
This constructor will assign a type accoring to the multiplicity of the indices. If the number of indices n is correct for a closed or open path of all vertices (e.g. 2n or 2n-2), then the type will be PATH. Otherwise, if n is divisible by 3 it will be SOLID. All other values will be UNDEFINED, and the user must manually set the type.
vertices | The vector of vertices (as floats) in this polygon |
indices | The vector of indices for the rendering |
|
inline |
Creates a polygon with the given vertices
The new polygon has no indices and the type is UNDEFINED.
vertices | The array of vertices (as Vec2) in this polygon |
vertsize | The number of elements to use from vertices |
voffset | The offset in vertices to start the polygon |
|
inline |
Creates a polygon with the given vertices
The float array should have an even number of elements. The number of vertices is half of the size of the array. For each value ii, 2*ii and 2*ii+1 are the coordinates of a single vertex.
The new polygon has no indices and the type is UNDEFINED.
vertices | The array of vertices (as floats) in this polygon |
vertsize | The number of elements to use from vertices |
voffset | The offset in vertices to start the polygon |
|
inline |
Creates a polygon with the given vertices and indices.
A valid list of indices must only refer to vertices in the vertex array. That is, the indices should all be non-negative, and each value should be less than the number of vertices.
This constructor will assign a type accoring to the multiplicity of the indices. If the number of indices n is correct for a closed or open path of all vertices (e.g. 2n or 2n-2), then the type will be PATH. Otherwise, if n is divisible by 3 it will be SOLID. All other values will be UNDEFINED, and the user must manually set the type.
vertices | The array of vertices (as Vec2) in this polygon |
vertsize | The number of elements to use from vertices |
indices | The array of indices for the rendering |
indxsize | The number of elements to use for the indices |
voffset | The offset in vertices to start the polygon |
ioffset | The offset in indices to start from |
|
inline |
Creates a polygon with the given vertices and indices.
The float array should have an even number of elements. The number of vertices is half of the size of the array. For each value ii, 2*ii and 2*ii+1 are the coordinates of a single vertex.
A valid list of indices must only refer to vertices in the vertex array. That is, the indices should all be non-negative, and each value should be less than the number of vertices.
This constructor will assign a type accoring to the multiplicity of the indices. If the number of indices n is correct for a closed or open path of all vertices (e.g. 2n or 2n-2), then the type will be PATH. Otherwise, if n is divisible by 3 it will be SOLID. All other values will be UNDEFINED, and the user must manually set the type.
vertices | The array of vertices (as floats) in this polygon |
vertsize | The number of elements to use from vertices |
indices | The array of indices for the rendering |
indxsize | The number of elements to use for the indices |
voffset | The offset in vertices to start the polygon |
ioffset | The offset in indices to start from |
|
inline |
Creates a copy of the given polygon.
Both the vertices and the indices are copied. No references to the original polygon are kept.
poly | The polygon to copy |
|
inline |
Creates a polygon for the given rectangle.
The polygon will have four vertices, one for each corner of the rectangle. This optional argument (which is true by default) will initialize the indices with a triangulation of the rectangle. In other words, the type will be SOLID. This is faster than using one of the more heavy-weight triangulators.
If solid is false, it will still generate indices, but will be a PATH instead.
rect | The rectangle to copy |
solid | Whether to treat this rectangle as a solid polygon |
|
inline |
Deletes the given polygon, freeing all resources.
|
inline |
Returns a reference to the attribute at the given index.
This accessor will allow you to change the (singular) vertex. It is intended to allow minor distortions to the polygon without changing the underlying mesh.
index | The attribute index |
|
inline |
Clears the contents of this polygon and sets the type to UNDEFINED
bool cugl::Poly2::contains | ( | const Vec2 & | point | ) | const |
Returns true if this polygon contains the given point.
This method returns false is the polygon is not SOLID. If it is solid, it checks for containment within the associated triangles. It includes points on the polygon border.
point | The point to test |
std::vector<Vec2> cugl::Poly2::convexHull | ( | ) | const |
Returns the set of points forming the convex hull of this polygon.
The returned set of points is guaranteed to be a counter-clockwise traversal of the hull.
The points on the convex hull define the "border" of the shape. In addition to minimizing the number of vertices, this is useful for determining whether or not a point lies on the boundary.
This implementation is adapted from the example at
http://www.geeksforgeeks.org/convex-hull-set-2-graham-scan/
|
static |
Creates a polygon that represents an ellipse of the given dimensions.
The indices will be generated automatically. If the value solid is true, then the type will be SOLID. Otherwise, the type will be PATH.
center | The ellipse center point. |
size | The size of the ellipse. |
segments | The number of segments to use. |
solid | If true, treat this ellipse as a SOLID. |
|
static |
Creates a polygon that represents an ellipse of the given dimensions.
The indices will be generated automatically. If the value solid is true, then the type will be SOLID. Otherwise, the type will be PATH.
center | The ellipse center point. |
size | The size of the ellipse. |
segments | The number of segments to use. |
dst | A polygon to store the result in. |
solid | If true, treat this ellipse as a SOLID. |
Creates a polygon that represents a line segment from origin to dest.
The polygon will have indices and the type will be PATH
origin | The line origin. |
dest | The line destination. |
|
static |
Creates a polygon that represents a line segment from origin to dest.
This alternate constructor does not allocate the Poly2 object. Instead, it sets the contents of Poly2 pointer.
The polygon will have indices and the type will be PATH
origin | The line origin. |
dest | The line destination. |
dst | A polygon to store the result in. |
|
static |
Creates a polygon that represents a simple triangle.
The indices will be generated automatically. If the value solid is true, then the type will be SOLID. Otherwise, the type will be PATH.
a | The first vertex. |
b | The second vertex. |
c | The third vertex. |
solid | If true, treat this triangle as a SOLID. |
|
static |
Creates a polygon that represents a simple triangle.
This alternate constructor does not allocate the Poly2 object. Instead, it sets the contents of Poly2 pointer.
The indices will be generated automatically. If the value solid is true, then the type will be SOLID. Otherwise, the type will be PATH.
a | The first vertex. |
b | The second vertex. |
c | The third vertex. |
dst | A polygon to store the result in. |
solid | If true, treat this triangle as a SOLID. |
|
inline |
Returns the bounding box for the polygon
The bounding box is the minimal rectangle that contains all of the vertices in this polygon. It is recomputed whenever the vertices are set.
|
inline |
Returns a reference to list of indices.
This accessor will not permit any changes to the index array. To change the array, you must change the polygon via a set() method.
|
inline |
Returns a reference to list of indices.
This accessor will not permit any changes to the index array. To change the array, you must change the polygon via a set() method.
This non-const version of the method is used by triangulators.
|
inline |
Returns the type of this polygon.
The type determines the proper form of the indices.
If the polygon is SOLID, there should be three times as many indices as vertices. Each triplet should define a triangle over the vertices.
If the polygon is PATH, there should be two times as many indices as vertices. Each pair should define a line segment over the vertices.
If the polygon is UNDEFINED, the index list should be empty.
|
inline |
Returns the list of vertices
This accessor will not permit any changes to the vertex array. To change the array, you must change the polygon via a set() method.
bool cugl::Poly2::incident | ( | const Vec2 & | point, |
float | variance = CU_MATH_EPSILON |
||
) | const |
Returns true if the given point is on the boundary of this polygon.
This method returns false is the polygon is not SOLID or PATH. If it is a path, it checks that the point is within variance of the a line segment on the path.
If it is solid, it checks that the point is within variance of the convex hull. The convex hull is not a fast computation, so this method should be used with care.
point | The point to test |
variance | The distance tolerance |
bool cugl::Poly2::isStandardized | ( | ) |
Returns true if the indices are in the proper normal form.
If the polygon is SOLID, this method will return true if the number of indices is divisible by three.
If the polygon is PATH, this method will return true if the number of indices is divisible by two.
If the polygon is UNDEFINED, this method will return true if there are no indices.
This method does not validate that the indices are with in range. See isValid().
bool cugl::Poly2::isValid | ( | ) |
Returns true if the indices are all valid.
This method is a heavier-weight version of isStandardized(). It verifies that the number of indices is correct, and that they are all in range.
If the polygon is SOLID, this method will return true if the number of indices is divisible by three and if the index values are all in range.
If the polygon is PATH, this method will return true if the number of indices is divisible by two and if the index values are all in range.
If the polygon is UNDEFINED, this method will return true if there are no indices.
|
inline |
Returns a new polygon by scaling the vertices uniformly.
The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.
Note: This method does not modify the polygon.
scale | The uniform scaling factor |
Returns a new polygon by scaling the vertices non-uniformly.
The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.
Note: This method does not modify the polygon.
scale | The non-uniform scaling factor |
Returns a new polygon by transforming all of the vertices of this polygon.
The vertices are transformed as points. The z-value is 0.
Note: This method does not modify the polygon.
transform | The transform matrix |
Poly2& cugl::Poly2::operator*= | ( | float | scale | ) |
Uniformly scales all of the vertices of this polygon.
The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.
scale | The uniform scaling factor |
Nonuniformly scales all of the vertices of this polygon.
The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.
scale | The non-uniform scaling factor |
Transforms all of the vertices of this polygon.
transform | The affine transform |
Transforms all of the vertices of this polygon.
The vertices are transformed as points. The z-value is 0.
transform | The transform matrix |
Returns a new polygon by transforming all of the vertices of this polygon.
Note: This method does not modify the polygon.
transform | The affine transform |
|
inline |
Returns a new polygon by translating the vertices uniformly.
Note: This method does not modify the polygon.
offset | The uniform translation amount |
Returns a new polygon by translating the vertices non-uniformly.
Note: This method does not modify the polygon.
offset | The non-uniform translation amount |
Poly2& cugl::Poly2::operator+= | ( | float | offset | ) |
Uniformly translates all of the vertices of this polygon.
offset | The uniform translation amount |
Non-uniformly translates all of the vertices of this polygon.
offset | The non-uniform translation amount |
|
inline |
Returns a new polygon by translating the vertices uniformly.
Note: This method does not modify the polygon.
offset | The inverse of the uniform translation amount |
Returns a new polygon by translating the vertices non-uniformly.
Note: This method does not modify the polygon.
offset | The inverse of the non-uniform translation amount |
Poly2& cugl::Poly2::operator-= | ( | float | offset | ) |
Uniformly translates all of the vertices of this polygon.
offset | The inverse of the uniform translation amount |
Non-uniformly translates all of the vertices of this polygon.
offset | The inverse of the non-uniform translation amount |
|
inline |
Returns a new polygon by scaling the vertices uniformly.
The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.
Note: This method does not modify the polygon.
scale | The inverse of the uniform scaling factor |
Returns a new polygon by scaling the vertices non-uniformly.
The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.
Note: This method does not modify the polygon.
scale | The inverse of the non-uniform scaling factor |
Poly2& cugl::Poly2::operator/= | ( | float | scale | ) |
Uniformly scales all of the vertices of this polygon.
The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.
scale | The inverse of the uniform scaling factor |
Nonuniformly scales all of the vertices of this polygon.
The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.
scale | The inverse of the non-uniform scaling factor |
Sets this polygon to be a copy of the given one.
All of the contents are copied, so that this polygon does not hold any references to elements of the other polygon. This method returns a reference to this polygon for chaining.
other | The polygon to copy |
Sets this polygon to be a copy of the given rectangle.
The polygon will have four vertices, one for each corner of the rectangle. In addition, this assignment will initialize the indices with a simple triangulation of the rectangle. The type will be SOLID.
rect | The rectangle to copy |
Sets the polygon to have the given vertices
The resulting polygon has no indices and the type is UNDEFINED.
This method returns a reference to this polygon for chaining.
vertices | The vector of vertices (as Vec2) in this polygon |
Poly2& cugl::Poly2::set | ( | const std::vector< Vec2 > & | vertices, |
const std::vector< unsigned short > & | indices | ||
) |
Sets the polygon to have the given vertices and indices.
A valid list of indices must only refer to vertices in the vertex array. That is, the indices should all be non-negative, and each value should be less than the number of vertices.
This method will assign a type accoring to the multiplicity of the indices. If the number of indices n is correct for a closed or open path of all vertices (e.g. 2n or 2n-2), then the type will be PATH. Otherwise, if n is divisible by 3 it will be SOLID. All other values will be UNDEFINED, and the user must manually set the type.
vertices | The vector of vertices (as Vec2) in this polygon |
indices | The vector of indices for the rendering |
Poly2& cugl::Poly2::set | ( | const std::vector< float > & | vertices | ) |
Sets the polygon to have the given vertices
The float array should have an even number of elements. The number of vertices is half of the size of the array. For each value ii, 2*ii and 2*ii+1 are the coordinates of a single vertex.
The resulting polygon has no indices and the type is UNDEFINED.
This method returns a reference to this polygon for chaining.
vertices | The vector of vertices (as floats) in this polygon |
Poly2& cugl::Poly2::set | ( | const std::vector< float > & | vertices, |
const std::vector< unsigned short > & | indices | ||
) |
Sets a polygon to have the given vertices and indices.
The float array should have an even number of elements. The number of vertices is half of the size of the array. For each value ii, 2*ii and 2*ii+1 are the coordinates of a single vertex.
A valid list of indices must only refer to vertices in the vertex array. That is, the indices should all be non-negative, and each value should be less than the number of vertices.
This method will assign a type accoring to the multiplicity of the indices. If the number of indices n is correct for a closed or open path of all vertices (e.g. 2n or 2n-2), then the type will be PATH. Otherwise, if n is divisible by 3 it will be SOLID. All other values will be UNDEFINED, and the user must manually set the type.
This method returns a reference to this polygon for chaining.
vertices | The vector of vertices (as floats) in this polygon |
indices | The vector of indices for the rendering |
Sets the polygon to have the given vertices.
The resulting polygon has no indices and the type is UNDEFINED.
This method returns a reference to this polygon for chaining.
vertices | The array of vertices (as Vec2) in this polygon |
vertsize | The number of elements to use from vertices |
voffset | The offset in vertices to start the polygon |
|
inline |
Sets the polygon to have the given vertices.
The float array should have an even number of elements. The number of vertices is half of the size of the array. For each value ii, 2*ii and 2*ii+1 are the coordinates of a single vertex.
The resulting polygon has no indices and the type is UNDEFINED.
This method returns a reference to this polygon for chaining.
vertices | The array of vertices (as floats) in this polygon |
vertsize | The number of elements to use from vertices |
voffset | The offset in vertices to start the polygon |
Poly2& cugl::Poly2::set | ( | Vec2 * | vertices, |
int | vertsize, | ||
unsigned short * | indices, | ||
int | indxsize, | ||
int | voffset = 0 , |
||
int | ioffset = 0 |
||
) |
Sets the polygon to have the given vertices and indices.
A valid list of indices must only refer to vertices in the vertex array. That is, the indices should all be non-negative, and each value should be less than the number of vertices.
This method will assign a type accoring to the multiplicity of the indices. If the number of indices n is correct for a closed or open path of all vertices (e.g. 2n or 2n-2), then the type will be PATH. Otherwise, if n is divisible by 3 it will be SOLID. All other values will be UNDEFINED, and the user must manually set the type.
This method returns a reference to this polygon for chaining.
vertices | The array of vertices (as Vec2) in this polygon |
vertsize | The number of elements to use from vertices |
indices | The array of indices for the rendering |
indxsize | The number of elements to use for the indices |
voffset | The offset in vertices to start the polygon |
ioffset | The offset in indices to start from |
|
inline |
Sets the polygon to have the given vertices and indices.
The float array should have an even number of elements. The number of vertices is half of the size of the array. For each value ii, 2*ii and 2*ii+1 are the coordinates of a single vertex.
A valid list of indices must only refer to vertices in the vertex array. That is, the indices should all be non-negative, and each value should be less than the number of vertices.
This method will assign a type accoring to the multiplicity of the indices. If the number of indices n is correct for a closed or open path of all vertices (e.g. 2n or 2n-2), then the type will be PATH. Otherwise, if n is divisible by 3 it will be SOLID. All other values will be UNDEFINED, and the user must manually set the type.
This method returns a reference to this polygon for chaining.
vertices | The array of vertices (as floats) in this polygon |
vertsize | The number of elements to use from vertices |
indices | The array of indices for the rendering |
indxsize | The number of elements to use for the indices |
voffset | The offset in vertices to start the polygon |
ioffset | The offset in indices to start from |
Sets this polygon to be a copy of the given one.
All of the contents are copied, so that this polygon does not hold any references to elements of the other polygon. This method returns a reference to this polygon for chaining.
This method returns a reference to this polygon for chaining.
poly | The polygon to copy |
Sets the polygon to represent the given rectangle.
The polygon will have four vertices, one for each corner of the rectangle. This optional argument (which is true by default) will initialize the indices with a triangulation of the rectangle. In other words, the type will be SOLID. This is faster than using one of the more heavy-weight triangulators.
If solid is false, it will still generate indices, but will be a PATH instead.
rect | The rectangle to copy |
solid | Whether to treat this rectangle as a solid polygon |
Poly2& cugl::Poly2::setIndices | ( | const std::vector< unsigned short > & | indices | ) |
Sets the indices for this polygon to the ones given.
A valid list of indices must only refer to vertices in the vertex array. That is, the indices should all be non-negative, and each value should be less than the number of vertices.
This method will assign a type accoring to the multiplicity of the indices. If the number of indices n is correct for a closed or open path of all vertices (e.g. 2n or 2n-2), then the type will be PATH. Otherwise, if n is divisible by 3 it will be SOLID. All other values will be UNDEFINED, and the user must manually set the type.
This method returns a reference to this polygon for chaining.
indices | The vector of indices for the shape |
Poly2& cugl::Poly2::setIndices | ( | unsigned short * | indices, |
int | indxsize, | ||
int | ioffset = 0 |
||
) |
Sets the indices for this polygon to the ones given.
A valid list of indices must only refer to vertices in the vertex array. That is, the indices should all be non-negative, and each value should be less than the number of vertices.
The provided array is copied. The polygon does not retain a reference.
This method will assign a type accoring to the multiplicity of the indices. If the number of indices n is correct for a closed or open path of all vertices (e.g. 2n or 2n-2), then the type will be PATH. Otherwise, if n is divisible by 3 it will be SOLID. All other values will be UNDEFINED, and the user must manually set the type.
This method returns a reference to this polygon for chaining.
indices | The array of indices for the rendering |
indxsize | The number of elements to use for the indices |
ioffset | The offset in indices to start from |
|
inline |
Sets the type of this polygon.
The type determines the proper form of the indices.
If the polygon is SOLID, there should be three times as many indices as vertices. Each triplet should define a triangle over the vertices.
If the polygon is PATH, there should be two times as many indices as vertices. Each pair should define a line segment over the vertices.
If the polygon is UNDEFINED, the index list should be empty.
type | The type of this polygon. |
Returns a new polygon by scaling the vertices uniformly.
The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.
scale | The uniform scaling factor |
Returns a new polygon by scaling the vertices non-uniformly.
The vertices are scaled from the origin of the coordinate space. This means that if the origin is not in the interior of this polygon, the polygon will be effectively translated by the scaling.
scale | The non-uniform scaling factor |