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