This class represents an axis-aligned bounding-box ("AABB") in 3-dimensional space. More...
#include "BoundingBox.hpp"
Public Types | |
enum | SideT { Back =-1, Both = 0, Front = 1 } |
Information about on which side of a plane the bounding box is. More... | |
Public Member Functions | |
BoundingBox3T () | |
The default constructor creates a bounding-box that is "uninitialized", i.e. More... | |
BoundingBox3T (const Vector3T< T > &A) | |
Constructs a zero-volume bounding box at A. More... | |
BoundingBox3T (const Vector3T< T > &A, const Vector3T< T > &B) | |
Constructs a bounding box as defined by A and B. More... | |
BoundingBox3T (const ArrayT< Vector3T< T > > &A) | |
Constructs a bounding box from the vertices of the array A. More... | |
BoundingBox3T< float > | AsBoxOfFloat () const |
Casts this BoundingBox3T<T> to a BoundingBox3T<float>, so that the cast is explicitly and easy to see and find in user code. More... | |
BoundingBox3T< double > | AsBoxOfDouble () const |
Casts this BoundingBox3T<T> to a BoundingBox3T<double>, so that the cast is explicitly and easy to see and find in user code. More... | |
bool | IsValid () const |
Determines whether a bounding-box is valid. More... | |
bool | IsInited () const |
Returns whether this bounding-box has been initialized with at least one point in space. More... | |
void | Insert (const Vector3T< T > &A) |
Inserts A into this boundig-box, growing it appropriately. More... | |
void | operator+= (const Vector3T< T > &A) |
An equivalent to Insert(A), but more readable. More... | |
void | Insert (const ArrayT< Vector3T< T > > &A) |
Inserts all vertices of A into this boundig-box, growing it appropriately. More... | |
void | operator+= (const ArrayT< Vector3T< T > > &A) |
An equivalent to Insert(A), but more readable. More... | |
void | Insert (const BoundingBox3T< T > &BB) |
Inserts the given bounding-box into this one, growing it appropriately. More... | |
void | operator+= (const BoundingBox3T< T > &BB) |
An equivalent to Insert(BB), but more readable. More... | |
void | InsertValid (const BoundingBox3T< T > &BB) |
Like Insert(BB), but with this version it suffices when BB is only valid, i.e. More... | |
BoundingBox3T< T > | GetEpsilonBox (const T Epsilon) const |
This method returns a copy of this bounding box that is slightly enlarged by Epsilon (or shrunk if Epsilon is negative). More... | |
BoundingBox3T< T > | GetOverallTranslationBox (const Vector3T< T > &Start, const Vector3T< T > &End) const |
Returns the overall bounding box that is defined by translating (moving) this bounding box in a linear fashion from point Start to End. More... | |
bool | Contains (const Vector3T< T > &A) const |
Determines whether this bounding box contains A. More... | |
bool | Intersects (const BoundingBox3T< T > &BB) const |
Determines whether this bounding box and BB intersect. More... | |
bool | IntersectsOrTouches (const BoundingBox3T< T > &BB) const |
Determines whether this bounding box and BB intersect or touch each other. More... | |
SideT | WhatSide (const Plane3T< T > &P, const T Epsilon=0) const |
Determines on what side of plane P the this BB is. More... | |
SideT | WhatSide_OLD (const Plane3T< T > &P, const T Epsilon=0) const |
Vector3T< T > | GetCenter () const |
Returns the center point of the BB. More... | |
T | GetDistance (const Plane3T< T > &P) const |
Determines the distance from the plane P to the nearest point of the BB. More... | |
bool | TraceRay (const Vector3T< T > &RayOrigin, const Vector3T< T > &RayDir, T &Fraction) const |
Traces a ray against this bounding-box, and returns whether it was hit. More... | |
void | GetCornerVertices (Vector3T< T > *Vertices) const |
Explicitly returns the eight corner vertices of this bounding box. More... | |
ArrayT< BoundingBox3T< T > > | GetSplits (const Plane3T< T > &SplitPlane, const T PlaneThickness) const |
Splits the quad that is defined by this bounding box and constructs new bounding boxes from the results. More... | |
Public Attributes | |
Vector3T< T > | Min |
The minimum-coordinate corner of the bounding-box. More... | |
Vector3T< T > | Max |
The maximum-coordinate corner of the bounding-box. More... | |
This class represents an axis-aligned bounding-box ("AABB") in 3-dimensional space.
enum BoundingBox3T::SideT |
BoundingBox3T< T >::BoundingBox3T | ( | ) |
The default constructor creates a bounding-box that is "uninitialized", i.e.
whose dimensions are not specified. Inserting the first vertex into the bounding-box will automatically turn it into a regular, initialized instance.
|
explicit |
Constructs a zero-volume bounding box at A.
A | The spatial location to initialize the bounding-box at. |
BoundingBox3T< T >::BoundingBox3T | ( | const Vector3T< T > & | A, |
const Vector3T< T > & | B | ||
) |
Constructs a bounding box as defined by A and B.
A | The first corner point that defines the dimensions of the bounding-box. |
B | The second corner point that defines the dimensions of the bounding-box. |
|
explicit |
Constructs a bounding box from the vertices of the array A.
The bounding-box will be "uninitialized" if A is empty.
A | An array of vertices whose elements define the dimensions of the bounding-box. |
|
inline |
Casts this BoundingBox3T<T> to a BoundingBox3T<double>, so that the cast is explicitly and easy to see and find in user code.
|
inline |
Casts this BoundingBox3T<T> to a BoundingBox3T<float>, so that the cast is explicitly and easy to see and find in user code.
bool BoundingBox3T< T >::Contains | ( | const Vector3T< T > & | A | ) | const |
Determines whether this bounding box contains A.
A | The point for which containment should be determined. |
|
inline |
Returns the center point of the BB.
void BoundingBox3T< T >::GetCornerVertices | ( | Vector3T< T > * | Vertices | ) | const |
Explicitly returns the eight corner vertices of this bounding box.
Vertices | An array of eight vertices in which the eight corner vertices are returned. |
T BoundingBox3T< T >::GetDistance | ( | const Plane3T< T > & | P | ) | const |
Determines the distance from the plane P to the nearest point of the BB.
P | The plane to test with. |
|
inline |
This method returns a copy of this bounding box that is slightly enlarged by Epsilon (or shrunk if Epsilon is negative).
The returned box is very useful with the containment / intersection / test methods when rounding errors are an issue! Note that it is easy to control the desired effect by passing either a positive number to make the box slightly larger, or by passing a negative number to make the box slightly smaller. For example, if BB is a bounding box, BB.GetEpsilonBox(0.1).Contains(A) returns true even if A is actually a bit outside of BB, or BB.GetEpsilonBox(-0.3).Intersects(OtherBB) yields false even if BB and OtherBB are neighboured and share a plane.
Epsilon | The amount by which the bounding-box is expanded. |
BoundingBox3T< T > BoundingBox3T< T >::GetOverallTranslationBox | ( | const Vector3T< T > & | Start, |
const Vector3T< T > & | End | ||
) | const |
Returns the overall bounding box that is defined by translating (moving) this bounding box in a linear fashion from point Start to End.
Start | The start point for the thought linear movement of this bounding box. |
End | The end point for the thought linear movement of this bounding box. |
ArrayT< BoundingBox3T< T > > BoundingBox3T< T >::GetSplits | ( | const Plane3T< T > & | SplitPlane, |
const T | PlaneThickness | ||
) | const |
Splits the quad that is defined by this bounding box and constructs new bounding boxes from the results.
SplitPlane | The plane along which this bounding box is split. |
PlaneThickness | The "thickness" that is attributed to the SplitPlane to account for rounding-error. |
void BoundingBox3T< T >::Insert | ( | const Vector3T< T > & | A | ) |
Inserts A into this boundig-box, growing it appropriately.
A | The point to be inserted into the bounding-box. |
void BoundingBox3T< T >::Insert | ( | const ArrayT< Vector3T< T > > & | A | ) |
Inserts all vertices of A into this boundig-box, growing it appropriately.
A | The list of points to be inserted into the bounding-box. |
void BoundingBox3T< T >::Insert | ( | const BoundingBox3T< T > & | BB | ) |
Inserts the given bounding-box into this one, growing it appropriately.
This is also called "merging" or "combining" BB with this bounding box.
BB | The bounding-box to be combined/merged with this bounding-box. BB.IsInited() must be true. |
void BoundingBox3T< T >::InsertValid | ( | const BoundingBox3T< T > & | BB | ) |
Like Insert(BB), but with this version it suffices when BB is only valid, i.e.
it can be initialized or uninitialized. If BB is uninitialized, this bounding-box is not changed. Otherwise, BB is inserted normally: this->Insert(BB).
BB | The bounding-box to be combined/merged with this bounding-box. BB.IsValid() must be true. |
bool BoundingBox3T< T >::Intersects | ( | const BoundingBox3T< T > & | BB | ) | const |
Determines whether this bounding box and BB intersect.
BB | The other bounding box to test with. |
bool BoundingBox3T< T >::IntersectsOrTouches | ( | const BoundingBox3T< T > & | BB | ) | const |
Determines whether this bounding box and BB intersect or touch each other.
This method is only used in the ClipSys, and the Intersects() method should always be preferred.
BB | The other bounding box to test with. |
bool BoundingBox3T< T >::IsInited | ( | ) | const |
Returns whether this bounding-box has been initialized with at least one point in space.
A bounding-box that has not yet been initialized can be initalized by inserting the first vertex.
bool BoundingBox3T< T >::IsValid | ( | ) | const |
Determines whether a bounding-box is valid.
A bounding-box is valid if it is in "uninitialized" or properly initialized state. (A bounding-box is invalid if it has negative volume.) This method is needed mostly for debugging, as a bounding-box should always be valid.
|
inline |
An equivalent to Insert(A), but more readable.
|
inline |
An equivalent to Insert(A), but more readable.
|
inline |
An equivalent to Insert(BB), but more readable.
bool BoundingBox3T< T >::TraceRay | ( | const Vector3T< T > & | RayOrigin, |
const Vector3T< T > & | RayDir, | ||
T & | Fraction | ||
) | const |
Traces a ray against this bounding-box, and returns whether it was hit.
The ray for the trace is defined by RayOrigin + RayDir*Fraction, where Fraction is a scalar >= 0. If a hit was detected, the Fraction is returned. The method only accounts for "incoming" hits, that is, where the ray comes from "outside" of the boundig-box and enters its inside. Hits where the ray leaves the inner of the bounding-box to the outside are not reported.
RayOrigin | The point where the ray starts. |
RayDir | A vector of non-zero length that describes the direction the ray extends to (not required to be a unit vector). |
Fraction | On hit, the scalar along RayDir at which the hit occurred is returned here. |
BoundingBox3T< T >::SideT BoundingBox3T< T >::WhatSide | ( | const Plane3T< T > & | P, |
const T | Epsilon = 0 |
||
) | const |
Determines on what side of plane P the this BB is.
P | The plane to test with. |
Epsilon | Maximum error value. |
Vector3T<T> BoundingBox3T< T >::Max |
The maximum-coordinate corner of the bounding-box.
Vector3T<T> BoundingBox3T< T >::Min |
The minimum-coordinate corner of the bounding-box.