The Shapes Library
Game Physics with Bespoke Code
Loading...
Searching...
No Matches
Shapes::CAabb2D Class Reference

2D Axially Aligned Bounding Box. More...

#include <AABB.h>

Public Member Functions

 CAabb2D (const Vector2 &, const Vector2 &)
 Constructor.
 
 CAabb2D ()
 Default constructor.
 
void Translate (const Vector2 &)
 Translate AABB.
 
CAabb2Doperator= (const Vector2 &)
 Set AABB to point.
 
CAabb2Doperator+= (const Vector2 &)
 Add point to AABB.
 
const float GetWidth () const
 Get width of AABB.
 
const float GetHt () const
 Get height of AABB.
 
const Vector2 & GetTopLeft () const
 Get top left corner.
 
const Vector2 & GetBottomRt () const
 Get bottom right corner.
 
UINT GetAndResetTestCount ()
 Get and reset number of intersection tests.
 

Private Attributes

Vector2 m_vTopLeft
 Top left point.
 
Vector2 m_vBottomRt
 Bottom right point.
 

Static Private Attributes

static UINT m_nTestCount = 0LLU
 Number of AABB to AABB intersection tests.
 

Friends

bool operator&& (const CAabb2D &, const CAabb2D &)
 AABB intersection test.
 
bool operator&& (const CAabb2D &, const Vector2 &)
 AABB intersection test.
 

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

◆ GetAndResetTestCount()

UINT CAabb2D::GetAndResetTestCount ( )

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.

◆ GetBottomRt()

const Vector2 & CAabb2D::GetBottomRt ( ) const

Reader function for the bottom right corner.

Returns
The bottom right corner.

◆ GetHt()

const float CAabb2D::GetHt ( ) const

Reader function for the height.

Returns
AABB height.

◆ GetTopLeft()

const Vector2 & CAabb2D::GetTopLeft ( ) const

Reader function for the top left corner.

Returns
The top left corner.

◆ GetWidth()

const float CAabb2D::GetWidth ( ) const

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.
Here is the caller graph for this function: