Cornell Cocos
Cornell Extensions to Cocos2d
Public Types | Public Member Functions | Friends | List of all members
Poly2 Class Reference

#include <CUPoly2.h>

Public Types

enum  Traversal { Traversal::OPEN, Traversal::CLOSED, Traversal::INTERIOR }
 
enum  Joint { Joint::NONE, Joint::MITRE, Joint::BEVEL, Joint::ROUND }
 
enum  Cap { Cap::NONE, Cap::SQUARE, Cap::ROUND }
 

Public Member Functions

 Poly2 ()
 
 Poly2 (const vector< Vec2 > &vertices)
 
 Poly2 (const vector< Vec2 > &vertices, const vector< unsigned short > &indices)
 
 Poly2 (const vector< float > &vertices)
 
 Poly2 (const vector< float > &vertices, const 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 index=true)
 
 ~Poly2 ()
 
Poly2set (const vector< Vec2 > &vertices)
 
Poly2set (const vector< Vec2 > &vertices, const vector< unsigned short > &indices)
 
Poly2set (const vector< float > &vertices)
 
Poly2set (const vector< float > &vertices, const vector< unsigned short > &indices)
 
Poly2set (Vec2 *vertices, int vertsize, int voffset=0)
 
Poly2set (float *vertices, int vertsize, int voffset=0)
 
Poly2set (Vec2 *vertices, int vertsize, unsigned short *indices, int indxsize, int voffset=0, int ioffset=0)
 
Poly2set (float *vertices, int vertsize, unsigned short *indices, int indxsize, int voffset=0, int ioffset=0)
 
Poly2set (const Poly2 &poly)
 
Poly2set (const Rect &rect, bool index=true)
 
Poly2setLine (const Vec2 &origin, const Vec2 &dest)
 
Poly2setEllipse (const Vec2 &center, const Size &size, unsigned int segments)
 
Poly2setIndices (const vector< unsigned short > &indices)
 
Poly2setIndices (unsigned short *indices, int indxsize, int ioffset=0)
 
Poly2triangulate ()
 
Poly2traverse (Traversal traversal=Traversal::CLOSED)
 
Poly2extrude (Poly2 &poly, float stroke, bool closed=true, Joint joint=Joint::NONE, Cap cap=Cap::NONE)
 
const vector< Vec2 > & getVertices () const
 
const vector< unsigned short > & getIndices () const
 
const Rect & getBounds () const
 
Poly2operator= (const Poly2 &other)
 
Poly2operator*= (float scale)
 
Poly2operator*= (const Vec2 &scale)
 
Poly2operator*= (const Mat4 &transform)
 
Poly2operator/= (float scale)
 
Poly2operator/= (const Vec2 &scale)
 
Poly2operator+= (float offset)
 
Poly2operator+= (const Vec2 &offset)
 
Poly2operator-= (float offset)
 
Poly2operator-= (const Vec2 &offset)
 
Poly2 operator* (float scale) const
 
Poly2 operator* (const Vec2 &scale) 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)
 

Friends

Poly2 operator* (float scale, const Poly2 &poly)
 
Poly2 operator* (const Vec2 &scale, const Poly2 &poly)
 
Poly2 operator+ (float offset, const Poly2 &poly)
 
Poly2 operator+ (const Vec2 &offset, const Poly2 &poly)
 

Detailed Description

Class to represent a simple polygon.

This class can represent any polygon (including non-convex polygons) that does not have holes or self-interections. It will not check for holes or self-intersections; those are the responsibility of the programmer.

When instantiating this class, the user can 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). The class does not enforce any semantic meaning on these indices. This class simply stores them. The semantic meaning is up the appropriate scene graph or graphics class.

This class does provide several methods for automatic index generation. There is a triangulate() method which will triangulate automatically via an ear-clipping. algorithm. There is also a traveral method for creating indices for a wireframe.

Member Enumeration Documentation

enum Poly2::Cap
strong

Enum for the end caps of an extruded path.

Enumerator
NONE 

No end cap; the path terminates at the end vertices

SQUARE 

Square cap; like no cap, except the ends are padded by stroke width

ROUND 

Round cap; the ends are half circles whose radius is the stroke width

enum Poly2::Joint
strong

Enum for the joints of an extruded path.

Enumerator
NONE 

No joint; the path will look like a sequence of links

MITRE 

Mitre joint; ideal for paths with sharp corners

BEVEL 

Bevel joint; ideal for smoother paths

ROUND 

Round joint; used to smooth out paths with sharp corners

enum Poly2::Traversal
strong

Enum for the type of path traversal.

Enumerator
OPEN 

