Plasma Engine  2.0
Loading...
Searching...
No Matches
plBoundingBoxTemplate< Type > Class Template Reference

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

#include <BoundingBox.h>

Public Types

using ComponentType = Type
 

Public Member Functions

 PL_DECLARE_POD_TYPE ()
 
 plBoundingBoxTemplate ()
 Default constructor does not initialize anything.
 
 plBoundingBoxTemplate (const plVec3Template< Type > &vMin, const plVec3Template< 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 (plVec3Template< Type > *out_pCorners) const
 Writes the 8 different corners of the box to the given array.
 
const plVec3Template< Type > GetCenter () const
 Returns the center position of the box.
 
const plVec3Template< Type > GetExtents () const
 Returns the extents of the box along each axis.
 
const plVec3Template< Type > GetHalfExtents () const
 Returns the half extents of the box along each axis.
 
void ExpandToInclude (const plVec3Template< Type > &vPoint)
 Expands the box such that the given point is inside it.
 
void ExpandToInclude (const plBoundingBoxTemplate &rhs)
 Expands the box such that the given box is inside it.
 
void ExpandToInclude (const plVec3Template< Type > *pPoints, plUInt32 uiNumPoints, plUInt32 uiStride=sizeof(plVec3Template< 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 plVec3Template< Type > &vDiff)
 Will increase the size of the box in all directions by the given amount (per axis).
 
bool Contains (const plVec3Template< Type > &vPoint) const
 Checks whether the given point is inside the box.
 
bool Contains (const plBoundingBoxTemplate &rhs) const
 Checks whether the given box is completely inside this box.
 
bool Contains (const plVec3Template< Type > *pPoints, plUInt32 uiNumPoints, plUInt32 uiStride=sizeof(plVec3Template< Type >)) const
 Checks whether all the given points are inside this box.
 
bool Contains (const plBoundingSphereTemplate< Type > &sphere) const
 Checks whether the given sphere is completely inside this box.
 
bool Overlaps (const plBoundingBoxTemplate &rhs) const
 Checks whether this box overlaps with the given box.
 
bool Overlaps (const plVec3Template< Type > *pPoints, plUInt32 uiNumPoints, plUInt32 uiStride=sizeof(plVec3Template< Type >)) const
 Checks whether any of the given points is inside this box.
 
bool Overlaps (const plBoundingSphereTemplate< Type > &sphere) const
 Checks whether the given sphere overlaps with this box.
 
bool IsIdentical (const plBoundingBoxTemplate &rhs) const
 Checks whether this box and the other box are exactly identical.
 
bool IsEqual (const plBoundingBoxTemplate &rhs, Type fEpsilon=plMath::DefaultEpsilon< Type >()) const
 Checks whether this box and the other box are equal within some threshold.
 
void Translate (const plVec3Template< Type > &vDiff)
 Moves the box by the given vector.
 
void ScaleFromCenter (const plVec3Template< Type > &vScale)
 Scales the box along each axis, but keeps its center constant.
 
void ScaleFromOrigin (const plVec3Template< Type > &vScale)
 Scales the box's corners by the given factors, thus also moves the box around.
 
void TransformFromCenter (const plMat4Template< 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 plMat4Template< 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 plVec3Template< Type > GetClampedPoint (const plVec3Template< 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 plVec3Template< 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 plBoundingBoxTemplate &rhs) const
 Returns the minimum squared distance between the two boxes. Zero if the boxes overlap.
 
Type GetDistanceTo (const plVec3Template< 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 plBoundingSphereTemplate< Type > &sphere) const
 Returns the minimum distance between the box and the sphere. Zero or negative if both overlap.
 
Type GetDistanceTo (const plBoundingBoxTemplate &rhs) const
 Returns the minimum distance between the two boxes. Zero if the boxes overlap.
 
bool GetRayIntersection (const plVec3Template< Type > &vStartPos, const plVec3Template< Type > &vRayDir, Type *out_pIntersectionDistance=nullptr, plVec3Template< 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 plVec3Template< Type > &vStartPos, const plVec3Template< Type > &vEndPos, Type *out_pLineFraction=nullptr, plVec3Template< 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 plBoundingSphereTemplate< Type > GetBoundingSphere () const
 Returns a bounding sphere that encloses this box.
 

Static Public Member Functions

static plBoundingBoxTemplate< Type > MakeZero ()
 Creates a box that is located at the origin and has zero size. This is a 'valid' box.
 
static plBoundingBoxTemplate< 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 plBoundingBoxTemplate< Type > MakeFromCenterAndHalfExtents (const plVec3Template< Type > &vCenter, const plVec3Template< Type > &vHalfExtents)
 Creates a box from a center point and half-extents for each axis.
 
static plBoundingBoxTemplate< Type > MakeFromMinMax (const plVec3Template< Type > &vMin, const plVec3Template< Type > &vMax)
 Creates a box with the given minimum and maximum values.
 
static plBoundingBoxTemplate< Type > MakeFromPoints (const plVec3Template< Type > *pPoints, plUInt32 uiNumPoints, plUInt32 uiStride=sizeof(plVec3Template< 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

plVec3Template< Type > m_vMin
 
plVec3Template< Type > m_vMax
 

Detailed Description

template<typename Type>
class plBoundingBoxTemplate< 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: