#include <qafCollisionStruct.h>
Inheritance diagram for qaf::CollisionStruct::Polygon:
The polygon may be concave and its edges may intersect. You could hardly ask for anything more generic than this, although it is much less efficient than other collision structures.
The polygon defined by points
is assumed to be the "untranslated" version of the collision boundary. If this were an hgeSprite
, think of the point (0, 0) as the polygon's hot spot.
Typically, you would specify the object's polygon points relative to its sprite's hot spot, and then update the polygon's position to the object's position once per frame.
Public Member Functions | |
Polygon (const hgeSprite *pSprite) | |
This constructor will create a polygon based on a sprite's width, height, and hotspot. | |
Polygon () | |
Default constructor, that creates an "empty" polygon. | |
void | getTransformedPoints (Container< Vector2D > *points) |
Returns the polygon points with scaling/translation applied. | |
void | setPosition (float x, float y) |
Sets the object's displacement relative to (0, 0). | |
void | getPosition (float *x, float *py) |
Gets the object displacement relative to (0, 0). | |
void | setRotation (float radians) |
Sets the object's rotation around its hot spot. | |
float | getRotation () |
Gets the object's rotation around its hot spot. | |
void | setScale (float s) |
Sets the object's scale. | |
void | getScale () |
Gets the object's current scale. | |
void | render (float scrollX, float scrollY, unsigned long color) |
bool | collidesWith (CollisionStruct *otherStruct) |
bool | hasPoint (float x, float y) |
bool | pointIntersection (float x1, float y1, float x2, float y2, Vector2D *pContact, Vector2D *pNormal) |
void | move (float dx, float dy) |
void | setPoints (const Vector2D *points, int nPoints) |
Redefines the points that represent the polygon's outline. | |
void | setPoints (const Container< Vector2D > &points) |
Redefines the points that represent the polygon's outline. |
qaf::CollisionStruct::Polygon::Polygon | ( | const Vector2D * | points, | |
int | nPoints | |||
) |
The constructor receives a series of points that represent the polygon's outline.
The polygon is always assumed to be closed (i.e., the last point will be "linked" with the first point).
The constructor receives a series of points that represent the polygon's outline.
The polygon is always assumed to be closed (i.e., the last point will be "linked" with the first point).
qaf::CollisionStruct::Polygon::Polygon | ( | const hgeSprite * | pSprite | ) |
This constructor will create a polygon based on a sprite's width, height, and hotspot.
You can then use it as the bounding box to represent the sprite, even when it's rotated/scaled.
qaf::CollisionStruct::Polygon::Polygon | ( | const Vector2D * | points, | |
int | nPoints | |||
) |
The constructor receives a series of points that represent the polygon's outline.
The polygon is always assumed to be closed (i.e., the last point will be "linked" with the first point).
The constructor receives a series of points that represent the polygon's outline.
The polygon is always assumed to be closed (i.e., the last point will be "linked" with the first point).
void qaf::CollisionStruct::Polygon::getTransformedPoints | ( | Container< Vector2D > * | points | ) | [inline] |
Returns the polygon points with scaling/translation applied.