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;
304 assert( (mExtent == EXTENT_FINITE) &&
"Can't get corners of a null or infinite AAB" );
315 mpCorners[0] = mMinimum;
316 mpCorners[1].x = mMinimum.x; mpCorners[1].y = mMaximum.y; mpCorners[1].z = mMinimum.z;
317 mpCorners[2].x = mMaximum.x; mpCorners[2].y = mMaximum.y; mpCorners[2].z = mMinimum.z;
318 mpCorners[3].x = mMaximum.x; mpCorners[3].y = mMinimum.y; mpCorners[3].z = mMinimum.z;
320 mpCorners[4] = mMaximum;
321 mpCorners[5].x = mMinimum.x; mpCorners[5].y = mMaximum.y; mpCorners[5].z = mMaximum.z;
322 mpCorners[6].x = mMinimum.x; mpCorners[6].y = mMinimum.y; mpCorners[6].z = mMaximum.z;
323 mpCorners[7].x = mMaximum.x; mpCorners[7].y = mMinimum.y; mpCorners[7].z = mMaximum.z;
334 case FAR_LEFT_BOTTOM:
337 return Vector3(mMinimum.x, mMaximum.y, mMinimum.z);
339 return Vector3(mMaximum.x, mMaximum.y, mMinimum.z);
340 case FAR_RIGHT_BOTTOM:
341 return Vector3(mMaximum.x, mMinimum.y, mMinimum.z);
342 case NEAR_RIGHT_BOTTOM:
343 return Vector3(mMaximum.x, mMinimum.y, mMaximum.z);
344 case NEAR_LEFT_BOTTOM:
345 return Vector3(mMinimum.x, mMinimum.y, mMaximum.z);
347 return Vector3(mMinimum.x, mMaximum.y, mMaximum.z);
360 o <<
"AxisAlignedBox(null)";
364 o <<
"AxisAlignedBox(min=" << aab.
mMinimum <<
", max=" << aab.
mMaximum <<
")";
367 case EXTENT_INFINITE:
368 o <<
"AxisAlignedBox(infinite)";
372 assert(
false &&
"Never reached" );
383 if ((rhs.
mExtent == EXTENT_NULL) || (mExtent == EXTENT_INFINITE))
388 else if (rhs.
mExtent == EXTENT_INFINITE)
390 mExtent = EXTENT_INFINITE;
393 else if (mExtent == EXTENT_NULL)
405 setExtents(min, max);
417 setExtents(point, point);
421 mMaximum.makeCeil(point);
422 mMinimum.makeFloor(point);
425 case EXTENT_INFINITE:
429 assert(
false &&
"Never reached" );
444 if( mExtent != EXTENT_FINITE )
447 Vector3 oldMin, oldMax, currentCorner;
465 currentCorner = oldMin;
466 merge( matrix * currentCorner );
469 currentCorner.z = oldMax.
z;
470 merge( matrix * currentCorner );
473 currentCorner.y = oldMax.
y;
474 merge( matrix * currentCorner );
477 currentCorner.z = oldMin.
z;
478 merge( matrix * currentCorner );
481 currentCorner.x = oldMax.
x;
482 merge( matrix * currentCorner );
485 currentCorner.z = oldMax.
z;
486 merge( matrix * currentCorner );
489 currentCorner.y = oldMin.
y;
490 merge( matrix * currentCorner );
493 currentCorner.z = oldMin.
z;
494 merge( matrix * currentCorner );
513 if ( mExtent != EXTENT_FINITE )
517 Vector3 halfSize = getHalfSize();
525 setExtents(newCentre - newHalfSize, newCentre + newHalfSize);
532 mExtent = EXTENT_NULL;
539 return (mExtent == EXTENT_NULL);
546 return (mExtent == EXTENT_FINITE);
553 mExtent = EXTENT_INFINITE;
560 return (mExtent == EXTENT_INFINITE);
567 if (this->isNull() || b2.
isNull())
597 if (this->isNull() || b2.
isNull())
601 else if (this->isInfinite())
617 if (intMin.
x < intMax.
x &&
618 intMin.
y < intMax.
y &&
637 Vector3 diff = mMaximum - mMinimum;
638 return diff.
x * diff.
y * diff.
z;
641 case EXTENT_INFINITE:
645 assert(
false &&
"Never reached" );
654 if (mExtent != EXTENT_FINITE)
660 setExtents(min, max);
682 return(v.
x >= mMinimum.x && v.
x <= mMaximum.x &&
683 v.
y >= mMinimum.y && v.
y <= mMaximum.y &&
684 v.
z >= mMinimum.z && v.
z <= mMaximum.z);
686 case EXTENT_INFINITE:
690 assert(
false &&
"Never reached" );
697 assert( (mExtent == EXTENT_FINITE) &&
"Can't get center of a null or infinite AAB" );
700 (mMaximum.x + mMinimum.x) * 0.5f,
701 (mMaximum.y + mMinimum.y) * 0.5f,
702 (mMaximum.z + mMinimum.z) * 0.5f);
713 return mMaximum - mMinimum;
715 case EXTENT_INFINITE:
722 assert(
false &&
"Never reached" );
735 return (mMaximum - mMinimum) * 0.5;
737 case EXTENT_INFINITE:
744 assert(
false &&
"Never reached" );
758 return mMinimum.x <= v.
x && v.
x <= mMaximum.x &&
759 mMinimum.y <= v.
y && v.
y <= mMaximum.y &&
760 mMinimum.z <= v.
z && v.
z <= mMaximum.z;
767 if (other.
isNull() || this->isInfinite())
773 return this->mMinimum.x <= other.
mMinimum.
x &&
785 if (this->mExtent != rhs.
mExtent)
788 if (!this->isFinite())
791 return this->mMinimum == rhs.
mMinimum &&
799 return !(*
this == rhs);
#define OGRE_ALLOC_T(T, count, category)
Allocate a block of memory for a primitive type, and indicate the category of usage.
Class encapsulating a standard 4x4 homogeneous matrix.
AxisAlignedBox(const AxisAlignedBox &rkBox)
float Real
Software floating point type.
void merge(const Vector3 &point)
Extends the box to encompass the specified point (if needed).
void setExtents(Real mx, Real my, Real mz, Real Mx, Real My, Real Mz)
Real volume(void) const
Calculate the volume of this box.
Defines a plane in 3D space.
static const AxisAlignedBox BOX_NULL
Vector3 getCenter(void) const
Gets the centre of the box.
static const Vector3 ZERO
void transformAffine(const Matrix4 &m)
Transforms the box according to the affine matrix supplied.
A 3D box aligned with the x/y/z axes.
static std::pair< bool, Real > intersects(const Ray &ray, const Plane &plane)
Ray / plane intersection, returns boolean result and distance.
void makeFloor(const Vector3 &cmp)
Sets this vector's components to the minimum of its own and the ones of the passed in vector...
AxisAlignedBox(const Vector3 &min, const Vector3 &max)
void transform(const Matrix4 &matrix)
Transforms the box according to the matrix supplied.
AxisAlignedBox intersection(const AxisAlignedBox &b2) const
Calculate the area of intersection of this box and another.
_OgreExport friend std::ostream & operator<<(std::ostream &o, const AxisAlignedBox aab)
void setMaximumX(Real x)
Changes one of the components of the maximum corner of the box used to resize only one dimension of t...
const Vector3 & getMaximum(void) const
Gets the maximum corner of the box.
Vector3 getCorner(CornerEnum cornerToGet) const
gets the position of one of the corners
bool isAffine(void) const
Check whether or not the matrix is affine matrix.
static const Real POS_INFINITY
bool intersects(const Vector3 &v) const
Tests whether the vector point is within this box.
Vector3 & getMaximum(void)
Gets a modifiable version of the maximum corner of the box.
static Real Abs(Real fValue)
void merge(const AxisAlignedBox &rhs)
Merges the passed in box into the current box.
static const AxisAlignedBox BOX_INFINITE
Vector3 transformAffine(const Vector3 &v) const
3-D Vector transformation specially for an affine matrix.
void setExtents(const Vector3 &min, const Vector3 &max)
Sets both minimum and maximum extents at once.
A sphere primitive, mostly used for bounds checking.
bool intersects(const AxisAlignedBox &b2) const
Returns whether or not this box intersects another.
Vector3 & getMinimum(void)
Gets a modifiable version of the minimum corner of the box.
void setMaximum(Real x, Real y, Real z)
void scale(const Vector3 &s)
Scales the AABB by the vector given.
bool isNull(void) const
Returns true if the box is null i.e.
Standard 3-dimensional vector.
const Vector3 * getAllCorners(void) const
Returns a pointer to an array of 8 corner points, useful for collision vs.
void setNull()
Sets the box to a 'null' value i.e.
Vector3 getSize(void) const
Gets the size of the box.
bool isFinite(void) const
Returns true if the box is finite.
void setMaximum(const Vector3 &vec)
Sets the maximum corner of the box.
void setMinimum(const Vector3 &vec)
Sets the minimum corner of the box.
bool isInfinite(void) const
Returns true if the box is infinite.
bool intersects(const Sphere &s) const
Tests whether this box intersects a sphere.
void setInfinite()
Sets the box to 'infinite'.
const Vector3 & getMinimum(void) const
Gets the minimum corner of the box.
void makeCeil(const Vector3 &cmp)
Sets this vector's components to the maximum of its own and the ones of the passed in vector...
#define OGRE_FREE(ptr, category)
Free the memory allocated with OGRE_MALLOC or OGRE_ALLOC_T. Category is required to be restated to en...
bool contains(const Vector3 &v) const
Tests whether the given point contained by this box.
AxisAlignedBox & operator=(const AxisAlignedBox &rhs)
AxisAlignedBox(Real mx, Real my, Real mz, Real Mx, Real My, Real Mz)
void setMinimumX(Real x)
Changes one of the components of the minimum corner of the box used to resize only one dimension of t...
bool contains(const AxisAlignedBox &other) const
Tests whether another box contained by this box.
bool intersects(const Plane &p) const
Tests whether this box intersects a plane.
void setMinimum(Real x, Real y, Real z)
Vector3 getHalfSize(void) const
Gets the half-size of the box.
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)
bool operator!=(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)