CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Math::TSphere< T > Struct Template Reference

A sphere represented by a center point and a radius. More...

#include <CeresEngine/Math/Geometry.hpp>

Public Member Functions

 TSphere ()=default
 Default constructor. Creates a unit sphere around the origin.
 
 TSphere (const TVector3< T > &center, T radius)
 
 TSphere (const TAABox< T > &box)
 
void merge (const TSphere &rhs)
 Merges the two spheres, creating a new sphere that encapsulates them both.
 
void merge (const TVector3< T > &point)
 Expands the sphere so it includes the provided point.
 
void transform (const TMatrix4< T > &matrix)
 Transforms the sphere by the given matrix.
 
void transform (const TTransform< T > &aTransform)
 Transforms the sphere by the given matrix.
 
bool contains (const TVector3< T > &v) const
 Returns whether or not this sphere contains the provided point.
 
bool contains (const TAABox< T > &box) const
 Returns whether or not this sphere contains the provided box.
 
bool intersects (const TSphere &s) const
 Returns whether or not this sphere intersects another sphere.
 
bool intersects (const TAABox< T > &box) const
 Returns whether or not this sphere intersects a box.
 
bool intersects (const TPlane< T > &plane) const
 Returns whether or not this sphere intersects a plane.
 
TRayIntersection< T > intersects (const TRay< T > &ray, bool discardInside=true) const
 Ray/sphere intersection, returns boolean result and distance to nearest intersection.
 
distance (const TVector3< T > &point) const
 Calculates the minimum distance between the sphere and the given point.
 
distance (const TSphere< T > &sphere) const
 Calculates the minimum distance between two spheres.
 

Public Attributes

radius = T(1.0)
 The radius of the sphere.
 
TVector3< T > center = TVector3<T>(T(0.0))
 The center point of the sphere.
 

Static Public Attributes

static const TSphere empty
 
static const TSphere unit
 
static const TSphere infinity
 

Friends

TSphere operator+ (TSphere lhs, const TSphere &rhs)
 Merges the two spheres, creating a new sphere that encapsulates them both.
 
TSphereoperator+= (TSphere &lhs, const TSphere &rhs)
 Merges the two spheres, creating a new sphere that encapsulates them both.
 
TSphere operator+ (TSphere lhs, const TVector3< T > &rhs)
 Expands the sphere so it includes the provided point.
 
TSphereoperator+= (TSphere &lhs, const TVector3< T > &rhs)
 Expands the sphere so it includes the provided point.
 
TSphere operator* (const TMatrix4< T > &lhs, TSphere rhs)
 Transforms the sphere by the given matrix.
 
TSphere operator* (const TTransform< T > &lhs, TSphere rhs)
 Transforms the sphere by the given matrix.
 

Detailed Description

template<typename T>
struct Math::TSphere< T >

A sphere represented by a center point and a radius.

Constructor & Destructor Documentation

◆ TSphere() [1/3]

template<typename T >
Math::TSphere< T >::TSphere ( )
default

Default constructor. Creates a unit sphere around the origin.

◆ TSphere() [2/3]

template<typename T >
Math::TSphere< T >::TSphere ( const TVector3< T > &  center,
radius 
)
inline

◆ TSphere() [3/3]

template<typename T >
Math::TSphere< T >::TSphere ( const TAABox< T > &  box)
inlineexplicit

Member Function Documentation

◆ contains() [1/2]

template<typename T >
bool Math::TSphere< T >::contains ( const TAABox< T > &  box) const

Returns whether or not this sphere contains the provided box.

◆ contains() [2/2]

template<typename T >
bool Math::TSphere< T >::contains ( const TVector3< T > &  v) const

Returns whether or not this sphere contains the provided point.

◆ distance() [1/2]

template<typename T >
T Math::TSphere< T >::distance ( const TSphere< T > &  sphere) const

Calculates the minimum distance between two spheres.

◆ distance() [2/2]

template<typename T >
T Math::TSphere< T >::distance ( const TVector3< T > &  point) const

Calculates the minimum distance between the sphere and the given point.

◆ intersects() [1/4]

template<typename T >
bool Math::TSphere< T >::intersects ( const TAABox< T > &  box) const

Returns whether or not this sphere intersects a box.

◆ intersects() [2/4]

template<typename T >
bool Math::TSphere< T >::intersects ( const TPlane< T > &  plane) const

Returns whether or not this sphere intersects a plane.

◆ intersects() [3/4]

template<typename T >
TRayIntersection< T > Math::TSphere< T >::intersects ( const TRay< T > &  ray,
bool  discardInside = true 
) const

Ray/sphere intersection, returns boolean result and distance to nearest intersection.

Parameters
rayRay to intersect with the sphere.
discardInsideIf true the intersection will be discarded if ray origin is located within the sphere.

◆ intersects() [4/4]

template<typename T >
bool Math::TSphere< T >::intersects ( const TSphere< T > &  s) const

Returns whether or not this sphere intersects another sphere.

◆ merge() [1/2]

template<typename T >
void Math::TSphere< T >::merge ( const TSphere< T > &  rhs)

Merges the two spheres, creating a new sphere that encapsulates them both.

◆ merge() [2/2]

template<typename T >
void Math::TSphere< T >::merge ( const TVector3< T > &  point)

Expands the sphere so it includes the provided point.

◆ transform() [1/2]

template<typename T >
void Math::TSphere< T >::transform ( const TMatrix4< T > &  matrix)

Transforms the sphere by the given matrix.

◆ transform() [2/2]

template<typename T >
void Math::TSphere< T >::transform ( const TTransform< T > &  aTransform)
inline

Transforms the sphere by the given matrix.

Friends And Related Symbol Documentation

◆ operator* [1/2]

template<typename T >
TSphere operator* ( const TMatrix4< T > &  lhs,
TSphere< T >  rhs 
)
friend

Transforms the sphere by the given matrix.

◆ operator* [2/2]

template<typename T >
TSphere operator* ( const TTransform< T > &  lhs,
TSphere< T >  rhs 
)
friend

Transforms the sphere by the given matrix.

◆ operator+ [1/2]

template<typename T >
TSphere operator+ ( TSphere< T >  lhs,
const TSphere< T > &  rhs 
)
friend

Merges the two spheres, creating a new sphere that encapsulates them both.

◆ operator+ [2/2]

template<typename T >
TSphere operator+ ( TSphere< T >  lhs,
const TVector3< T > &  rhs 
)
friend

Expands the sphere so it includes the provided point.

◆ operator+= [1/2]

template<typename T >
TSphere & operator+= ( TSphere< T > &  lhs,
const TSphere< T > &  rhs 
)
friend

Merges the two spheres, creating a new sphere that encapsulates them both.

◆ operator+= [2/2]

template<typename T >
TSphere & operator+= ( TSphere< T > &  lhs,
const TVector3< T > &  rhs 
)
friend

Expands the sphere so it includes the provided point.

Member Data Documentation

◆ center

template<typename T >
TVector3<T> Math::TSphere< T >::center = TVector3<T>(T(0.0))

The center point of the sphere.

◆ empty

template<typename T >
const TSphere Math::TSphere< T >::empty
static

◆ infinity

template<typename T >
const TSphere Math::TSphere< T >::infinity
static

◆ radius

template<typename T >
T Math::TSphere< T >::radius = T(1.0)

The radius of the sphere.

◆ unit

template<typename T >
const TSphere Math::TSphere< T >::unit
static

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