Traverse the border, but do not close the ends.

CLOSED 

Traverse the border, and close the ends.

INTERIOR 

Traverse the individual triangles in the tesselation.

Constructor & Destructor Documentation

Poly2::Poly2 ( )
inline

Creates an empty polygon.

The created polygon has no vertices and no triangulation. The bounding box is trivial.

Poly2::Poly2 ( const vector< Vec2 > &  vertices)
inline

Creates a polygon with the given vertices

The new polygon has no indices.

Parameters
verticesThe vector of vertices (as Vec2) in this polygon
Poly2::Poly2 ( const vector< Vec2 > &  vertices,
const vector< unsigned short > &  indices 
)
inline

Creates a polygon with the given vertices and indices.

A valid list of indices must only refer to vertices in the vertex array. Remember that vertex ii refers to both elements 2*ii and 2*ii+1 in the array of vertices. This constructor does not verify that the set of indices is valid.

Parameters
verticesThe vector of vertices (as Vec2) in this polygon
indicesThe vector of indices for the rendering
Poly2::Poly2 ( const vector< float > &  vertices)
inline

Creates a polygon with the given vertices

The new polygon has no indices.

Parameters
verticesThe vector of vertices (as floats) in this polygon
Poly2::Poly2 ( const vector< float > &  vertices,
const vector< unsigned short > &  indices 
)
inline

Creates a polygon with the given vertices and indices.

A valid list of indices must only refer to vertices in the vertex array. This constructor does not verify that the set of indices is valid.

Parameters
verticesThe vector of vertices (as floats) in this polygon
indicesThe vector of indices for the rendering
Poly2::Poly2 ( Vec2 *  vertices,
int  vertsize,
int  voffset = 0 
)
inline

Creates a polygon with the given vertices

The new polygon has no indices.

Parameters
verticesThe array of vertices (as Vec2) in this polygon
vertsizeThe number of elements to use from vertices
voffsetThe offset in vertices to start the polygon
Poly2::Poly2 ( float *  vertices,
int  vertsize,
int  voffset = 0 
)
inline

Creates a polygon with the given vertices

The new polygon has no indices.

Parameters
verticesThe array of vertices (as floats) in this polygon
vertsizeThe number of elements to use from vertices
voffsetThe offset in vertices to start the polygon
Poly2::Poly2 ( Vec2 *  vertices,
int  vertsize,
unsigned short *  indices,
int  indxsize,
int  voffset = 0,
int  ioffset = 0 
)
inline

Creates a polygon with the given vertices and indices.

A valid list of indices must only refer to vertices in the vertex array. This constructor does not verify that the set of indices is valid.

Parameters
verticesThe array of vertices (as Vec2) in this polygon
vertsizeThe number of elements to use from vertices
indicesThe array of indices for the rendering
indxsizeThe number of elements to use for the indices
voffsetThe offset in vertices to start the polygon
ioffsetThe offset in indices to start from
Poly2::Poly2 ( float *  vertices,
int  vertsize,
unsigned short *  indices,
int  indxsize,
int  voffset = 0,
int  ioffset = 0 
)
inline

Creates a polygon with the given vertices and indices.

A valid list of indices must only refer to vertices in the vertex array. This constructor does not verify that the set of indices is valid.

Parameters
verticesThe array of vertices (as floats) in this polygon
vertsizeThe number of elements to use from vertices
indicesThe array of indices for the rendering
indxsizeThe number of elements to use for the indices
voffsetThe offset in vertices to start the polygon
ioffsetThe offset in indices to start from
Poly2::Poly2 ( const Poly2 poly)
inline

Creates a copy of the given polygon.

Both the vertices and the indices are copied.

Parameters
polyThe polygon to copy
Poly2::Poly2 ( const Rect &  rect,
bool  index = true 
)
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. This is faster than calling the triangulate() method directly.

Parameters
rectThe rectangle to copy
indexWhether to generate indices for the rect
Poly2::~Poly2 ( )
inline

Deletes the given polygon.

Member Function Documentation

Poly2 * Poly2::extrude ( Poly2 poly,
float  stroke,
bool  closed = true,
Joint  joint = Joint::NONE,
Cap  cap = Cap::NONE 
)

Generates a new polygon that is an extrusion of this one.

An extrusion of a polygon is a second polygon that follows the path of the first one, but gives it width. Hence it takes a path and turns it into a solid shape. This is more complicated than simply triangulating the original polygon. The new polygon has more vertices, depending on the choice of joint (shape at the corners) and cap (shape at the end).

Unlike the traverse option, this method cannot be used to extrude an internal polygon tesselation. It assumes that the path is continuous.

