Ogre::AxisAlignedBox Class Reference
Core » Math

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

## Static Public Attributes

static const AxisAlignedBox | BOX_INFINITE
static const AxisAlignedBox | BOX_NULL

## Protected Attributes

Vector3 * | mCorners
Extent | mExtent
Vector3 | mMaximum
Vector3 | mMinimum

## 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.

Definition at line 54 of file OgreAxisAlignedBox.h.

## Member Enumeration Documentation

## CornerEnum

enum Ogre::AxisAlignedBox::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 |

Definition at line 81 of file OgreAxisAlignedBox.h.

## Extent

enum Ogre::AxisAlignedBox::Extent

Enumerator
EXTENT_NULL |
EXTENT_FINITE |
EXTENT_INFINITE |

Definition at line 57 of file OgreAxisAlignedBox.h.

## Constructor & Destructor Documentation

## AxisAlignedBox() [1/5]

Ogre::AxisAlignedBox::AxisAlignedBox | ( |  | ) |

Definition at line 91 of file OgreAxisAlignedBox.h.

## AxisAlignedBox() [2/5]

Ogre::AxisAlignedBox::AxisAlignedBox | ( | Extent | e | ) |

Definition at line 98 of file OgreAxisAlignedBox.h.

## AxisAlignedBox() [3/5]

Ogre::AxisAlignedBox::AxisAlignedBox | ( | const AxisAlignedBox & | rkBox | ) |

Definition at line 105 of file OgreAxisAlignedBox.h.

References isInfinite(), isNull(), mMaximum, and mMinimum.

## AxisAlignedBox() [4/5]

Ogre::AxisAlignedBox::AxisAlignedBox | ( | const Vector3 & | min,
|  | const Vector3 & | max
| ) |  |

Definition at line 116 of file OgreAxisAlignedBox.h.

## AxisAlignedBox() [5/5]

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

Definition at line 121 of file OgreAxisAlignedBox.h.

## ~AxisAlignedBox()

Ogre::AxisAlignedBox::~AxisAlignedBox | ( |  | ) |

Definition at line 141 of file OgreAxisAlignedBox.h.

References Ogre::MEMCATEGORY_SCENE_CONTROL, and OGRE_FREE.

## Member Function Documentation

## contains() [1/2]

bool Ogre::AxisAlignedBox::contains | ( | const Vector3 & | v | ) | const

Tests whether the given point contained by this box.

Definition at line 750 of file OgreAxisAlignedBox.h.

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

## contains() [2/2]

bool Ogre::AxisAlignedBox::contains | ( | const AxisAlignedBox & | other | ) | const

Tests whether another box contained by this box.

Definition at line 800 of file OgreAxisAlignedBox.h.

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

## distance()

Real Ogre::AxisAlignedBox::distance | ( | const Vector3 & | v | ) | const

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

Definition at line 793 of file OgreAxisAlignedBox.h.

References Ogre::Math::Sqrt().

Referenced by Ogre::Volume::CSGCubeSource::distanceTo().

## getAllCorners()

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

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

Definition at line 301 of file OgreAxisAlignedBox.h.

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

Gets the centre of the box.

Definition at line 694 of file OgreAxisAlignedBox.h.

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

Referenced by Ogre::PlaneBoundedVolume::intersects().

## getCorner()

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

Gets the position of one of the corners.

Definition at line 329 of file OgreAxisAlignedBox.h.

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

## getHalfSize()

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

Gets the half-size of the box.

Definition at line 726 of file OgreAxisAlignedBox.h.

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

Referenced by Ogre::PlaneBoundedVolume::intersects().

## getMaximum() [1/2]

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

Gets the maximum corner of the box.

Definition at line 165 of file OgreAxisAlignedBox.h.

Referenced by Ogre::Volume::MeshBuilder::addVertex(), Ogre::Volume::CSGCubeSource::distanceTo(), and intersection().

## getMaximum() [2/2]

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

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

Definition at line 173 of file OgreAxisAlignedBox.h.

## getMinimum() [1/2]

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

Gets the minimum corner of the box.

Definition at line 150 of file OgreAxisAlignedBox.h.

Referenced by Ogre::Volume::MeshBuilder::addVertex(), Ogre::Volume::CSGCubeSource::distanceTo(), and intersection().

## getMinimum() [2/2]

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

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

Definition at line 158 of file OgreAxisAlignedBox.h.

