OGRE 2.1
Object-Oriented Graphics Rendering Engine
Loading...
Searching...
No Matches
Ogre::AxisAlignedBox Class Reference

A 3D box aligned with the x/y/z axes. More...

#include <OgreAxisAlignedBox.h>

Public Types

enum  CornerEnum {
  FAR_LEFT_BOTTOM = 0 , FAR_LEFT_TOP = 1 , FAR_RIGHT_TOP = 2 , FAR_RIGHT_BOTTOM = 3 ,
  NEAR_RIGHT_BOTTOM = 7 , NEAR_LEFT_BOTTOM = 6 , NEAR_LEFT_TOP = 5 , NEAR_RIGHT_TOP = 4
}
 
enum  Extent { EXTENT_NULL , EXTENT_FINITE , EXTENT_INFINITE }
 

Public Member Functions

 AxisAlignedBox ()
 
 AxisAlignedBox (const AxisAlignedBox &rkBox)
 
 AxisAlignedBox (const Vector3 &min, const Vector3 &max)
 
 AxisAlignedBox (Extent e)
 
 AxisAlignedBox (Real mx, Real my, Real mz, Real Mx, Real My, Real Mz)
 
 ~AxisAlignedBox ()
 
bool contains (const AxisAlignedBox &other) const
 Tests whether another box contained by this box.
 
bool contains (const Vector3 &v) const
 Tests whether the given point contained by this box.
 
Real distance (const Vector3 &v) const
 Returns the minimum distance between a given point and any part of the box.
 
const Vector3getAllCorners (void) const
 Returns a pointer to an array of 8 corner points, useful for collision vs.
 
Vector3 getCenter (void) const
 Gets the centre of the box.
 
Vector3 getCorner (CornerEnum cornerToGet) const
 Gets the position of one of the corners.
 
Vector3 getHalfSize (void) const
 Gets the half-size of the box.
 
Vector3getMaximum (void)
 Gets a modifiable version of the maximum corner of the box.
 
const Vector3getMaximum (void) const
 Gets the maximum corner of the box.
 
Vector3getMinimum (void)
 Gets a modifiable version of the minimum corner of the box.
 
const Vector3getMinimum (void) const
 Gets the minimum corner of the box.
 
Vector3 getSize (void) const
 Gets the size of the box.
 
AxisAlignedBox intersection (const AxisAlignedBox &b2) const
 Calculate the area of intersection of this box and another.
 
bool intersects (const AxisAlignedBox &b2) const
 Returns whether or not this box intersects another.
 
bool intersects (const Plane &p) const
 Tests whether this box intersects a plane.
 
bool intersects (const Sphere &s) const
 Tests whether this box intersects a sphere.
 
bool intersects (const Vector3 &v) const
 Tests whether the vector point is within this box.
 
bool isFinite (void) const
 Returns true if the box is finite.
 
bool isInfinite (void) const
 Returns true if the box is infinite.
 
bool isNull (void) const
 Returns true if the box is null i.e.
 
void merge (const AxisAlignedBox &rhs)
 Merges the passed in box into the current box.
 
void merge (const Vector3 &point)
 Extends the box to encompass the specified point (if needed).
 
bool operator!= (const AxisAlignedBox &rhs) const
 Tests 2 boxes for inequality.
 
AxisAlignedBoxoperator= (const AxisAlignedBox &rhs)
 
bool operator== (const AxisAlignedBox &rhs) const
 Tests 2 boxes for equality.
 
void scale (const Vector3 &s)
 Scales the AABB by the vector given.
 
void setExtents (const Vector3 &min, const Vector3 &max)
 Sets both minimum and maximum extents at once.
 
void setExtents (Real mx, Real my, Real mz, Real Mx, Real My, Real Mz)
 
void setInfinite ()
 Sets the box to 'infinite'.
 
void setMaximum (const Vector3 &vec)
 Sets the maximum corner of the box.
 
void setMaximum (Real x, Real y, Real z)
 
void setMaximumX (Real x)
 Changes one of the components of the maximum corner of the box used to resize only one dimension of the box.
 
void setMaximumY (Real y)
 
void setMaximumZ (Real z)
 
void setMinimum (const Vector3 &vec)
 Sets the minimum corner of the box.
 
void setMinimum (Real x, Real y, Real z)
 
void setMinimumX (Real x)
 Changes one of the components of the minimum corner of the box used to resize only one dimension of the box.
 
