Open 3D Engine EMotionFX Gem API Reference  24.09
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
MCore::BoundingSphere Class Reference

#include <BoundingSphere.h>

Public Member Functions

MCORE_INLINE BoundingSphere ()
 
MCORE_INLINE BoundingSphere (const AZ::Vector3 &pos, float rad)
 
MCORE_INLINE BoundingSphere (const AZ::Vector3 &pos, float rad, float radSq)
 
MCORE_INLINE void Init ()
 
MCORE_INLINE void EncapsulateFast (const AZ::Vector3 &v)
 
MCORE_INLINE bool Contains (const AZ::Vector3 &v)
 
MCORE_INLINE bool Contains (const BoundingSphere &s) const
 
MCORE_INLINE bool Intersects (const BoundingSphere &s) const
 
MCORE_INLINE float GetRadius () const
 
MCORE_INLINE float GetRadiusSquared () const
 
MCORE_INLINE const AZ::Vector3 & GetCenter () const
 
MCORE_INLINE void SetCenter (const AZ::Vector3 &center)
 
MCORE_INLINE void SetRadius (float radius)
 

Detailed Description

A 3D bounding sphere class. This template represents a 3D bounding sphere, which has a center point and a radius. This type of bounding volume can be used to speedup collision detection or (ray) intersection tests or visibility tests.

Constructor & Destructor Documentation

◆ BoundingSphere() [1/3]

MCORE_INLINE MCore::BoundingSphere::BoundingSphere ( )
inline

Default constructor. Sets the sphere center to (0,0,0) and makes the radius 0.

◆ BoundingSphere() [2/3]

MCORE_INLINE MCore::BoundingSphere::BoundingSphere ( const AZ::Vector3 &  pos,
float  rad 
)
inline

Constructor which sets the center of the sphere and it's radius. Automatically calculates the squared radius too.

Parameters
posThe center position of the sphere.
radThe radius of the sphere.

◆ BoundingSphere() [3/3]

MCORE_INLINE MCore::BoundingSphere::BoundingSphere ( const AZ::Vector3 &  pos,
float  rad,
float  radSq 
)
inline

Constructor which sets the center, radius and squared radius. Use this constructor when the squared radius is already known, so an extra multiplication is eliminated.

Parameters
posThe center position of the sphere.
radThe radius of the sphere.
radSqThe squared radius of the sphere (rad*rad).

Member Function Documentation

◆ Contains() [1/2]

MCORE_INLINE bool MCore::BoundingSphere::Contains ( const AZ::Vector3 &  v)
inline

Check if the sphere contains a given 3D point. Note that the border of the sphere is also counted as inside.

Parameters
vThe vector representing the 3D point to perform the test with.
Returns
Returns true when 'v' is inside the spheres volume, otherwise false is returned.

◆ Contains() [2/2]

MCORE_INLINE bool MCore::BoundingSphere::Contains ( const BoundingSphere s) const
inline

Check if the sphere COMPLETELY contains a given other sphere. Note that the border of the sphere is also counted as inside.

Parameters
sThe sphere to perform the test with.
Returns
Returns true when 's' is completely inside this sphere. False is returned in any other case.

◆ EncapsulateFast()

MCORE_INLINE void MCore::BoundingSphere::EncapsulateFast ( const AZ::Vector3 &  v)
inline

Encapsulate a 3D point to the sphere. Automatically adjusts the radius of the sphere. Only use this method when the center of the sphere is already known. This is the faster way of encapsulating. But again, only use this method when the center of the sphere is known upfront and won't change. If the center of the sphere should automatically adjust as well, use the Encapsulate method instead (of course that's slower too).

Parameters
vThe vector representing the 3D point to encapsulate (add) to the sphere.

◆ GetCenter()

MCORE_INLINE const AZ::Vector3& MCore::BoundingSphere::GetCenter ( ) const
inline

Get the center of the sphere. So the position of the sphere.

Returns
Returns the center position of the sphere.

◆ GetRadius()

MCORE_INLINE float MCore::BoundingSphere::GetRadius ( ) const
inline

Get the radius of the sphere.

Returns
Returns the radius of the sphere.

◆ GetRadiusSquared()

MCORE_INLINE float MCore::BoundingSphere::GetRadiusSquared ( ) const
inline

Get the squared radius of the sphere.

Returns
Returns the squared radius of the sphere (no calculations done for this), since it's already known.

◆ Init()

MCORE_INLINE void MCore::BoundingSphere::Init ( )
inline

Initialize the spheres center, radius and square radius. This will set the center position to (0,0,0) and both the radius and squared radius to 0. Call this method when you want to reset the sphere. Note that this is already done by the default constructor.

◆ Intersects()

MCORE_INLINE bool MCore::BoundingSphere::Intersects ( const BoundingSphere s) const
inline

Check if a given sphere intersects with this sphere. Note that the border of this sphere is counted as 'inside'. So if only the borders of the spheres intersects, this is seen as intersection.

Parameters
sThe sphere to perform the intersection test with.
Returns
Returns true when 's' intersects this sphere. So if it's partially or completely inside this sphere or if the borders overlap.

◆ SetCenter()

MCORE_INLINE void MCore::BoundingSphere::SetCenter ( const AZ::Vector3 &  center)
inline

Set the center of the sphere.

Parameters
centerThe center position of the sphere.

◆ SetRadius()

MCORE_INLINE void MCore::BoundingSphere::SetRadius ( float  radius)
inline

Set the radius of the sphere. The squared radius will automatically be updated inside this method.

Parameters
radiusThe radius of the sphere.

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