CREDITS: This code is ported from the Kivy implementation of Line in package kivy.vertex_instructions. My belief is that this port is acceptable within the scope of the Kivy license. There are no specific credits in that file, so there is no one specific to credit. However, thanks to the Kivy team for doing the heavy lifting on this method.

Because they did all the hard work, I will plug their picture of how joints and end caps work:

 http://kivy.org/docs/_images/line-instruction.png

This method does not allocate a new polygon. You provide it with a polygon to store the values. This method returns a reference to that polygon (not the original one) for chaining.

Parameters
polyThe polygon to store the new vertices and indices
strokeThe stroke width of the extrusion
closedWhether or not the polygon path is closed
jointThe joint shape (default NONE) for corners
capThe cap shape (default NONE) for the two ends
Returns
Reference to the newly initialized polygon
const Rect& Poly2::getBounds ( ) const
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.

Returns
the bounding box for the polygon
const vector<unsigned short>& Poly2::getIndices ( ) const
inline

Returns a reference to list of indices index.

This accessor will not permit any changes to the index array. To change the array, you must change the polygon via a set() method.

Returns
a reference to the vertex array
const vector<Vec2>& Poly2::getVertices ( ) const
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.

Returns
a reference to the vertex array
Poly2 Poly2::operator* ( float  scale) const
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.

Parameters
scaleThe uniform scaling factor
Returns
The scaled polygon
Poly2 Poly2::operator* ( const Vec2 &  scale) const
inline

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.

Parameters
scaleThe non-uniform scaling factor
Returns
The scaled polygon
Poly2 Poly2::operator* ( const Mat4 &  transform) const
inline

Returns a new polygon by transforming all of the vertices of this polygon.

The vertices are transformed as points; they are treated if they are homongenous vectors with z = 0.

Parameters
Mat4The transform matrix
Returns
The transformed polygon
Poly2 & 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.

Parameters
scaleThe uniform scaling factor
Returns
This polygon, scaled uniformly.
Poly2 & Poly2::operator*= ( const Vec2 &  scale)

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.

Parameters
scaleThe non-uniform scaling factor
Returns
This polygon, scaled non-uniformly.
Poly2 & Poly2::operator*= ( const Mat4 &  transform)

Transforms all of the vertices of this polygon.

The vertices are transformed as points; they are treated if they are homongenous vectors with z = 0.

Parameters
Mat4The transform matrix
Returns
This polygon with the vertices transformed
Poly2 Poly2::operator+ ( float  offset) const
inline

Returns a new polygon by translating the vertices uniformly.

The vertices are all shifted by the given amount. Note that this operation has no effect on getTriangles(), as the drawing vertices are always normalized to have an origin relative to the polygon bounding box.

Parameters
offsetThe uniform translation amount
Returns
The translated polygon
Poly2 Poly2::operator+ ( const Vec2 &  offset) const
inline

Returns a new polygon by translating the vertices non-uniformly.

The vertices are all shifted by the given amount. Note that this operation has no effect on getTriangles(), as the drawing vertices are always normalized to have an origin relative to the polygon bounding box.

Parameters
offsetThe non-uniform translation amount
Returns
The translated polygon
Poly2 & Poly2::operator+= ( float  offset)

Uniformly translates all of the vertices of this polygon.

The vertices are all shifted by the given amount. Note that this operation has no effect on getTriangles(), as the drawing vertices are always normalized to have an origin relative to the polygon bounding box.

Parameters
offsetThe uniform translation amount
Returns
This polygon, translated uniformly.
Poly2 & Poly2::operator+= ( const Vec2 &  offset)

Non-uniformly translates all of the vertices of this polygon.

The vertices are all shifted by the given amount. Note that this operation has no effect on getTriangles(), as the drawing vertices are always normalized to have an origin relative to the polygon bounding box.

Parameters
offsetThe non-uniform translation amount
Returns
This polygon, translated non-uniformly.
Poly2 Poly2::operator- ( float  offset)
inline

Returns a new polygon by translating the vertices uniformly.

The vertices are all shifted by the given amount. Note that this operation has no effect on getTriangles(), as the drawing vertices are always normalized to have an origin relative to the polygon bounding box.

Parameters
offsetThe inverse of the uniform translation amount
Returns
The translated polygon
Poly2 Poly2::operator- ( const Vec2 &  offset)
inline

Returns a new polygon by translating the vertices non-uniformly.

The vertices are all shifted by the given amount. Note that this operation has no effect on getTriangles(), as the drawing vertices are always normalized to have an origin relative to the polygon bounding box.

Parameters
offsetThe inverse of the non-uniform translation amount
Returns
The translated polygon
Poly2 & Poly2::operator-= ( float  offset)

