CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Math::TAABox< T > Struct Template Reference

Axis aligned box represented by minimum and maximum point. More...

#include <CeresEngine/Math/Geometry.hpp>

Public Types

enum  Corner {
  FarLeftBottom = 0 , FarLeftTop = 1 , FarRightTop = 2 , FarRightBottom = 3 ,
  NearRightBottom = 7 , NearLeftBottom = 6 , NearLeftTop = 5 , NearRightTop = 4
}
 Different corners of a box. More...
 

Public Member Functions

 TAABox ()=default
 
 TAABox (const TVector3< T > &min, const TVector3< T > &max)
 
 TAABox (const TSphere< T > &sphere)
 
 TAABox (const TAABox &)=default
 
 ~TAABox ()=default
 
TAABox scale (const TVector3< T > &s) const
 Scales the box around the center by multiplying its extents with the provided scale.
 
TAABox translate (const TVector3< T > &t) const
 Translates the box center by adding t to the minimum and maximum.
 
TVector3< T > getCorner (Corner cornerToGet) const noexcept
 Returns the coordinates of a specific corner.
 
Array< TVector3< T >, 8 > getCorners () const noexcept
 
TAABox merge (const TAABox &rhs)
 Merges the two boxes, creating a new bounding box that encapsulates them both.
 
TAABox merge (const TVector3< T > &point)
 Expands the bounding box so it includes the provided point.
 
void transform (const TMatrix4< T > &matrix)
 Transforms the bounding box by the given matrix.
 
void transform (const TTransform< T > &aTransform)
 Transforms the bounding box by the given matrix.
 
bool intersects (const TAABox &b2) const
 Returns true if this and the provided box intersect.
 
bool intersects (const TSphere< T > &s) const
 Returns true if the sphere intersects the bounding box.
 
bool intersects (const TPlane< T > &p) const
 Returns true if the plane intersects the bounding box.
 
TRayIntersection< T > intersects (const TRay< T > &ray) const
 Ray / box intersection, returns a boolean result and nearest distance to intersection.
 
bool intersects (const TRay< T > &ray, T &d1, T &d2) const
 Ray / box intersection, returns boolean result and near and far intersection distance.
 
bool contains (const TVector3< T > &v) const
 Returns true if the provided point is inside the bounding box.
 
bool contains (const TVector3< T > &v, T extra) const
 Returns true if the provided point is inside the bounding box while.
 
bool contains (const TAABox &other) const
 Returns true if the provided bounding box is completely inside the bounding box.
 
bool contains (const TSphere< T > &s) const
 Returns true if the sphere is completely inside the bounding box.
 
TVector3< T > getCenter () const
 Center of the box.
 
TVector3< T > getSize () const
 Size of the box (difference between minimum and maximum corners)
 
TVector3< T > getHalfSize () const
 Extents of the box (distance from center to one of the corners)
 
getRadius () const
 Radius of a sphere that fully encompasses the box.
 
getVolume () const
 Size of the volume in the box.
 

Public Attributes

TVector3< T > minimum = Vector3(-T(0.5), -T(0.5), -T(0.5))
 The corner of the box with minimum values (opposite to maximum corner).
 
TVector3< T > maximum = Vector3(T(0.5), T(0.5), T(0.5))
 The corner of the box with maximum values (opposite to minimum corner).
 

Static Public Attributes

static const TAABox empty
 
static const TAABox unit
 
static const TAABox infinity
 
template<typename I = UInt32>
static constexpr I CUBE_INDICES []
 Indices that can be used for rendering a box constructed from 8 corner vertices, using AABox::Corner for mapping.
 

Friends

bool operator== (const TAABox &lhs, const TAABox &rhs)
 
bool operator!= (const TAABox &lhs, const TAABox &rhs)
 
TAABox operator+ (const TAABox &lhs, const TAABox &rhs)
 Merges the two boxes, creating a new bounding box that encapsulates them both.
 
TAABoxoperator+= (TAABox &lhs, const TAABox &rhs)
 Merges the two boxes, creating a new bounding box that encapsulates them both.
 
TAABox operator+ (const TAABox &lhs, const TVector3< T > &rhs)
 Expands the bounding box so it includes the provided point.
 
TAABoxoperator+= (TAABox &lhs, const TVector3< T > &rhs)
 Expands the bounding box so it includes the provided point.
 
TAABox operator* (const TMatrix4< T > &lhs, TAABox rhs)
 Transforms the bounding box by the given matrix.
 
TAABox operator* (const TTransform< T > &lhs, TAABox rhs)
 Transforms the bounding box by the given transform.
 

Detailed Description

template<typename T>
struct Math::TAABox< T >

Axis aligned box represented by minimum and maximum point.

Member Enumeration Documentation

◆ Corner

template<typename T >
enum Math::TAABox::Corner

Different corners of a box.

1--—2 /| /| / | / | 5--—4 | | 0–|–3 | / | / |/ |/ 6--—7

Enumerator
FarLeftBottom 
FarLeftTop 
FarRightTop 
FarRightBottom 
NearRightBottom 
NearLeftBottom 
NearLeftTop 
NearRightTop 

Constructor & Destructor Documentation

◆ TAABox() [1/4]

template<typename T >
Math::TAABox< T >::TAABox ( )
default

◆ TAABox() [2/4]

template<typename T >
Math::TAABox< T >::TAABox ( const TVector3< T > &  min,
const TVector3< T > &  max 
)

◆ TAABox() [3/4]

template<typename T >
Math::TAABox< T >::TAABox ( const TSphere< T > &  sphere)
inlineexplicit

◆ TAABox() [4/4]

template<typename T >
Math::TAABox< T >::TAABox ( const TAABox< T > &  )
default

◆ ~TAABox()

template<typename T >
Math::TAABox< T >::~TAABox ( )
default

Member Function Documentation

◆ contains() [1/4]

template<typename T >
bool Math::TAABox< T >::contains ( const TAABox< T > &  other) const

Returns true if the provided bounding box is completely inside the bounding box.

◆ contains() [2/4]

template<typename T >
bool Math::TAABox< T >::contains ( const TSphere< T > &  s) const

Returns true if the sphere is completely inside the bounding box.

◆ contains() [3/4]

template<typename T >
bool Math::TAABox< T >::contains ( const TVector3< T > &  v) const

Returns true if the provided point is inside the bounding box.

◆ contains() [4/4]

template<typename T >
bool Math::TAABox< T >::contains ( const TVector3< T > &  v,
extra 
) const

Returns true if the provided point is inside the bounding box while.

expanding the bounds by extra in every direction.

◆ getCenter()

template<typename T >
TVector3< T > Math::TAABox< T >::getCenter ( ) const

Center of the box.

◆ getCorner()

template<typename T >
TVector3< T > Math::TAABox< T >::getCorner ( Corner  cornerToGet) const
noexcept

Returns the coordinates of a specific corner.

◆ getCorners()

template<typename T >
Array< TVector3< T >, 8 > Math::TAABox< T >::getCorners ( ) const
noexcept
Returns
The coordinates for all corners.

◆ getHalfSize()

template<typename T >
TVector3< T > Math::TAABox< T >::getHalfSize ( ) const

Extents of the box (distance from center to one of the corners)

◆ getRadius()

template<typename T >
T Math::TAABox< T >::getRadius ( ) const

Radius of a sphere that fully encompasses the box.

◆ getSize()

template<typename T >
TVector3< T > Math::TAABox< T >::getSize ( ) const

Size of the box (difference between minimum and maximum corners)

◆ getVolume()

template<typename T >
T Math::TAABox< T >::getVolume ( ) const

Size of the volume in the box.

◆ intersects() [1/5]

template<typename T >
bool Math::TAABox< T >::intersects ( const TAABox< T > &  b2) const

Returns true if this and the provided box intersect.

◆ intersects() [2/5]

template<typename T >
bool Math::TAABox< T >::intersects ( const TPlane< T > &  p) const

Returns true if the plane intersects the bounding box.

◆ intersects() [3/5]

template<typename T >
TRayIntersection< T > Math::TAABox< T >::intersects ( const TRay< T > &  ray) const

Ray / box intersection, returns a boolean result and nearest distance to intersection.

◆ intersects() [4/5]

template<typename T >
bool Math::TAABox< T >::intersects ( const TRay< T > &  ray,
T &  d1,
T &  d2 
) const

Ray / box intersection, returns boolean result and near and far intersection distance.

◆ intersects() [5/5]

template<typename T >
bool Math::TAABox< T >::intersects ( const TSphere< T > &  s) const

Returns true if the sphere intersects the bounding box.

◆ merge() [1/2]

template<typename T >
TAABox Math::TAABox< T >::merge ( const TAABox< T > &  rhs)

Merges the two boxes, creating a new bounding box that encapsulates them both.

◆ merge() [2/2]

template<typename T >
TAABox Math::TAABox< T >::merge ( const TVector3< T > &  point)

Expands the bounding box so it includes the provided point.

◆ scale()

template<typename T >
TAABox Math::TAABox< T >::scale ( const TVector3< T > &  s) const

Scales the box around the center by multiplying its extents with the provided scale.

◆ transform() [1/2]

template<typename T >
void Math::TAABox< T >::transform ( const TMatrix4< T > &  matrix)

Transforms the bounding box by the given matrix.

Note
As the resulting box will no longer be axis aligned, an axis align box is instead created by encompassing the transformed oriented bounding box. Retrieving the value as an actual OBB would provide a tighter fit.

◆ transform() [2/2]

template<typename T >
void Math::TAABox< T >::transform ( const TTransform< T > &  aTransform)
inline

Transforms the bounding box by the given matrix.

Note
As the resulting box will no longer be axis aligned, an axis align box is instead created by encompassing the transformed oriented bounding box. Retrieving the value as an actual OBB would provide a tighter fit.

◆ translate()

template<typename T >
TAABox Math::TAABox< T >::translate ( const TVector3< T > &  t) const

Translates the box center by adding t to the minimum and maximum.

Friends And Related Symbol Documentation

◆ operator!=

template<typename T >
bool operator!= ( const TAABox< T > &  lhs,
const TAABox< T > &  rhs 
)
friend

◆ operator* [1/2]

template<typename T >
TAABox operator* ( const TMatrix4< T > &  lhs,
TAABox< T >  rhs 
)
friend

Transforms the bounding box by the given matrix.

Note
As the resulting box will no longer be axis aligned, an axis align box is instead created by encompassing the transformed oriented bounding box. Retrieving the value as an actual OBB would provide a tighter fit.

◆ operator* [2/2]

template<typename T >
TAABox operator* ( const TTransform< T > &  lhs,
TAABox< T >  rhs 
)
friend

Transforms the bounding box by the given transform.

Note
As the resulting box will no longer be axis aligned, an axis align box is instead created by encompassing the transformed oriented bounding box. Retrieving the value as an actual OBB would provide a tighter fit.

◆ operator+ [1/2]

template<typename T >
TAABox operator+ ( const TAABox< T > &  lhs,
const TAABox< T > &  rhs 
)
friend

Merges the two boxes, creating a new bounding box that encapsulates them both.

Parameters
lhsThe box to be expanded
rhsThe box to expand with
Returns
The expanded box

◆ operator+ [2/2]

template<typename T >
TAABox operator+ ( const TAABox< T > &  lhs,
const TVector3< T > &  rhs 
)
friend

Expands the bounding box so it includes the provided point.

Parameters
lhsThe box to be expanded
rhsThe point to be encapsulated
Returns
The expanded box

◆ operator+= [1/2]

template<typename T >
TAABox & operator+= ( TAABox< T > &  lhs,
const TAABox< T > &  rhs 
)
friend

Merges the two boxes, creating a new bounding box that encapsulates them both.

Parameters
lhsThe box to be expanded
rhsThe box to expand with
Returns
lhs

◆ operator+= [2/2]

template<typename T >
TAABox & operator+= ( TAABox< T > &  lhs,
const TVector3< T > &  rhs 
)
friend

Expands the bounding box so it includes the provided point.

Parameters
lhsThe box to be expanded
rhsThe point to be encapsulated
Returns
lhs

◆ operator==

template<typename T >
bool operator== ( const TAABox< T > &  lhs,
const TAABox< T > &  rhs 
)
friend

Member Data Documentation

◆ CUBE_INDICES

template<typename T >
template<typename I = UInt32>
constexpr I Math::TAABox< T >::CUBE_INDICES[]
inlinestaticconstexpr
Initial value:

Indices that can be used for rendering a box constructed from 8 corner vertices, using AABox::Corner for mapping.

Template Parameters
Ithe index type

◆ empty

template<typename T >
const TAABox Math::TAABox< T >::empty
static

◆ infinity

template<typename T >
const TAABox Math::TAABox< T >::infinity
static

◆ maximum

template<typename T >
TVector3<T> Math::TAABox< T >::maximum = Vector3(T(0.5), T(0.5), T(0.5))

The corner of the box with maximum values (opposite to minimum corner).

◆ minimum

template<typename T >
TVector3<T> Math::TAABox< T >::minimum = Vector3(-T(0.5), -T(0.5), -T(0.5))

The corner of the box with minimum values (opposite to maximum corner).

◆ unit

template<typename T >
const TAABox Math::TAABox< T >::unit
static

The documentation for this struct was generated from the following file: