Class twodee.Polygon
A polygon.
Defined in: Polygon.js.
Constructor Attributes | Constructor Name and Description |
---|---|
twodee.Polygon(vertices)
Constructs a new polygon
|
Field Attributes | Field Name and Description |
---|---|
<static> |
twodee.Polygon.counter
Instance counter.
|
Method Attributes | Method Name and Description |
---|---|
apply(g)
Applies the polygon as a path to the specified canvas 2D context.
|
|
collidesWith(other)
Checks if the this polygon collides with the specified other polygon.
|
|
copy()
Returns a copy of this polygon.
|
|
Returns the number of polygon vertices.
|
|
Returns the current bounding box of this polygon.
|
|
getVertex(index)
Returns the vertex with the specified index.
|
|
setTransform(m)
Sets the transformation of the polygon.
|
|
transform(m)
Transforms the vertices of the polygon with the specified matrix.
|
Class Detail
twodee.Polygon(vertices)
Constructs a new polygon
- Parameters:
-
{Array.
} vertices - The vertices as array of vectors.
Field Detail
<static>
twodee.Polygon.counter
Instance counter.
Method Detail
apply(g)
Applies the polygon as a path to the specified canvas 2D context.
- Parameters:
- {CanvasRenderingContext2D} g
- The canvas 2D context to apply the polygon to
{boolean}
collidesWith(other)
Checks if the this polygon collides with the specified other polygon.
Note that this check only works for convex polygons. A simple bounding box
check is done before the complex polygon collision detection is used.
- Parameters:
- {twodee.Polygon} other
- The other polygon to test collision with
- Returns:
- {boolean} True if the polygons collide, false if not
{twodee.Polygon}
copy()
Returns a copy of this polygon.
- Returns:
- {twodee.Polygon} The polygon copy
{number}
countVertices()
Returns the number of polygon vertices.
- Returns:
- {number} The number of polygon vertices
{twodee.BoundingBox}
getBoundingBox()
Returns the current bounding box of this polygon.
- Returns:
- {twodee.BoundingBox} The current bounding box
{twodee.Vector}
getVertex(index)
Returns the vertex with the specified index.
- Parameters:
- {number} index
- The vertex index
- Returns:
- {twodee.Vector} The vertex
setTransform(m)
Sets the transformation of the polygon. This method uses the original
vertices instead of the already transformed vertices. So using this
method is effectively the same as calling reset() and then transform().
But its a little bit faster.
- Parameters:
- {twodee.Matrix} m
- The matrix to transform this polygon with
transform(m)
Transforms the vertices of the polygon with the specified matrix.
- Parameters:
- {twodee.Matrix} m
- The matrix to transform this polygon with