void setMinimumY (Real y)
 
void setMinimumZ (Real z)
 
void setNull ()
 Sets the box to a 'null' value i.e.
 
Real squaredDistance (const Vector3 &v) const
 Returns the squared minimum distance between a given point and any part of the box.
 
void transform (const Matrix4 &matrix)
 Transforms the box according to the matrix supplied.
 
void transformAffine (const Matrix4 &m)
 Transforms the box according to the affine matrix supplied.
 
Real volume (void) const
 Calculate the volume of this box.
 

Static Public Attributes

static const AxisAlignedBox BOX_INFINITE
 
static const AxisAlignedBox BOX_NULL
 

Friends

_OgreExport friend std::ostream & operator<< (std::ostream &o, const AxisAlignedBox &aab)
 

Detailed Description

A 3D box aligned with the x/y/z axes.

Remarks
This class represents a simple box which is aligned with the axes. Internally it only stores 2 points as the extremeties of the box, one which is the minima of all 3 axes, and the other which is the maxima of all 3 axes. This class is typically used for an axis-aligned bounding box (AABB) for collision and visibility determination.

Member Enumeration Documentation

◆ CornerEnum

Enumerator
FAR_LEFT_BOTTOM 
FAR_LEFT_TOP 
FAR_RIGHT_TOP 
FAR_RIGHT_BOTTOM 
NEAR_RIGHT_BOTTOM 
NEAR_LEFT_BOTTOM 
NEAR_LEFT_TOP 
NEAR_RIGHT_TOP 

◆ Extent

Enumerator
EXTENT_NULL 
EXTENT_FINITE 
EXTENT_INFINITE 

Constructor & Destructor Documentation

◆ AxisAlignedBox() [1/5]

Ogre::AxisAlignedBox::AxisAlignedBox ( )
inline

◆ AxisAlignedBox() [2/5]

Ogre::AxisAlignedBox::AxisAlignedBox ( Extent  e)
inline

◆ AxisAlignedBox() [3/5]

Ogre::AxisAlignedBox::AxisAlignedBox ( const AxisAlignedBox rkBox)
inline

◆ AxisAlignedBox() [4/5]

Ogre::AxisAlignedBox::AxisAlignedBox ( const Vector3 min,
const Vector3 max 
)
inline

References Ogre::max(), and Ogre::min().

◆ AxisAlignedBox() [5/5]

Ogre::AxisAlignedBox::AxisAlignedBox ( Real  mx,
Real  my,
Real  mz,
Real  Mx,
Real  My,
Real  Mz 
)
inline

◆ ~AxisAlignedBox()

Ogre::AxisAlignedBox::~AxisAlignedBox ( )
inline

Member Function Documentation

◆ contains() [1/2]

bool Ogre::AxisAlignedBox::contains ( const AxisAlignedBox other) const
inline

Tests whether another box contained by this box.

References isInfinite(), isNull(), Ogre::Vector3::x, Ogre::Vector3::y, and Ogre::Vector3::z.

◆ contains() [2/2]

bool Ogre::AxisAlignedBox::contains ( const Vector3 v) const
inline

Tests whether the given point contained by this box.

References Ogre::Vector3::x, Ogre::Vector3::y, and Ogre::Vector3::z.

◆ distance()

Real Ogre::AxisAlignedBox::distance ( const Vector3 v) const
inline

Returns the minimum distance between a given point and any part of the box.

References Ogre::Math::Sqrt().

◆ getAllCorners()

const Vector3 * Ogre::AxisAlignedBox::getAllCorners ( void  ) const
inline

Returns a pointer to an array of 8 corner points, useful for collision vs.

non-aligned objects.

Remarks
If the order of these corners is important, they are as follows: The 4 points of the minimum Z face (note that because Ogre uses right-handed coordinates, the minimum Z is at the 'back' of the box) starting with the minimum point of all, then anticlockwise around this face (if you are looking onto the face from outside the box). Then the 4 points of the maximum Z face, starting with maximum point of all, then anticlockwise around this face (looking onto the face from outside the box). Like this:
   1-------2
  /|      /|
 / |     / |
5-------4  |
|  0----|--3
| /     | /
|/      |/
6-------7

References Ogre::MEMCATEGORY_SCENE_CONTROL, OGRE_ALLOC_T, Ogre::Vector3::x, Ogre::Vector3::y, and Ogre::Vector3::z.