Uniformly translates all of the vertices of this polygon.

The vertices are all shifted by the given amount. Note that this operation has no effect on getTriangles(), as the drawing vertices are always normalized to have an origin relative to the polygon bounding box.

Parameters
offsetThe inverse of the uniform translation amount
Returns
This polygon, translated uniformly.
Poly2 & Poly2::operator-= ( const Vec2 &  offset)

Non-uniformly translates all of the vertices of this polygon.

The vertices are all shifted by the given amount. Note that this operation has no effect on getTriangles(), as the drawing vertices are always normalized to have an origin relative to the polygon bounding box.

Parameters
offsetThe inverse of the non-uniform translation amount
Returns
This polygon, translated non-uniformly.
Poly2 Poly2::operator/ ( float  scale) const
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.

Parameters
scaleThe inverse of the uniform scaling factor
Returns
The scaled polygon
Poly2 Poly2::operator/ ( const Vec2 &  scale) const
inline

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.

Parameters
scaleThe inverse of the non-uniform scaling factor
Returns
The scaled polygon
Poly2 & 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.

Parameters
scaleThe inverse of the uniform scaling factor
Returns
This polygon, scaled uniformly.
Poly2 & Poly2::operator/= ( const Vec2 &  scale)

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.

Parameters
scaleThe inverse of the non-uniform scaling factor
Returns
This polygon, scaled non-uniformly.
Poly2& Poly2::operator= ( const Poly2 other)
inline

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.

Parameters
polyThe polygon to copy
Returns
This polygon, returned for chaining
Poly2 & Poly2::set ( const vector< Vec2 > &  vertices)

Sets the polygon to have the given vertices

The new polygon has no indices.

This method returns a reference to this polygon for chaining.

Parameters
verticesThe vector of vertices (as Vec2) in this polygon
Returns
This polygon, returned for chaining
Poly2 & Poly2::set ( const vector< Vec2 > &  vertices,
const 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. Remember that vertex ii refers to both elements 2*ii and 2*ii+1 in the array of vertices. This constructor does not verify that the set of indices is valid.

This method returns a reference to this polygon for chaining.

Parameters
verticesThe vector of vertices (as Vec2) in this polygon
indicesThe vector of indices for the rendering
Returns
This polygon, returned for chaining
Poly2 & Poly2::set ( const vector< float > &  vertices)

Sets the polygon to have the given vertices

The new polygon has no indices.

This method returns a reference to this polygon for chaining.

Parameters
verticesThe vector of vertices (as floats) in this polygon
Returns
This polygon, returned for chaining
Poly2 & Poly2::set ( const vector< float > &  vertices,
const vector< unsigned short > &  indices 
)

Sets a polygon to have the given vertices and indices.

A valid list of indices must only refer to vertices in the vertex array. This constructor does not verify that the set of indices is valid.

This method returns a reference to this polygon for chaining.

Parameters
verticesThe vector of vertices (as floats) in this polygon
indicesThe vector of indices for the rendering
Returns
This polygon, returned for chaining
Poly2 & Poly2::set ( Vec2 *  vertices,
int  vertsize,
int  voffset = 0 
)

Sets the polygon to have the given vertices.

The new polygon has no indices.

This method returns a reference to this polygon for chaining.

Parameters
verticesThe array of vertices (as Vec2) in this polygon
vertsizeThe number of elements to use from vertices
voffsetThe offset in vertices to start the polygon
Returns
This polygon, returned for chaining
Poly2& Poly2::set ( float *  vertices,
int  vertsize,
int  voffset = 0 
)
inline

Sets the polygon to have the given vertices.

The new polygon has no indices.

This method returns a reference to this polygon for chaining.

Parameters
verticesThe array of vertices (as floats) in this polygon
vertsizeThe number of elements to use from vertices
voffsetThe offset in vertices to start the polygon
Returns
This polygon, returned for chaining
Poly2 & 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. This constructor does not verify that the set of indices is valid.

This method returns a reference to this polygon for chaining.

Parameters
verticesThe array of vertices (as Vec2) in this polygon
vertsizeThe number of elements to use from vertices
indicesThe array of indices for the rendering
indxsizeThe number of elements to use for the indices
voffsetThe offset in vertices to start the polygon
ioffsetThe offset in indices to start from
Returns
This polygon, returned for chaining
Poly2& Poly2::set ( float *  vertices,
int  vertsize,
unsigned short *  indices,
int  indxsize,
int  voffset = 0,
int  ioffset = 0 
)
inline

Sets the polygon to have the given vertices and indices.

A valid list of indices must only refer to vertices in the vertex array. Remember that, for float representation, vertex ii refers to both elements 2*ii and 2*ii+1 in the array of vertices. This constructor does not verify that the set of indices is valid.

This method returns a reference to this polygon for chaining.

Parameters
verticesThe array of vertices (as floats) in this polygon
vertsizeThe number of elements to use from vertices
indicesThe array of indices for the rendering
indxsizeThe number of elements to use for the indices
voffsetThe offset in vertices to start the polygon
ioffsetThe offset in indices to start from
Returns
This polygon, returned for chaining
Poly2 & Poly2::set ( const Poly2 poly)

Sets this polygon to be a copy of the given one.

Both the vertices and the indices are copied. All of the content arrays are copied, so that this polygon does not hold any references to elements of poly.

This method returns a reference to this polygon for chaining.

Parameters
polyThe polygon to copy
Returns
This polygon, returned for chaining
Poly2 & Poly2::set ( const Rect &  rect,
bool  index = true 
)

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. This is faster than calling the triangulate() method directly.

This method returns a reference to this polygon for chaining.

Parameters
rectThe rectangle to copy
indexWhether to generate indices for the rect
Returns
This polygon, returned for chaining
Poly2 & Poly2::setEllipse ( const Vec2 &  center,
const Size &  size,
unsigned int  segments 
)

Sets the polygon to represent an ellipse of the given dimensions.

The triangulation will show the boundary, not the circle tesselation.

Parameters
centerThe ellipse center point.
sizeThe size of the ellipse.
segmentsThe number of segments to use.
Returns
This polygon, returned for chaining
Poly2 & Poly2::setIndices ( const 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. Remember that vertex ii refers to both elements 2*ii and 2*ii+1 in the array vertices. This constructor does not verify that the set of indices is valid.

Parameters
indicesThe vector of indices for the rendering
Returns
This polygon, returned for chaining
Poly2 & 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. Remember that vertex ii refers to both elements 2*ii and 2*ii+1 in the array vertices. This constructor does not verify that the set of indices is valid.

The provided array is copied. The polygon does not retain a reference. This method returns a reference to this polygon for chaining.

Parameters
indicesThe array of indices for the rendering
indxsizeThe number of elements to use for the indices
ioffsetThe offset in indices to start from
Returns
This polygon, returned for chaining
Poly2 & Poly2::setLine ( const Vec2 &  origin,
const Vec2 &  dest 
)

Sets the polygon to represent a line from origin to dest.

This method returns a reference to this polygon for chaining.

Parameters
originThe line origin.
destThe line destination.
Returns
This polygon, returned for chaining
Poly2 & Poly2::traverse ( Traversal  traversal = Traversal::CLOSED)

Generates indices from a traversal of the polygon vertices.

A traversal is useful for creating a wireframe from a polygon. The type of wireframe generated depends on the traversal value:

OPEN:     The traversal is in order, but does not close the ends.

CLOSED:   The traversal is in order, and closes the ends.

INTERIOR: The traverse will outline the default triangulation.

The default is CLOSED_TRAVERSAL.

This method returns a reference to this polygon for chaining.

Parameters
traversalThe path to traverse for index generation.
Returns
This polygon, returned for chaining
Poly2 & Poly2::triangulate ( )

Generates indices from a default triangulation of this polygon.

This method uses ear-clipping for triangulation, which is faster than poly2tri for our simple applications.

This method returns a reference to this polygon for chaining.

Returns
This polygon, returned for chaining

Friends And Related Function Documentation

Poly2 operator* ( float  scale,
const Poly2 poly 
)
friend

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.

Parameters
scaleThe uniform scaling factor
Returns
The scaled polygon
Poly2 operator* ( const Vec2 &  scale,
const Poly2 poly 
)
friend

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.

Parameters
scaleThe non-uniform scaling factor
Returns
The scaled polygon
Poly2 operator+ ( float  offset,
const Poly2 poly 
)
friend

Returns a new polygon by translating the vertices uniformly.

The vertices are all shifted by the given amount. Note that this operation has no effect on getTriangles(), as the drawing vertices are always normalized to have an origin relative to the polygon bounding box.

Parameters
offsetThe uniform translation amount
Returns
The translated polygon
Poly2 operator+ ( const Vec2 &  offset,
const Poly2 poly 
)
friend

Returns a new polygon by translating the vertices non-uniformly.

The vertices are all shifted by the given amount. Note that this operation has no effect on getTriangles(), as the drawing vertices are always normalized to have an origin relative to the polygon bounding box.

Parameters
offsetThe non-uniform translation amount
Returns
The translated polygon

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