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);
420 mMaximum.makeCeil(point);
421 mMinimum.makeFloor(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();
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:
644 assert(
false &&
"Never reached" );
653 if (mExtent != EXTENT_FINITE)
659 setExtents(min, max);
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);
712 return mMaximum - mMinimum;
714 case EXTENT_INFINITE:
721 assert(
false &&
"Never reached" );
734 return (mMaximum - mMinimum) * 0.5;
736 case EXTENT_INFINITE:
743 assert(
false &&
"Never reached" );
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);
Real squaredDistance(const Vector3 &v) const
Returns the squared minimum distance between a given point and any part of the box.
#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...
_OgreExport friend std::ostream & operator<<(std::ostream &o, const AxisAlignedBox &aab)
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.
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.
Real distance(const Vector3 &v) const
Returns the minimum distance between a given point and any part of the box.
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)
Absolute value function.
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.
static Real Sqrt(Real fValue)
Square root function.
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.
Real squaredLength() const
Returns the square of the length(magnitude) of the vector.
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++)