ezEngine  Milestone 7
ezBoundingSphereTemplate< Type > Class Template Reference

An implementation of a bounding sphere. More...

#include <BoundingSphere.h>

Public Types

typedef Type ComponentType
 

Public Member Functions

 EZ_DECLARE_POD_TYPE ()
 
 ezBoundingSphereTemplate ()
 Default constructor does not initialize any data.
 
 ezBoundingSphereTemplate (const ezVec3Template< Type > &vCenter, Type fRadius)
 Creates a sphere with the given radius around the given center.
 
void SetZero ()
 Sets all elements to Zero. The sphere is thus 'valid'.
 
bool IsZero (Type fEpsilon=ezMath::BasicType< Type >::DefaultEpsilon()) const
 Checks whether the sphere is all zero.
 
void SetInvalid ()
 Sets the bounding sphere to invalid values.
 
bool IsValid () const
 Returns whether the sphere has valid values.
 
bool IsNaN () const
 Returns whether any value is NaN.
 
void SetElements (const ezVec3Template< Type > &vCenter, Type fRadius)
 Sets the sphere to the given values.
 
void SetFromPoints (const ezVec3Template< Type > *pPoints, ezUInt32 uiNumPoints, ezUInt32 uiStride=sizeof(ezVec3Template< Type >))
 Initializes the sphere to be the bounding sphere of all the given points (not necessarily the smallest one).
 
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::BasicType< Type >::DefaultEpsilon()) 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_fIntersection=nullptr, ezVec3Template< Type > *out_vIntersection=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_fHitFraction=nullptr, ezVec3Template< Type > *out_vIntersection=nullptr) const
 Returns true if the line segment intersects the sphere.
 

Public Attributes

ezVec3Template< Type > m_vCenter
 
Type m_fRadius
 

Detailed Description

template<typename Type>
class ezBoundingSphereTemplate< Type >

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.


The documentation for this class was generated from the following files: