My Project
Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
ParaEngine::AxisAlignedBox Class Reference

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

#include <ParaAxisAlignedBox.h>

Public Types

enum  Extent { EXTENT_NULL, EXTENT_FINITE, EXTENT_INFINITE }
 
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
}
 

Public Member Functions

 AxisAlignedBox (Extent e)
 
 AxisAlignedBox (const AxisAlignedBox &rkBox)
 
 AxisAlignedBox (const Vector3 &min, const Vector3 &max)
 
 AxisAlignedBox (float mx, float my, float mz, float Mx, float My, float Mz)
 
AxisAlignedBoxoperator= (const AxisAlignedBox &rhs)
 
const Vector3getMinimum (void) const
 Gets the minimum corner of the box.
 
Vector3getMinimum (void)
 Gets a modifiable version of the minimum corner of the box.
 
const Vector3getMaximum (void) const
 Gets the maximum corner of the box.
 
Vector3getMaximum (void)
 Gets a modifiable version of the maximum corner of the box.
 
void setMinimum (const Vector3 &vec)
 Sets the minimum corner of the box.
 
void setMinimum (float x, float y, float z)
 
void setMinimumX (float x)
 Changes one of the components of the minimum corner of the box used to resize only one dimension of the box.
 
void setMinimumY (float y)
 
void setMinimumZ (float z)
 
void setMaximum (const Vector3 &vec)
 Sets the maximum corner of the box.
 
void setMaximum (float x, float y, float z)
 
void setMaximumX (float x)
 Changes one of the components of the maximum corner of the box used to resize only one dimension of the box.
 
void setMaximumY (float y)
 
void setMaximumZ (float z)
 
void setExtents (const Vector3 &min, const Vector3 &max)
 Sets both minimum and maximum extents at once.
 
void setExtents (float mx, float my, float mz, float Mx, float My, float Mz)
 
const Vector3getAllCorners (void) const
 Returns a pointer to an array of 8 corner points, useful for collision vs. More...
 
Vector3 getCorner (CornerEnum cornerToGet) const
 gets the position of one of the corners
 
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).
 
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...
 
void setNull ()
 Sets the box to a 'null' value i.e. More...
 
bool isNull (void) const
 Returns true if the box is null i.e. More...
 
bool isFinite (void) const
 Returns true if the box is finite.
 
void setInfinite ()
 Sets the box to 'infinite'.
 
bool isInfinite (void) const
 Returns true if the box is infinite.
 
bool intersects (const AxisAlignedBox &b2) const
 Returns whether or not this box intersects another. More...
 
AxisAlignedBox intersection (const AxisAlignedBox &b2) const
 Calculate the area of intersection of this box and another.
 
float volume (void) const
 Calculate the volume of this box.
 
void scale (const Vector3 &s)
 Scales the AABB by the vector given. 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...
 
Vector3 getCenter (void) const
 Gets the centre of the box.
 
Vector3 getSize (void) const
 Gets the size of the box.
 
Vector3 getHalfSize (void) const
 Gets the half-size of the box.
 
bool contains (const Vector3 &v) const
 Tests whether the given point contained by this box.
 
bool contains (const AxisAlignedBox &other) const
 Tests whether another box contained by this box.
 
bool operator== (const AxisAlignedBox &rhs) const
 Tests 2 boxes for equality.
 
bool operator!= (const AxisAlignedBox &rhs) const
 Tests 2 boxes for inequality.
 

Static Public Attributes

static const AxisAlignedBox BOX_NULL
 
static const AxisAlignedBox BOX_INFINITE
 

Protected Attributes

Vector3 mMinimum
 
Vector3 mMaximum
 
Extent mExtent
 
Vector3mpCorners
 

Friends

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 Function Documentation

§ getAllCorners()

const Vector3 * ParaEngine::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
as this implementation uses a static member, make sure to use your own copy !

§ intersects() [1/4]

bool ParaEngine::AxisAlignedBox::intersects ( const AxisAlignedBox b2) const

Returns whether or not this box intersects another.

§ intersects() [2/4]

bool ParaEngine::AxisAlignedBox::intersects ( const Sphere s) const

Tests whether this box intersects a sphere.

§ intersects() [3/4]

bool ParaEngine::AxisAlignedBox::intersects ( const Plane p) const

Tests whether this box intersects a plane.

§ intersects() [4/4]

bool ParaEngine::AxisAlignedBox::intersects ( const Vector3 v) const

Tests whether the vector point is within this box.

§ isNull()

bool ParaEngine::AxisAlignedBox::isNull ( void  ) const

Returns true if the box is null i.e.

empty.

§ merge()

void ParaEngine::AxisAlignedBox::merge ( const AxisAlignedBox rhs)

Merges the passed in box into the current box.

The result is the box which encompasses both.

§ scale()

void ParaEngine::AxisAlignedBox::scale ( const Vector3 s)

Scales the AABB by the vector given.

§ setNull()

void ParaEngine::AxisAlignedBox::setNull ( )

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

not a box.

§ transform()

void ParaEngine::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.

§ transformAffine()

void ParaEngine::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.

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