![]() |
ezEngine
Release 25.03
|
An implementation of a bounding sphere. More...
#include <BoundingSphere.h>
Public Types | |
using | ComponentType = Type |
Public Member Functions | |
EZ_DECLARE_POD_TYPE () | |
ezBoundingSphereTemplate () | |
Default constructor does not initialize any data. | |
bool | IsZero (Type fEpsilon=ezMath::DefaultEpsilon< Type >()) const |
Checks whether the sphere is all zero. | |
bool | IsValid () const |
Returns whether the sphere has valid values. | |
bool | IsNaN () const |
Returns whether any value is NaN. | |
void | ExpandToInclude (const ezVec3Template< Type > &vPoint) |
Increases the sphere's radius to include this point. Does NOT change its position, thus the resulting sphere might be not a very tight fit. | |
void | ExpandToInclude (const ezVec3Template< Type > *pPoints, ezUInt32 uiNumPoints, ezUInt32 uiStride=sizeof(ezVec3Template< Type >)) |
Increases the sphere's radius to include all given points. Does NOT change its position, thus the resulting sphere might be not a very tight fit. More efficient than calling this for every point individually. | |
void | ExpandToInclude (const ezBoundingSphereTemplate &rhs) |
Increases this sphere's radius, such that it encloses the other sphere. Does not change the center position of this sphere. | |
void | ExpandToInclude (const ezBoundingBoxTemplate< Type > &rhs) |
Increases this sphere's radius, such that it encloses the box. Does not change the center position of this sphere. | |
void | Grow (Type fDiff) |
Increases the size of the sphere by the given amount. | |
bool | IsIdentical (const ezBoundingSphereTemplate &rhs) const |
Tests whether two spheres are identical. | |
bool | IsEqual (const ezBoundingSphereTemplate &rhs, Type fEpsilon=ezMath::DefaultEpsilon< Type >()) const |
Tests whether two spheres are equal within some threshold. | |
void | Translate (const ezVec3Template< Type > &vTranslation) |
Moves the sphere by the given vector. | |
void | ScaleFromCenter (Type fScale) |
Scales the sphere's size, does not change its center position. | |
void | ScaleFromOrigin (const ezVec3Template< Type > &vScale) |
Scales the sphere in world unites, meaning its center position will change as well. | |
void | TransformFromOrigin (const ezMat4Template< Type > &mTransform) |
Transforms the sphere with the given matrix from the world origin. I.e. scalings and rotations will influence its position. | |
void | TransformFromCenter (const ezMat4Template< Type > &mTransform) |
Transforms the sphere with the given matrix from its own center. I.e. rotations have no effect, scalings will only affect the radius, and only translations will affect its position. | |
Type | GetDistanceTo (const ezVec3Template< Type > &vPoint) const |
Computes the distance of the point to the sphere's surface. Returns negative values for points inside the sphere. | |
Type | GetDistanceTo (const ezBoundingSphereTemplate &rhs) const |
Returns the distance between the two spheres. Zero for spheres that are exactly touching each other, negative values for overlapping spheres. | |
Type | GetDistanceTo (const ezBoundingBoxTemplate< Type > &rhs) const |
Returns the minimum distance between the box and the sphere. Zero if both are exactly touching, negative values if they overlap. | |
Type | GetDistanceTo (const ezVec3Template< Type > *pPoints, ezUInt32 uiNumPoints, ezUInt32 uiStride=sizeof(ezVec3Template< Type >)) const |
Returns the minimum distance of any of the points to the sphere. | |
bool | Contains (const ezVec3Template< Type > &vPoint) const |
Returns true if the given point is inside the sphere. | |
bool | Contains (const ezVec3Template< Type > *pPoints, ezUInt32 uiNumPoints, ezUInt32 uiStride=sizeof(ezVec3Template< Type >)) const |
Returns whether all the given points are inside this sphere. | |
bool | Contains (const ezBoundingSphereTemplate &rhs) const |
Returns whether the other sphere is completely inside this sphere. | |
bool | Contains (const ezBoundingBoxTemplate< Type > &rhs) const |
Returns whether the given box is completely inside this sphere. | |
bool | Overlaps (const ezVec3Template< Type > *pPoints, ezUInt32 uiNumPoints, ezUInt32 uiStride=sizeof(ezVec3Template< Type >)) const |
Checks whether any of the given points is inside the sphere. | |
bool | Overlaps (const ezBoundingSphereTemplate &rhs) const |
Checks whether the two objects overlap. | |
bool | Overlaps (const ezBoundingBoxTemplate< Type > &rhs) const |
Checks whether the two objects overlap. | |
const ezBoundingBoxTemplate< Type > | GetBoundingBox () const |
Returns a bounding box that encloses this sphere. | |
const ezVec3Template< Type > | GetClampedPoint (const ezVec3Template< Type > &vPoint) |
Clamps the given position to the volume of the sphere. The resulting point will always be inside the sphere, but have the closest distance to the original point. | |
bool | GetRayIntersection (const ezVec3Template< Type > &vRayStartPos, const ezVec3Template< Type > &vRayDir, Type *out_pIntersectionDistance=nullptr, ezVec3Template< Type > *out_pIntersection=nullptr) const |
Computes the intersection of a ray with this sphere. Returns true if there was an intersection. May optionally return the intersection time and position. The ray's direction must be normalized. The function will also return true, if the ray already starts inside the sphere, but it will still compute the intersection with the surface of the sphere. | |
bool | GetLineSegmentIntersection (const ezVec3Template< Type > &vLineStartPos, const ezVec3Template< Type > &vLineEndPos, Type *out_pHitFraction=nullptr, ezVec3Template< Type > *out_pIntersection=nullptr) const |
Returns true if the line segment intersects the sphere. | |
Static Public Member Functions | |
static ezBoundingSphereTemplate< Type > | MakeZero () |
Creates a sphere at the origin with radius zero. | |
static ezBoundingSphereTemplate< Type > | MakeInvalid (const ezVec3Template< Type > &vCenter=ezVec3Template< Type >::MakeZero()) |
Creates an 'invalid' sphere, with its center at the given position and a negative radius. More... | |
static ezBoundingSphereTemplate< Type > | MakeFromCenterAndRadius (const ezVec3Template< Type > &vCenter, Type fRadius) |
Creates a sphere with the provided center and radius. | |
static ezBoundingSphereTemplate< Type > | MakeFromPoints (const ezVec3Template< Type > *pPoints, ezUInt32 uiNumPoints, ezUInt32 uiStride=sizeof(ezVec3Template< Type >)) |
Creates a bounding sphere around the provided points. More... | |
Public Attributes | |
ezVec3Template< Type > | m_vCenter |
Type | m_fRadius |
An implementation of a bounding sphere.
This class allows to construct and manipulate bounding spheres. It also provides a large set of functions to do overlap queries, ray casts and other useful operations.
|
static |
Creates a bounding sphere around the provided points.
The center of the sphere will be at the 'center of mass' of all the points, and the radius will be the distance to the farthest point from there.
|
static |
Creates an 'invalid' sphere, with its center at the given position and a negative radius.
Such a sphere can be made 'valid' through ExpandToInclude(), but be aware that the originally provided center position will always be part of the sphere.