Colliding Shapes
Ian Parberry's "Introduction to Game Physics"
Public Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
CAabb2D Class Reference

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...
 
CAabb2Doperator= (const Vector2 &)
 Set AABB to point. More...
 
CAabb2Doperator+= (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...
 

Detailed Description

An AABB, or Axially Aligned Bounding Box, is a rectangle with axes aligned with the cardinal axes.

Constructor & Destructor Documentation

◆ CAabb2D() [1/2]

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.

Parameters
tlTop left corner.
brBottom right corner.

◆ CAabb2D() [2/2]

CAabb2D::CAabb2D ( )

The default constructor creates an AABB whose top left and bottom right corners are the origin.

Member Function Documentation

◆ GetBottomRt()

const Vector2 & CAabb2D::GetBottomRt ( )

Reader function for the bottom right corner.

Returns
The bottom right corner.

◆ GetHt()

float CAabb2D::GetHt ( )

Reader function for the height.

Returns
AABB height.

◆ GetTestCount()

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.

Returns
Number of tests since last call.

◆ GetTopLeft()

const Vector2 & CAabb2D::GetTopLeft ( )

Reader function for the top left corner.

Returns
The top left corner.

◆ GetWidth()

float CAabb2D::GetWidth ( )

Reader function for the width.

Returns
AABB width.

◆ operator+=()

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.

Parameters
pA point.
Returns
AABB consisting of old AABB extended to cover p.

◆ operator=()

CAabb2D & CAabb2D::operator= ( const Vector2 &  p)

Overloaded assignment operator that sets an AABB to a single point.

Parameters
pA point.
Returns
AABB for the point.

◆ Translate()

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.

Parameters
pVector displacement.

Friends And Related Function Documentation

◆ operator && [1/2]

bool operator&& ( const CAabb2D a,
const CAabb2D b 
)
friend

Overloaded && operator to determine whether an AABB overlaps another AABB.

Parameters
aAn AABB.
bAn AABB.
Returns
true if a and b overlap

◆ operator && [2/2]

bool operator&& ( const CAabb2D a,
const Vector2 &  p 
)
friend

Overloaded && operator to determine whether a point is inside an AABB.

Parameters
aAn AABB.
pA point.
Returns
true if p is inside a.