![]() |
ezEngine
Release 25.03
|
An axis-aligned bounding box implementation. More...
#include <BoundingBox.h>
Public Types | |
using | ComponentType = Type |
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. | |
bool | IsValid () const |
Checks whether the box is in an invalid state. | |
bool | IsNaN () const |
Checks whether any component is NaN. | |
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::DefaultEpsilon< Type >()) 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 in its local space. The center of the box does not change, unless the transform contains a translation. | |
void | TransformFromOrigin (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. | |
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 > &vRayDir, Type *out_pIntersectionDistance=nullptr, ezVec3Template< 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 ezVec3Template< Type > &vStartPos, const ezVec3Template< Type > &vEndPos, Type *out_pLineFraction=nullptr, ezVec3Template< 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 ezBoundingSphereTemplate< Type > | GetBoundingSphere () const |
Returns a bounding sphere that encloses this box. | |
Static Public Member Functions | |
static ezBoundingBoxTemplate< Type > | MakeZero () |
Creates a box that is located at the origin and has zero size. This is a 'valid' box. | |
static ezBoundingBoxTemplate< 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 ezBoundingBoxTemplate< Type > | MakeFromCenterAndHalfExtents (const ezVec3Template< Type > &vCenter, const ezVec3Template< Type > &vHalfExtents) |
Creates a box from a center point and half-extents for each axis. | |
static ezBoundingBoxTemplate< Type > | MakeFromMinMax (const ezVec3Template< Type > &vMin, const ezVec3Template< Type > &vMax) |
Creates a box with the given minimum and maximum values. | |
static ezBoundingBoxTemplate< Type > | MakeFromPoints (const ezVec3Template< Type > *pPoints, ezUInt32 uiNumPoints, ezUInt32 uiStride=sizeof(ezVec3Template< 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 | |
ezVec3Template< Type > | m_vMin |
ezVec3Template< Type > | m_vMax |
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.