ezEngine  Milestone 7
ezBoundingBoxTemplate< Type > Class Template Reference

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

#include <BoundingBox.h>

Public Types

typedef Type ComponentType
 

Public Member Functions

 EZ_DECLARE_POD_TYPE ()
 
 ezBoundingBoxTemplate ()
 Default constructor does not initialize anything.
 
 ezBoundingBoxTemplate (const ezVec3Template< Type > &vMin, const ezVec3Template< Type > &vMax)
 Constructs the box with the given minimum and maximum values.
 
void SetInvalid ()
 Resets the box to an invalid state. ExpandToInclude can then be used to make it into a bounding box for objects.
 
void SetCenterAndHalfExtents (const ezVec3Template< Type > &vCenter, const ezVec3Template< Type > &vHalfExtents)
 Sets the box from a center point and half-extents for each axis.
 
bool IsValid () const
 Checks whether the box is in an invalid state.
 
bool IsNaN () const
 Checks whether any component is NaN.
 
void SetElements (const ezVec3Template< Type > &vMin, const ezVec3Template< Type > &vMax)
 Directly sets the minimum and maximum values.
 
void SetFromPoints (const ezVec3Template< Type > *pPoints, ezUInt32 uiNumPoints, ezUInt32 uiStride=sizeof(ezVec3Template< Type >))
 Creates a new bounding-box around the given set of points.
 
void GetCorners (ezVec3Template< Type > *out_pCorners) const
 Writes the 8 different corners of the box to the given array.
 
const ezVec3Template< Type > GetCenter () const
 Returns the center position of the box.
 
const ezVec3Template< Type > GetExtents () const
 Returns the extents of the box along each axis.
 
const ezVec3Template< Type > GetHalfExtents () const
 Returns the half extents of the box along each axis.
 
void ExpandToInclude (const ezVec3Template< Type > &vPoint)
 Expands the box such that the given point is inside it.
 
void ExpandToInclude (const ezBoundingBoxTemplate &rhs)
 Expands the box such that the given box is inside it.
 
void ExpandToInclude (const ezVec3Template< Type > *pPoints, ezUInt32 uiNumPoints, ezUInt32 uiStride=sizeof(ezVec3Template< 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 ezVec3Template< Type > &vDiff)
 Will increase the size of the box in all directions by the given amount (per axis).
 
bool Contains (const ezVec3Template< Type > &vPoint) const
 Checks whether the given point is inside the box.
 
bool Contains (const ezBoundingBoxTemplate &rhs) const
 Checks whether the given box is completely inside this box.
 
bool Contains (const ezVec3Template< Type > *pPoints, ezUInt32 uiNumPoints, ezUInt32 uiStride=sizeof(ezVec3Template< Type >)) const
 Checks whether all the given points are inside this box.
 
bool Contains (const ezBoundingSphereTemplate< Type > &sphere) const
 Checks whether the given sphere is completely inside this box.
 
bool Overlaps (const ezBoundingBoxTemplate &rhs) const
 Checks whether this box overlaps with the given box.
 
bool Overlaps (const ezVec3Template< Type > *pPoints, ezUInt32 uiNumPoints, ezUInt32 uiStride=sizeof(ezVec3Template< Type >)) const
 Checks whether any of the given points is inside this box.
 
bool Overlaps (const ezBoundingSphereTemplate< Type > &sphere) const
 Checks whether the given sphere overlaps with this box.
 
bool IsIdentical (const ezBoundingBoxTemplate &rhs) const
 Checks whether this box and the other box are exactly identical.
 
bool IsEqual (const ezBoundingBoxTemplate &rhs, Type fEpsilon=ezMath::BasicType< Type >::DefaultEpsilon()) const
 Checks whether this box and the other box are equal within some threshold.
 
void Translate (const ezVec3Template< Type > &vDiff)
 Moves the box by the given vector.
 
void ScaleFromCenter (const ezVec3Template< Type > &vScale)
 Scales the box along each axis, but keeps its center constant.
 
void ScaleFromOrigin (const ezVec3Template< Type > &vScale)
 Scales the box's corners by the given factors, thus also moves the box around.
 
void TransformFromCenter (const ezMat4Template< 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.
 
void TransformFromOrigin (const ezMat4Template< 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.
 
const ezVec3Template< Type > GetClampedPoint (const ezVec3Template< 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 ezVec3Template< 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 ezBoundingBoxTemplate &rhs) const
 Returns the minimum squared distance between the two boxes. Zero if the boxes overlap.
 
Type GetDistanceTo (const ezVec3Template< 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 ezBoundingSphereTemplate< Type > &sphere) const
 Returns the minimum distance between the box and the sphere. Zero or negative if both overlap.
 
Type GetDistanceTo (const ezBoundingBoxTemplate &rhs) const
 Returns the minimum distance between the two boxes. Zero if the boxes overlap.
 
bool GetRayIntersection (const ezVec3Template< Type > &vStartPos, const ezVec3Template< Type > &vRayDirNormalized, Type *out_fIntersection=nullptr, ezVec3Template< Type > *out_vIntersection=nullptr) const
 Returns whether the given ray intersects the box. Optionally returns the intersection distance and position.
 
bool GetLineSegmentIntersection (const ezVec3Template< Type > &vStartPos, const ezVec3Template< Type > &vEndPos, Type *out_fLineFraction=nullptr, ezVec3Template< Type > *out_vIntersection=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 ezBoundingSphereTemplate
< Type > 
GetBoundingSphere () const
 Returns a bounding sphere that encloses this box.
 

Public Attributes

ezVec3Template< Type > m_vMin
 
ezVec3Template< Type > m_vMax
 

Detailed Description

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