Cafu Engine
BoundingBox3T< T > Class Template Reference

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...
 
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...
 

Detailed Description

template<class T>
class BoundingBox3T< T >

This class represents an axis-aligned bounding-box ("AABB") in 3-dimensional space.

Member Enumeration Documentation

template<class T>
enum BoundingBox3T::SideT

Information about on which side of a plane the bounding box is.

Enumerator
Back 

The bounding box is on the back-side of the plane.

Both 

The bounding box is on both sides of the plane (i.e. it is intersected by the plane).

Front 

The bounding box is on the front-side of the plane.

Constructor & Destructor Documentation

template<class T >
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.

template<class T>
BoundingBox3T< T >::BoundingBox3T ( const Vector3T< T > &  A)
explicit

Constructs a zero-volume bounding box at A.

Parameters
AThe spatial location to initialize the bounding-box at.
template<class T>
BoundingBox3T< T >::BoundingBox3T ( const Vector3T< T > &  A,
const Vector3T< T > &  B 
)

Constructs a bounding box as defined by A and B.

Parameters
AThe first corner point that defines the dimensions of the bounding-box.
BThe second corner point that defines the dimensions of the bounding-box.
template<class T>
BoundingBox3T< T >::BoundingBox3T ( const ArrayT< Vector3T< T > > &  A)
explicit

Constructs a bounding box from the vertices of the array A.

The bounding-box will be "uninitialized" if A is empty.

Parameters
AAn array of vertices whose elements define the dimensions of the bounding-box.

Member Function Documentation

template<class T>
BoundingBox3T<double> BoundingBox3T< T >::AsBoxOfDouble ( ) const
inline

Casts this BoundingBox3T<T> to a BoundingBox3T<double>, so that the cast is explicitly and easy to see and find in user code.

template<class T>
BoundingBox3T<float> BoundingBox3T< T >::AsBoxOfFloat ( ) const
inline

Casts this BoundingBox3T<T> to a BoundingBox3T<float>, so that the cast is explicitly and easy to see and find in user code.

template<class T>
bool BoundingBox3T< T >::Contains ( const Vector3T< T > &  A) const

Determines whether this bounding box contains A.

Parameters
AThe point for which containment should be determined.
template<class T>
Vector3T<T> BoundingBox3T< T >::GetCenter ( ) const
inline

Returns the center point of the BB.

template<class T>
void BoundingBox3T< T >::GetCornerVertices ( Vector3T< T > *  Vertices) const

Explicitly returns the eight corner vertices of this bounding box.

Parameters
VerticesAn array of eight vertices in which the eight corner vertices are returned.
template<class T>
T BoundingBox3T< T >::GetDistance ( const Plane3T< T > &  P) const

Determines the distance from the plane P to the nearest point of the BB.

Parameters
PThe plane to test with.
Returns
the distance from the plane P to the nearest point of the BB, 0 whenever the BB intersects P.
template<class T>
BoundingBox3T<T> BoundingBox3T< T >::GetEpsilonBox ( const T  Epsilon) const
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.

Parameters
EpsilonThe amount by which the bounding-box is expanded.
template<class T>
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.

Parameters
StartThe start point for the thought linear movement of this bounding box.
EndThe end point for the thought linear movement of this bounding box.
Returns
the overall bounding box that contains the entire movement.
template<class T>
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.

Parameters
SplitPlaneThe plane along which this bounding box is split.
PlaneThicknessThe "thickness" that is attributed to the SplitPlane to account for rounding-error.
Returns
an array of two bounding-boxes that correspond to the front and back split results.
template<class T>
void BoundingBox3T< T >::Insert ( const Vector3T< T > &  A)

Inserts A into this boundig-box, growing it appropriately.

Parameters
AThe point to be inserted into the bounding-box.
template<class T>
void BoundingBox3T< T >::Insert ( const ArrayT< Vector3T< T > > &  A)

Inserts all vertices of A into this boundig-box, growing it appropriately.

Parameters
AThe list of points to be inserted into the bounding-box.
template<class T>
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.

Parameters
BBThe bounding-box to be combined/merged with this bounding-box. BB.IsInited() must be true.
template<class T>
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).

Parameters
BBThe bounding-box to be combined/merged with this bounding-box. BB.IsValid() must be true.
template<class T>
bool BoundingBox3T< T >::Intersects ( const BoundingBox3T< T > &  BB) const

Determines whether this bounding box and BB intersect.

Parameters
BBThe other bounding box to test with.
template<class T>
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.

Parameters
BBThe other bounding box to test with.
template<class T >
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.

template<class T >
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.

template<class T>
void BoundingBox3T< T >::operator+= ( const Vector3T< T > &  A)
inline

An equivalent to Insert(A), but more readable.

template<class T>
void BoundingBox3T< T >::operator+= ( const ArrayT< Vector3T< T > > &  A)
inline

An equivalent to Insert(A), but more readable.

template<class T>
void BoundingBox3T< T >::operator+= ( const BoundingBox3T< T > &  BB)
inline

An equivalent to Insert(BB), but more readable.

template<class T>
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.

Parameters
RayOriginThe point where the ray starts.
RayDirA vector of non-zero length that describes the direction the ray extends to (not required to be a unit vector).
FractionOn hit, the scalar along RayDir at which the hit occurred is returned here.
Returns
true if the ray hit this bounding-box, false otherwise. On hit, the Fraction is returned via reference paramaters.
template<class T>
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.

Parameters
PThe plane to test with.
EpsilonMaximum error value.
Returns
SideT::Front if this box is completely on the front of P, SideT::Back if this box is completely on the back of P, SideT::Both if this box is on both sides of P.

Member Data Documentation

template<class T>
Vector3T<T> BoundingBox3T< T >::Max

The maximum-coordinate corner of the bounding-box.

template<class T>
Vector3T<T> BoundingBox3T< T >::Min

The minimum-coordinate corner of the bounding-box.


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