XII Release 0.1.0
Loading...
Searching...
No Matches
xiiBoundingBoxTemplate< Type > Class Template Reference

An axis-aligned bounding box implementation. More...

#include <BoundingBox.h>

Public Types

using ComponentType = Type
 

Public Member Functions

 XII_DECLARE_POD_TYPE ()
 
 xiiBoundingBoxTemplate ()
 Default constructor does not initialize anything.
 
 xiiBoundingBoxTemplate (const xiiVec3Template< Type > &vMin, const xiiVec3Template< Type > &vMax)
 Constructs the box with the given minimum and maximum values.
 
bool IsValid () const
 Checks whether the box is in an invalid state.
 
bool IsNaN () const
 Checks whether any component is NaN.
 
void GetCorners (xiiVec3Template< Type > *out_pCorners) const
 Writes the 8 different corners of the box to the given array.
 
const xiiVec3Template< Type > GetCenter () const
 Returns the center position of the box.
 
const xiiVec3Template< Type > GetExtents () const
 Returns the extents of the box along each axis.
 
const xiiVec3Template< Type > GetHalfExtents () const
 Returns the half extents of the box along each axis.
 
void ExpandToInclude (const xiiVec3Template< Type > &vPoint)
 Expands the box such that the given point is inside it.
 
void ExpandToInclude (const xiiBoundingBoxTemplate &rhs)
 Expands the box such that the given box is inside it.
 
void ExpandToInclude (const xiiVec3Template< Type > *pPoints, xiiUInt32 uiNumPoints, xiiUInt32 uiStride=sizeof(xiiVec3Template< Type >))
 Expands the box such that all the given points are inside it.
 
void ExpandToCube ()
 If the box is not cubic all extents are set to the value of the maximum extent, such that the box becomes cubic.
 
void Grow (const xiiVec3Template< Type > &vDiff)
 Will increase the size of the box in all directions by the given amount (per axis).
 
bool Contains (const xiiVec3Template< Type > &vPoint) const
 Checks whether the given point is inside the box.
 
bool Contains (const xiiBoundingBoxTemplate &rhs) const
 Checks whether the given box is completely inside this box.
 
bool Contains (const xiiVec3Template< Type > *pPoints, xiiUInt32 uiNumPoints, xiiUInt32 uiStride=sizeof(xiiVec3Template< Type >)) const
 Checks whether all the given points are inside this box.
 
bool Contains (const xiiBoundingSphereTemplate< Type > &sphere) const
 Checks whether the given sphere is completely inside this box.
 
bool Overlaps (const xiiBoundingBoxTemplate &rhs) const
 Checks whether this box overlaps with the given box.
 
bool Overlaps (const xiiVec3Template< Type > *pPoints, xiiUInt32 uiNumPoints, xiiUInt32 uiStride=sizeof(xiiVec3Template< Type >)) const
 Checks whether any of the given points is inside this box.
 
bool Overlaps (const xiiBoundingSphereTemplate< Type > &sphere) const
 Checks whether the given sphere overlaps with this box.
 
bool IsIdentical (const xiiBoundingBoxTemplate &rhs) const
 Checks whether this box and the other box are exactly identical.
 
bool IsEqual (const xiiBoundingBoxTemplate &rhs, Type fEpsilon=xiiMath::DefaultEpsilon< Type >()) const
 Checks whether this box and the other box are equal within some threshold.
 
void Translate (const xiiVec3Template< Type > &vDiff)
 Moves the box by the given vector.
 
void ScaleFromCenter (const xiiVec3Template< Type > &vScale)
 Scales the box along each axis, but keeps its center constant.
 
void ScaleFromOrigin (const xiiVec3Template< Type > &vScale)
 Scales the box's corners by the given factors, thus also moves the box around.
 
void TransformFromCenter (const xiiMat4Template< Type > &mTransform)
 Transforms the corners of the box in its local space. The center of the box does not change, unless the transform contains a translation.
 
void TransformFromOrigin (const xiiMat4Template< Type > &mTransform)
 Transforms the corners of the box and recomputes the AABB of those transformed points. Rotations and scalings will influence the center position of the box.
 
const xiiVec3Template< Type > GetClampedPoint (const xiiVec3Template< Type > &vPoint) const
 The given point is clamped to the volume of the box, i.e. it will be either inside the box or on its surface and it will have the closest possible distance to the original point.
 
Type GetDistanceSquaredTo (const xiiVec3Template< Type > &vPoint) const
 Returns the squared minimum distance from the box's surface to the point. Zero if the point is inside the box.
 
Type GetDistanceSquaredTo (const xiiBoundingBoxTemplate &rhs) const
 Returns the minimum squared distance between the two boxes. Zero if the boxes overlap.
 
Type GetDistanceTo (const xiiVec3Template< Type > &vPoint) const
 Returns the minimum distance from the box's surface to the point. Zero if the point is inside the box.
 
Type GetDistanceTo (const xiiBoundingSphereTemplate< Type > &sphere) const
 Returns the minimum distance between the box and the sphere. Zero or negative if both overlap.
 
Type GetDistanceTo (const xiiBoundingBoxTemplate &rhs) const
 Returns the minimum distance between the two boxes. Zero if the boxes overlap.
 
bool GetRayIntersection (const xiiVec3Template< Type > &vStartPos, const xiiVec3Template< Type > &vRayDir, Type *out_pIntersectionDistance=nullptr, xiiVec3Template< Type > *out_pIntersection=nullptr) const
 Returns whether the given ray intersects the box. Optionally returns the intersection distance and position. Note that vRayDir is not required to be normalized.
 
bool GetLineSegmentIntersection (const xiiVec3Template< Type > &vStartPos, const xiiVec3Template< Type > &vEndPos, Type *out_pLineFraction=nullptr, xiiVec3Template< Type > *out_pIntersection=nullptr) const
 Checks whether the line segment intersects the box. Optionally returns the intersection point and the fraction along the line segment where the intersection occurred.
 
const xiiBoundingSphereTemplate< Type > GetBoundingSphere () const
 Returns a bounding sphere that encloses this box.
 

Static Public Member Functions

static xiiBoundingBoxTemplate< Type > MakeZero ()
 Creates a box that is located at the origin and has zero size. This is a 'valid' box.
 
static xiiBoundingBoxTemplate< Type > MakeInvalid ()
 Creates a box that is in an invalid state. ExpandToInclude can then be used to make it into a bounding box for objects.
 
static xiiBoundingBoxTemplate< Type > MakeFromCenterAndHalfExtents (const xiiVec3Template< Type > &vCenter, const xiiVec3Template< Type > &vHalfExtents)
 Creates a box from a center point and half-extents for each axis.
 
static xiiBoundingBoxTemplate< Type > MakeFromMinMax (const xiiVec3Template< Type > &vMin, const xiiVec3Template< Type > &vMax)
 Creates a box with the given minimum and maximum values.
 
static xiiBoundingBoxTemplate< Type > MakeFromPoints (const xiiVec3Template< Type > *pPoints, xiiUInt32 uiNumPoints, xiiUInt32 uiStride=sizeof(xiiVec3Template< Type >))
 Creates a box around the given set of points. If uiNumPoints is zero, the returned box is invalid (same as MakeInvalid() returns).
 

Public Attributes

xiiVec3Template< Type > m_vMin
 
xiiVec3Template< Type > m_vMax
 

Detailed Description

template<typename Type>
class xiiBoundingBoxTemplate< Type >

An axis-aligned bounding box implementation.

This class allows to construct AABBs and also provides a large set of functions to work with them, e.g. for overlap queries and ray casts.


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