## getSize()

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

Gets the size of the box.

Definition at line 704 of file OgreAxisAlignedBox.h.

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

## intersection()

AxisAlignedBox Ogre::AxisAlignedBox::intersection | ( | const AxisAlignedBox & | b2 | ) | const

Calculate the area of intersection of this box and another.

Definition at line 594 of file OgreAxisAlignedBox.h.

References getMaximum(), getMinimum(), isInfinite(), isNull(), Ogre::Vector3::makeCeil(), Ogre::Vector3::makeFloor(), Ogre::Vector3::x, Ogre::Vector3::y, and Ogre::Vector3::z.

## intersects() [1/4]

bool Ogre::AxisAlignedBox::intersects | ( | const AxisAlignedBox & | b2 | ) | const

Returns whether or not this box intersects another.

Definition at line 563 of file OgreAxisAlignedBox.h.

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

## intersects() [2/4]

bool Ogre::AxisAlignedBox::intersects | ( | const Sphere & | s | ) | const

Tests whether this box intersects a sphere.

Definition at line 663 of file OgreAxisAlignedBox.h.

References Ogre::Math::intersects().

## intersects() [3/4]

bool Ogre::AxisAlignedBox::intersects | ( | const Plane & | p | ) | const

Tests whether this box intersects a plane.

Definition at line 668 of file OgreAxisAlignedBox.h.

References Ogre::Math::intersects().

## intersects() [4/4]

bool Ogre::AxisAlignedBox::intersects | ( | const Vector3 & | v | ) | const

Tests whether the vector point is within this box.

Definition at line 673 of file OgreAxisAlignedBox.h.

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

## isFinite()

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

Returns true if the box is finite.

Definition at line 543 of file OgreAxisAlignedBox.h.

## isInfinite()

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

Returns true if the box is infinite.

Definition at line 557 of file OgreAxisAlignedBox.h.

Referenced by AxisAlignedBox(), contains(), intersection(), Ogre::PlaneBoundedVolume::intersects(), intersects(), and operator=().

## isNull()

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

Returns true if the box is null i.e.

empty.

Definition at line 536 of file OgreAxisAlignedBox.h.

Referenced by AxisAlignedBox(), contains(), intersection(), Ogre::PlaneBoundedVolume::intersects(), intersects(), and operator=().

## merge() [1/2]

void Ogre::AxisAlignedBox::merge | ( | const AxisAlignedBox & | rhs | ) |

Merges the passed in box into the current box.

The result is the box which encompasses both.

Definition at line 379 of file OgreAxisAlignedBox.h.

References Ogre::Vector3::makeCeil(), Ogre::Vector3::makeFloor(), mExtent, mMaximum, and mMinimum.

## merge() [2/2]

void Ogre::AxisAlignedBox::merge | ( | const Vector3 & | point | ) |

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

Definition at line 411 of file OgreAxisAlignedBox.h.

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

## operator!=()

bool Ogre::AxisAlignedBox::operator!= | ( | const AxisAlignedBox & | rhs | ) | const

Tests 2 boxes for inequality.

Definition at line 832 of file OgreAxisAlignedBox.h.

## operator=()

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

Definition at line 128 of file OgreAxisAlignedBox.h.

References isInfinite(), isNull(), mMaximum, and mMinimum.

## operator==()

bool Ogre::AxisAlignedBox::operator== | ( | const AxisAlignedBox & | rhs | ) | const

Tests 2 boxes for equality.

Definition at line 818 of file OgreAxisAlignedBox.h.

References mExtent, mMaximum, and mMinimum.

## scale()

void Ogre::AxisAlignedBox::scale | ( | const Vector3 & | s | ) |

Scales the AABB by the vector given.

Definition at line 650 of file OgreAxisAlignedBox.h.

## setExtents() [1/2]

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

Sets both minimum and maximum extents at once.

Definition at line 249 of file OgreAxisAlignedBox.h.

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

Referenced by Ogre::Volume::MeshBuilder::addVertex().

## setExtents() [2/2]

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

Definition at line 259 of file OgreAxisAlignedBox.h.

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

## setInfinite()

void Ogre::AxisAlignedBox::setInfinite | ( |  | ) |

Sets the box to 'infinite'.

Definition at line 550 of file OgreAxisAlignedBox.h.

## setMaximum() [1/2]

void Ogre::AxisAlignedBox::setMaximum | ( | const Vector3 & | vec | ) |

Sets the maximum corner of the box.

Definition at line 215 of file OgreAxisAlignedBox.h.

## setMaximum() [2/2]

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

Definition at line 221 of file OgreAxisAlignedBox.h.

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

## setMaximumX()

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

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

Definition at line 232 of file OgreAxisAlignedBox.h.

References Ogre::Vector3::x.

Referenced by Ogre::Volume::MeshBuilder::addVertex().

## setMaximumY()

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

Definition at line 237 of file OgreAxisAlignedBox.h.

References Ogre::Vector3::y.

Referenced by Ogre::Volume::MeshBuilder::addVertex().

## setMaximumZ()

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

Definition at line 242 of file OgreAxisAlignedBox.h.

References Ogre::Vector3::z.

Referenced by Ogre::Volume::MeshBuilder::addVertex().

## setMinimum() [1/2]

void Ogre::AxisAlignedBox::setMinimum | ( | const Vector3 & | vec | ) |

Sets the minimum corner of the box.

Definition at line 181 of file OgreAxisAlignedBox.h.

## setMinimum() [2/2]

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

Definition at line 187 of file OgreAxisAlignedBox.h.

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

## setMinimumX()

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

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

Definition at line 198 of file OgreAxisAlignedBox.h.

References Ogre::Vector3::x.

Referenced by Ogre::Volume::MeshBuilder::addVertex().

## setMinimumY()

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

Definition at line 203 of file OgreAxisAlignedBox.h.

References Ogre::Vector3::y.

Referenced by Ogre::Volume::MeshBuilder::addVertex().

## setMinimumZ()

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

Definition at line 208 of file OgreAxisAlignedBox.h.

References Ogre::Vector3::z.

Referenced by Ogre::Volume::MeshBuilder::addVertex().

## setNull()

void Ogre::AxisAlignedBox::setNull | ( |  | ) |

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

not a box.

Definition at line 529 of file OgreAxisAlignedBox.h.

## squaredDistance()

Real Ogre::AxisAlignedBox::squaredDistance | ( | const Vector3 & | v | ) | const

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.

Definition at line 764 of file OgreAxisAlignedBox.h.

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

## transform()

void Ogre::AxisAlignedBox::transform | ( | const Matrix4 & | matrix | ) |

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.

Definition at line 440 of file OgreAxisAlignedBox.h.

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

## transformAffine()

void Ogre::AxisAlignedBox::transformAffine | ( | const Matrix4 & | m | ) |

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.

Definition at line 507 of file OgreAxisAlignedBox.h.

References Ogre::Math::Abs(), Ogre::Matrix4::isAffine(), Ogre::Matrix4::transformAffine(), Ogre::Vector3::x, Ogre::Vector3::y, and Ogre::Vector3::z.

## volume()

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

Calculate the volume of this box.

Definition at line 627 of file OgreAxisAlignedBox.h.

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

## Friends And Related Function Documentation

## operator<<

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

friend

Definition at line 354 of file OgreAxisAlignedBox.h.

## Member Data Documentation

## BOX_INFINITE

const AxisAlignedBox Ogre::AxisAlignedBox::BOX_INFINITE

static

Definition at line 839 of file OgreAxisAlignedBox.h.

## BOX_NULL

const AxisAlignedBox Ogre::AxisAlignedBox::BOX_NULL

static

Definition at line 838 of file OgreAxisAlignedBox.h.

## mCorners

Vector3* Ogre::AxisAlignedBox::mCorners

mutable protected

Definition at line 68 of file OgreAxisAlignedBox.h.

## mExtent

Extent Ogre::AxisAlignedBox::mExtent

protected

Definition at line 67 of file OgreAxisAlignedBox.h.

Referenced by merge(), and operator==().

## mMaximum

Vector3 Ogre::AxisAlignedBox::mMaximum

protected

Definition at line 66 of file OgreAxisAlignedBox.h.

Referenced by AxisAlignedBox(), contains(), intersects(), merge(), operator=(), and operator==().

## mMinimum

Vector3 Ogre::AxisAlignedBox::mMinimum

protected

Definition at line 65 of file OgreAxisAlignedBox.h.

Referenced by AxisAlignedBox(), contains(), intersects(), merge(), operator=(), and operator==().

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

- OgreAxisAlignedBox.h

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.