![]() |
Colliding Shapes
Ian Parberry's "Introduction to Game Physics"
|
2D Axially Aligned Bounding Box. More...
#include <AABB.h>
Public Member Functions | |
CAabb2D (const Vector2 &, const Vector2 &) | |
Constructor. More... | |
CAabb2D () | |
Default constructor. More... | |
void | Translate (const Vector2 &) |
Translate AABB. More... | |
CAabb2D & | operator= (const Vector2 &) |
Set AABB to point. More... | |
CAabb2D & | operator+= (const Vector2 &) |
Add point to AABB. More... | |
float | GetWidth () |
Get width of AABB. More... | |
float | GetHt () |
Get height of AABB. More... | |
const Vector2 & | GetTopLeft () |
Get top left corner. More... | |
const Vector2 & | GetBottomRt () |
Get bottom right corner. More... | |
int | GetTestCount () |
Get number of AABB to AABB intersection tests. More... | |
Private Attributes | |
Vector2 | m_vTopLeft |
Top left point. | |
Vector2 | m_vBottomRt |
Bottom right point. | |
Static Private Attributes | |
static int | m_nTestCount = 0 |
Number of AABB to AABB intersection tests. | |
Friends | |
bool | operator && (const CAabb2D &, const CAabb2D &) |
AABB intersection test. More... | |
bool | operator && (const CAabb2D &, const Vector2 &) |
AABB intersection test. More... | |
An AABB, or Axially Aligned Bounding Box, is a rectangle with axes aligned with the cardinal axes.
CAabb2D::CAabb2D | ( | const Vector2 & | tl, |
const Vector2 & | br | ||
) |
This constructor creates an AABB given its top left and bottom right corners. No effort is made to check whether the top left corner is actually above and to the left of the bottom right corner, so beware.
tl | Top left corner. |
br | Bottom right corner. |
CAabb2D::CAabb2D | ( | ) |
The default constructor creates an AABB whose top left and bottom right corners are the origin.
const Vector2 & CAabb2D::GetBottomRt | ( | ) |
Reader function for the bottom right corner.
float CAabb2D::GetHt | ( | ) |
Reader function for the height.
int CAabb2D::GetTestCount | ( | ) |
Get the number of AABB to AABB intersection tests made since the last time this function was called, and reset it to zero.
const Vector2 & CAabb2D::GetTopLeft | ( | ) |
Reader function for the top left corner.
float CAabb2D::GetWidth | ( | ) |
Reader function for the width.
CAabb2D & CAabb2D::operator+= | ( | const Vector2 & | p | ) |
Overloaded += operator that adds a point to an AABB, that is, it extends the AABB to cover the new point in addition to its existing area.
p | A point. |
CAabb2D & CAabb2D::operator= | ( | const Vector2 & | p | ) |
Overloaded assignment operator that sets an AABB to a single point.
p | A point. |
void CAabb2D::Translate | ( | const Vector2 & | p | ) |
Translate AABB to a new position. Adds the displacement vector to the top left and bottom right corners of the AABB.
p | Vector displacement. |
Overloaded && operator to determine whether an AABB overlaps another AABB.
a | An AABB. |
b | An AABB. |
|
friend |
Overloaded && operator to determine whether a point is inside an AABB.
a | An AABB. |
p | A point. |