◆ getCenter()

Vector3 Ogre::AxisAlignedBox::getCenter ( void  ) const
inline

Gets the centre of the box.

References Ogre::Vector3::x, Ogre::Vector3::y, and Ogre::Vector3::z.

◆ getCorner()

Vector3 Ogre::AxisAlignedBox::getCorner ( CornerEnum  cornerToGet) const
inline

Gets the position of one of the corners.

References Ogre::Vector3::x, Ogre::Vector3::y, and Ogre::Vector3::z.

◆ getHalfSize()

Vector3 Ogre::AxisAlignedBox::getHalfSize ( void  ) const
inline

Gets the half-size of the box.

References Ogre::Math::POS_INFINITY, and Ogre::Vector3::ZERO.

◆ getMaximum() [1/2]

Vector3 & Ogre::AxisAlignedBox::getMaximum ( void  )
inline

Gets a modifiable version of the maximum corner of the box.

◆ getMaximum() [2/2]

const Vector3 & Ogre::AxisAlignedBox::getMaximum ( void  ) const
inline

Gets the maximum corner of the box.

◆ getMinimum() [1/2]

Vector3 & Ogre::AxisAlignedBox::getMinimum ( void  )
inline

Gets a modifiable version of the minimum corner of the box.

◆ getMinimum() [2/2]

const Vector3 & Ogre::AxisAlignedBox::getMinimum ( void  ) const
inline

Gets the minimum corner of the box.

◆ getSize()

Vector3 Ogre::AxisAlignedBox::getSize ( void  ) const
inline

Gets the size of the box.

References Ogre::Math::POS_INFINITY, and Ogre::Vector3::ZERO.

◆ intersection()

AxisAlignedBox Ogre::AxisAlignedBox::intersection ( const AxisAlignedBox b2) const
inline

Calculate the area of intersection of this box and another.

◆ intersects() [1/4]

bool Ogre::AxisAlignedBox::intersects ( const AxisAlignedBox b2) const
inline

Returns whether or not this box intersects another.

References Ogre::Vector3::x, Ogre::Vector3::y, and Ogre::Vector3::z.

◆ intersects() [2/4]

bool Ogre::AxisAlignedBox::intersects ( const Plane p) const
inline

Tests whether this box intersects a plane.

References Ogre::Math::intersects().

◆ intersects() [3/4]

bool Ogre::AxisAlignedBox::intersects ( const Sphere s) const
inline

Tests whether this box intersects a sphere.

References Ogre::Math::intersects().

◆ intersects() [4/4]

bool Ogre::AxisAlignedBox::intersects ( const Vector3 v) const
inline

Tests whether the vector point is within this box.

References Ogre::Vector3::x, Ogre::Vector3::y, and Ogre::Vector3::z.

◆ isFinite()

bool Ogre::AxisAlignedBox::isFinite ( void  ) const
inline

Returns true if the box is finite.

◆ isInfinite()

bool Ogre::AxisAlignedBox::isInfinite ( void  ) const
inline

Returns true if the box is infinite.

Referenced by contains().

◆ isNull()

bool Ogre::AxisAlignedBox::isNull ( void  ) const
inline

Returns true if the box is null i.e.

empty.

Referenced by contains().

◆ merge() [1/2]

void Ogre::AxisAlignedBox::merge ( const AxisAlignedBox rhs)
inline

Merges the passed in box into the current box.

The result is the box which encompasses both.

References Ogre::max(), and Ogre::min().

◆ merge() [2/2]

void Ogre::AxisAlignedBox::merge ( const Vector3 point)
inline

Extends the box to encompass the specified point (if needed).

References Ogre::Vector3::makeCeil(), and Ogre::Vector3::makeFloor().

◆ operator!=()

bool Ogre::AxisAlignedBox::operator!= ( const AxisAlignedBox rhs) const
inline

Tests 2 boxes for inequality.

◆ operator=()

AxisAlignedBox & Ogre::AxisAlignedBox::operator= ( const AxisAlignedBox rhs)
inline

◆ operator==()

bool Ogre::AxisAlignedBox::operator== ( const AxisAlignedBox rhs) const
inline

Tests 2 boxes for equality.

◆ scale()

void Ogre::AxisAlignedBox::scale ( const Vector3 s)
inline

Scales the AABB by the vector given.

References Ogre::max(), and Ogre::min().

◆ setExtents() [1/2]

