![]() |
XII Release 0.1.0
|
An implementation of a bounding sphere. More...
#include <BoundingSphere.h>
Public Types | |
using | ComponentType = Type |
Public Member Functions | |
XII_DECLARE_POD_TYPE () | |
xiiBoundingSphereTemplate () | |
Default constructor does not initialize any data. | |
bool | IsZero (Type fEpsilon=xiiMath::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 xiiVec3Template< 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 xiiVec3Template< Type > *pPoints, xiiUInt32 uiNumPoints, xiiUInt32 uiStride=sizeof(xiiVec3Template< 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 xiiBoundingSphereTemplate &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 xiiBoundingBoxTemplate< 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 xiiBoundingSphereTemplate &rhs) const |
Tests whether two spheres are identical. | |
bool | IsEqual (const xiiBoundingSphereTemplate &rhs, Type fEpsilon=xiiMath::DefaultEpsilon< Type >()) const |
Tests whether two spheres are equal within some threshold. | |
void | Translate (const xiiVec3Template< 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 xiiVec3Template< Type > &vScale) |
Scales the sphere in world unites, meaning its center position will change as well. | |
void | TransformFromOrigin (const xiiMat4Template< 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 xiiMat4Template< 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 xiiVec3Template< 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 xiiBoundingSphereTemplate &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 xiiBoundingBoxTemplate< 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 xiiVec3Template< Type > *pPoints, xiiUInt32 uiNumPoints, xiiUInt32 uiStride=sizeof(xiiVec3Template< Type >)) const |
Returns the minimum distance of any of the points to the sphere. | |
bool | Contains (const xiiVec3Template< Type > &vPoint) const |
Returns true if the given point is inside the sphere. | |
bool | Contains (const xiiVec3Template< Type > *pPoints, xiiUInt32 uiNumPoints, xiiUInt32 uiStride=sizeof(xiiVec3Template< Type >)) const |
Returns whether all the given points are inside this sphere. | |
bool | Contains (const xiiBoundingSphereTemplate &rhs) const |
Returns whether the other sphere is completely inside this sphere. | |
bool | Contains (const xiiBoundingBoxTemplate< Type > &rhs) const |
Returns whether the given box is completely inside this sphere. | |
bool | Overlaps (const xiiVec3Template< Type > *pPoints, xiiUInt32 uiNumPoints, xiiUInt32 uiStride=sizeof(xiiVec3Template< Type >)) const |
Checks whether any of the given points is inside the sphere. | |
bool | Overlaps (const xiiBoundingSphereTemplate &rhs) const |
Checks whether the two objects overlap. | |
bool | Overlaps (const xiiBoundingBoxTemplate< Type > &rhs) const |
Checks whether the two objects overlap. | |
const xiiBoundingBoxTemplate< Type > | GetBoundingBox () const |
Returns a bounding box that encloses this sphere. | |
const xiiVec3Template< Type > | GetClampedPoint (const xiiVec3Template< 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 xiiVec3Template< Type > &vRayStartPos, const xiiVec3Template< Type > &vRayDir, Type *out_pIntersectionDistance=nullptr, xiiVec3Template< 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 xiiVec3Template< Type > &vLineStartPos, const xiiVec3Template< Type > &vLineEndPos, Type *out_pHitFraction=nullptr, xiiVec3Template< Type > *out_pIntersection=nullptr) const |
Returns true if the line segment intersects the sphere. | |
Static Public Member Functions | |
static xiiBoundingSphereTemplate< Type > | MakeZero () |
Creates a sphere at the origin with radius zero. | |
static xiiBoundingSphereTemplate< Type > | MakeInvalid (const xiiVec3Template< Type > &vCenter=xiiVec3Template< Type >::MakeZero()) |
Creates an 'invalid' sphere, with its center at the given position and a negative radius. | |
static xiiBoundingSphereTemplate< Type > | MakeFromCenterAndRadius (const xiiVec3Template< Type > &vCenter, Type fRadius) |
Creates a sphere with the provided center and radius. | |
static xiiBoundingSphereTemplate< Type > | MakeFromPoints (const xiiVec3Template< Type > *pPoints, xiiUInt32 uiNumPoints, xiiUInt32 uiStride=sizeof(xiiVec3Template< Type >)) |
Creates a bounding sphere around the provided points. | |
Public Attributes | |
xiiVec3Template< 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.
|
staticnodiscard |
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.
|
staticnodiscard |
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.