28#ifndef __AxisAlignedBox_H_
29#define __AxisAlignedBox_H_
86 NEAR_RIGHT_BOTTOM = 7,
94 setMinimum( -0.5, -0.5, -0.5 );
95 setMaximum( 0.5, 0.5, 0.5 );
96 mExtent = EXTENT_NULL;
100 setMinimum( -0.5, -0.5, -0.5 );
101 setMaximum( 0.5, 0.5, 0.5 );
118 setExtents( min, max );
125 setExtents( mx, my, mz, Mx, My, Mz );
183 mExtent = EXTENT_FINITE;
189 mExtent = EXTENT_FINITE;
217 mExtent = EXTENT_FINITE;
223 mExtent = EXTENT_FINITE;
251 assert( (min.
x <= max.
x && min.
y <= max.
y && min.
z <= max.
z) &&
252 "The minimum corner of the box must be less than or equal to maximum corner" );
254 mExtent = EXTENT_FINITE;
263 assert( (mx <= Mx && my <= My && mz <= Mz) &&
264 "The minimum corner of the box must be less than or equal to maximum corner" );
266 mExtent = EXTENT_FINITE;
303 assert( (mExtent == EXTENT_FINITE) &&
"Can't get corners of a null or infinite AAB" );
314 mCorners[0] = mMinimum;
315 mCorners[1].
x = mMinimum.
x; mCorners[1].
y = mMaximum.
y; mCorners[1].
z = mMinimum.
z;
316 mCorners[2].
x = mMaximum.
x; mCorners[2].
y = mMaximum.
y; mCorners[2].
z = mMinimum.
z;
317 mCorners[3].
x = mMaximum.
x; mCorners[3].
y = mMinimum.
y; mCorners[3].
z = mMinimum.
z;
319 mCorners[4] = mMaximum;
320 mCorners[5].
x = mMinimum.
x; mCorners[5].
y = mMaximum.
y; mCorners[5].
z = mMaximum.
z;
321 mCorners[6].
x = mMinimum.
x; mCorners[6].
y = mMinimum.
y; mCorners[6].
z = mMaximum.
z;
322 mCorners[7].
x = mMaximum.
x; mCorners[7].
y = mMinimum.
y; mCorners[7].
z = mMaximum.
z;
333 case FAR_LEFT_BOTTOM:
336 return Vector3(mMinimum.
x, mMaximum.
y, mMinimum.
z);
338 return Vector3(mMaximum.
x, mMaximum.
y, mMinimum.
z);
339 case FAR_RIGHT_BOTTOM:
340 return Vector3(mMaximum.
x, mMinimum.
y, mMinimum.
z);
341 case NEAR_RIGHT_BOTTOM:
342 return Vector3(mMaximum.
x, mMinimum.
y, mMaximum.
z);
343 case NEAR_LEFT_BOTTOM:
344 return Vector3(mMinimum.
x, mMinimum.
y, mMaximum.
z);
346 return Vector3(mMinimum.
x, mMaximum.
y, mMaximum.
z);
359 o <<
"AxisAlignedBox(null)";
363 o <<
"AxisAlignedBox(min=" << aab.
mMinimum <<
", max=" << aab.
mMaximum <<
")";
366 case EXTENT_INFINITE:
367 o <<
"AxisAlignedBox(infinite)";
371 assert(
false &&
"Never reached" );
382 if ((rhs.
mExtent == EXTENT_NULL) || (mExtent == EXTENT_INFINITE))
387 else if (rhs.
mExtent == EXTENT_INFINITE)
389 mExtent = EXTENT_INFINITE;
392 else if (mExtent == EXTENT_NULL)
404 setExtents(min, max);
416 setExtents(point, point);
424 case EXTENT_INFINITE:
428 assert(
false &&
"Never reached" );
443 if( mExtent != EXTENT_FINITE )
446 Vector3 oldMin, oldMax, currentCorner;
464 currentCorner = oldMin;
465 merge( matrix * currentCorner );
468 currentCorner.
z = oldMax.
z;
469 merge( matrix * currentCorner );
472 currentCorner.
y = oldMax.
y;
473 merge( matrix * currentCorner );
476 currentCorner.
z = oldMin.
z;
477 merge( matrix * currentCorner );
480 currentCorner.
x = oldMax.
x;
481 merge( matrix * currentCorner );
484 currentCorner.
z = oldMax.
z;
485 merge( matrix * currentCorner );
488 currentCorner.
y = oldMin.
y;
489 merge( matrix * currentCorner );
492 currentCorner.
z = oldMin.
z;
493 merge( matrix * currentCorner );
512 if ( mExtent != EXTENT_FINITE )
516 Vector3 halfSize = getHalfSize();
520 Math::Abs(m[0][0]) * halfSize.
x + Math::Abs(m[0][1]) * halfSize.
y + Math::Abs(m[0][2]) * halfSize.
z,
521 Math::Abs(m[1][0]) * halfSize.
x + Math::Abs(m[1][1]) * halfSize.
y + Math::Abs(m[1][2]) * halfSize.
z,
522 Math::Abs(m[2][0]) * halfSize.
x + Math::Abs(m[2][1]) * halfSize.
y + Math::Abs(m[2][2]) * halfSize.
z);
524 setExtents(newCentre - newHalfSize, newCentre + newHalfSize);
531 mExtent = EXTENT_NULL;
538 return (mExtent == EXTENT_NULL);
545 return (mExtent == EXTENT_FINITE);
552 mExtent = EXTENT_INFINITE;
559 return (mExtent == EXTENT_INFINITE);
566 if (this->isNull() || b2.
isNull())
596 if (this->isNull() || b2.
isNull())
600 else if (this->isInfinite())
616 if (intMin.
x < intMax.
x &&
617 intMin.
y < intMax.
y &&
636 Vector3 diff = mMaximum - mMinimum;
637 return diff.
x * diff.
y * diff.
z;
640 case EXTENT_INFINITE:
641 return Math::POS_INFINITY;
644 assert(
false &&
"Never reached" );
653 if (mExtent != EXTENT_FINITE)
659 setExtents(min, max);
665 return Math::intersects(s, *
this);
670 return Math::intersects(p, *
this);
681 return(v.
x >= mMinimum.
x && v.
x <= mMaximum.
x &&
682 v.
y >= mMinimum.
y && v.
y <= mMaximum.
y &&
683 v.
z >= mMinimum.
z && v.
z <= mMaximum.
z);
685 case EXTENT_INFINITE:
689 assert(
false &&
"Never reached" );
696 assert( (mExtent == EXTENT_FINITE) &&
"Can't get center of a null or infinite AAB" );
699 (mMaximum.
x + mMinimum.
x) * 0.5f,
700 (mMaximum.
y + mMinimum.
y) * 0.5f,
701 (mMaximum.
z + mMinimum.
z) * 0.5f);
709 return Vector3::ZERO;
712 return mMaximum - mMinimum;
714 case EXTENT_INFINITE:
721 assert(
false &&
"Never reached" );
722 return Vector3::ZERO;
731 return Vector3::ZERO;
734 return (mMaximum - mMinimum) * 0.5;
736 case EXTENT_INFINITE:
743 assert(
false &&
"Never reached" );
744 return Vector3::ZERO;
757 return mMinimum.
x <= v.
x && v.
x <= mMaximum.
x &&
758 mMinimum.
y <= v.
y && v.
y <= mMaximum.
y &&
759 mMinimum.
z <= v.
z && v.
z <= mMaximum.
z;
767 if (this->contains(v))
773 if (v.
x < mMinimum.
x)
774 maxDist.
x = mMinimum.
x - v.
x;
775 else if (v.
x > mMaximum.
x)
776 maxDist.
x = v.
x - mMaximum.
x;
778 if (v.
y < mMinimum.
y)
779 maxDist.
y = mMinimum.
y - v.
y;
780 else if (v.
y > mMaximum.
y)
781 maxDist.
y = v.
y - mMaximum.
y;
783 if (v.
z < mMinimum.
z)
784 maxDist.
z = mMinimum.
z - v.
z;
785 else if (v.
z > mMaximum.
z)
786 maxDist.
z = v.
z - mMaximum.
z;
802 if (other.
isNull() || this->isInfinite())
808 return this->mMinimum.
x <= other.
mMinimum.
x &&
820 if (this->mExtent != rhs.
mExtent)
823 if (!this->isFinite())
826 return this->mMinimum == rhs.
mMinimum &&
834 return !(*
this == rhs);
A 3D box aligned with the x/y/z axes.
bool intersects(const Vector3 &v) const
Tests whether the vector point is within this box.
void transformAffine(const Matrix4 &m)
Transforms the box according to the affine matrix supplied.
void setInfinite()
Sets the box to 'infinite'.
Vector3 & getMaximum(void)
Gets a modifiable version of the maximum corner of the box.
void setMaximumX(Real x)
Changes one of the components of the maximum corner of the box used to resize only one dimension of t...
bool isNull(void) const
Returns true if the box is null i.e.
void setExtents(Real mx, Real my, Real mz, Real Mx, Real My, Real Mz)
AxisAlignedBox & operator=(const AxisAlignedBox &rhs)
void setMinimumX(Real x)
Changes one of the components of the minimum corner of the box used to resize only one dimension of t...
AxisAlignedBox(const Vector3 &min, const Vector3 &max)
AxisAlignedBox(const AxisAlignedBox &rkBox)
Vector3 & getMinimum(void)
Gets a modifiable version of the minimum corner of the box.
static const AxisAlignedBox BOX_NULL
Real volume(void) const
Calculate the volume of this box.
void merge(const AxisAlignedBox &rhs)
Merges the passed in box into the current box.
bool intersects(const Sphere &s) const
Tests whether this box intersects a sphere.
void setExtents(const Vector3 &min, const Vector3 &max)
Sets both minimum and maximum extents at once.
Real squaredDistance(const Vector3 &v) const
Returns the squared minimum distance between a given point and any part of the box.
Vector3 getHalfSize(void) const
Gets the half-size of the box.
void setMaximum(const Vector3 &vec)
Sets the maximum corner of the box.
Vector3 getCenter(void) const
Gets the centre of the box.
const Vector3 & getMaximum(void) const
Gets the maximum corner of the box.
bool intersects(const AxisAlignedBox &b2) const
Returns whether or not this box intersects another.
Real distance(const Vector3 &v) const
Returns the minimum distance between a given point and any part of the box.
void setNull()
Sets the box to a 'null' value i.e.
AxisAlignedBox intersection(const AxisAlignedBox &b2) const
Calculate the area of intersection of this box and another.
const Vector3 * getAllCorners(void) const
Returns a pointer to an array of 8 corner points, useful for collision vs.
bool isInfinite(void) const
Returns true if the box is infinite.
const Vector3 & getMinimum(void) const
Gets the minimum corner of the box.
AxisAlignedBox(Real mx, Real my, Real mz, Real Mx, Real My, Real Mz)
bool intersects(const Plane &p) const
Tests whether this box intersects a plane.
void setMinimum(const Vector3 &vec)
Sets the minimum corner of the box.
static const AxisAlignedBox BOX_INFINITE
void scale(const Vector3 &s)
Scales the AABB by the vector given.
bool isFinite(void) const
Returns true if the box is finite.
bool contains(const Vector3 &v) const
Tests whether the given point contained by this box.
void transform(const Matrix4 &matrix)
Transforms the box according to the matrix supplied.
void setMaximum(Real x, Real y, Real z)
Vector3 getCorner(CornerEnum cornerToGet) const
Gets the position of one of the corners.
void setMinimum(Real x, Real y, Real z)
bool contains(const AxisAlignedBox &other) const
Tests whether another box contained by this box.
void merge(const Vector3 &point)
Extends the box to encompass the specified point (if needed).
Vector3 getSize(void) const
Gets the size of the box.
_OgreExport friend std::ostream & operator<<(std::ostream &o, const AxisAlignedBox &aab)
static Real Sqrt(Real fValue)
Square root function.
Class encapsulating a standard 4x4 homogeneous matrix.
bool isAffine(void) const
Check whether or not the matrix is affine matrix.
Vector3 transformAffine(const Vector3 &v) const
3-D Vector transformation specially for an affine matrix.
Defines a plane in 3D space.
A sphere primitive, mostly used for bounds checking.
Standard 3-dimensional vector.
Real squaredLength() const
Returns the square of the length(magnitude) of the vector.
void makeCeil(const Vector3 &cmp)
Sets this vector's components to the maximum of its own and the ones of the passed in vector.
void makeFloor(const Vector3 &cmp)
Sets this vector's components to the minimum of its own and the ones of the passed in vector.
#define OGRE_ALLOC_T(T, count, category)
Allocate a block of memory for a primitive type, and indicate the category of usage.
#define OGRE_FREE(ptr, category)
Free the memory allocated with OGRE_MALLOC or OGRE_ALLOC_T. Category is required to be restated to en...
@ MEMCATEGORY_SCENE_CONTROL
Nodes, control data.
float Real
Software floating point type.