void Ogre::AxisAlignedBox::setExtents ( const Vector3 min,
const Vector3 max 
)
inline

Sets both minimum and maximum extents at once.

References Ogre::max(), and Ogre::min().

◆ setExtents() [2/2]

void Ogre::AxisAlignedBox::setExtents ( Real  mx,
Real  my,
Real  mz,
Real  Mx,
Real  My,
Real  Mz 
)
inline

◆ setInfinite()

void Ogre::AxisAlignedBox::setInfinite ( )
inline

Sets the box to 'infinite'.

◆ setMaximum() [1/2]

void Ogre::AxisAlignedBox::setMaximum ( const Vector3 vec)
inline

Sets the maximum corner of the box.

◆ setMaximum() [2/2]

void Ogre::AxisAlignedBox::setMaximum ( Real  x,
Real  y,
Real  z 
)
inline

◆ setMaximumX()

void Ogre::AxisAlignedBox::setMaximumX ( Real  x)
inline

Changes one of the components of the maximum corner of the box used to resize only one dimension of the box.

References Ogre::Vector3::x.

◆ setMaximumY()

void Ogre::AxisAlignedBox::setMaximumY ( Real  y)
inline

References Ogre::Vector3::y.

◆ setMaximumZ()

void Ogre::AxisAlignedBox::setMaximumZ ( Real  z)
inline

References Ogre::Vector3::z.

◆ setMinimum() [1/2]

void Ogre::AxisAlignedBox::setMinimum ( const Vector3 vec)
inline

Sets the minimum corner of the box.

◆ setMinimum() [2/2]

void Ogre::AxisAlignedBox::setMinimum ( Real  x,
Real  y,
Real  z 
)
inline

◆ setMinimumX()

void Ogre::AxisAlignedBox::setMinimumX ( Real  x)
inline

Changes one of the components of the minimum corner of the box used to resize only one dimension of the box.

References Ogre::Vector3::x.

◆ setMinimumY()

void Ogre::AxisAlignedBox::setMinimumY ( Real  y)
inline

References Ogre::Vector3::y.

◆ setMinimumZ()

void Ogre::AxisAlignedBox::setMinimumZ ( Real  z)
inline

References Ogre::Vector3::z.

◆ setNull()

void Ogre::AxisAlignedBox::setNull ( )
inline

Sets the box to a 'null' value i.e.

not a box.

◆ squaredDistance()

Real Ogre::AxisAlignedBox::squaredDistance ( const Vector3 v) const
inline

Returns the squared minimum distance between a given point and any part of the box.

This is faster than distance since avoiding a squareroot, so use if you can.

References Ogre::Vector3::x, Ogre::Vector3::y, and Ogre::Vector3::z.

◆ transform()

void Ogre::AxisAlignedBox::transform ( const Matrix4 matrix)
inline

Transforms the box according to the matrix supplied.

Remarks
By calling this method you get the axis-aligned box which surrounds the transformed version of this box. Therefore each corner of the box is transformed by the matrix, then the extents are mapped back onto the axes to produce another AABB. Useful when you have a local AABB for an object which is then transformed.

◆ transformAffine()

void Ogre::AxisAlignedBox::transformAffine ( const Matrix4 m)
inline

Transforms the box according to the affine matrix supplied.

Remarks
By calling this method you get the axis-aligned box which surrounds the transformed version of this box. Therefore each corner of the box is transformed by the matrix, then the extents are mapped back onto the axes to produce another AABB. Useful when you have a local AABB for an object which is then transformed.
Note
The matrix must be an affine matrix.
See also
Matrix4::isAffine.

References Ogre::Math::Abs(), Ogre::Matrix4::isAffine(), and Ogre::Matrix4::transformAffine().

◆ volume()

Real Ogre::AxisAlignedBox::volume ( void  ) const
inline

Calculate the volume of this box.

References Ogre::Math::POS_INFINITY.

Friends And Related Symbol Documentation

◆ operator<<

_OgreExport friend std::ostream & operator<< ( std::ostream &  o,
const AxisAlignedBox aab 
)
friend

Member Data Documentation

◆ BOX_INFINITE

const AxisAlignedBox Ogre::AxisAlignedBox::BOX_INFINITE
static

◆ BOX_NULL

const AxisAlignedBox Ogre::AxisAlignedBox::BOX_NULL
static

The documentation for this class was generated from the following file: