Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::Sphere< T > Class Template Reference

Math class that represents a sphere "S2" in a three dimensional euclidean space. More...

Public Member Functions

 Sphere (T X, T Y, T Z, T Radius)
 Constructs a Sphere object from its center position and radius. More...
 
 Sphere (const Vector3< T > &center, T Radius)
 Constructs a Sphere object from its position and radius. More...
 
 Sphere (const T sphere[4])
 Constructs a Sphere object from an array of four elements. More...
 
template<typename U >
 Sphere (const Sphere< U > &sphere)
 Constructs a Sphere object from another type of Sphere. More...
 
 Sphere (const Sphere &sphere)=default
 
bool Contains (T X, T Y, T Z) const
 Tests whether the sphere contains the provided point inclusive of the edge of the sphere. More...
 
bool Contains (const Box< T > &box) const
 Tests whether the sphere contains the provided box inclusive of the edge of the sphere. More...
 
bool Contains (const Vector3< T > &point) const
 Tests whether the sphere contains the provided point inclusive of the edge of the sphere. More...
 
Distance (T X, T Y, T Z) const
 Returns the distance from the sphere to the point (is negative when the point is inside the sphere) More...
 
Distance (const Vector3< T > &point) const
 Returns the distance from the sphere to the point (is negative when the point is inside the sphere) More...
 
SphereExtendTo (T X, T Y, T Z)
 Extends the sphere to contain the point in the boundary. More...
 
SphereExtendTo (const Vector3< T > &point)
 Extends the sphere to contain the point in the boundary. More...
 
Vector3< T > GetNegativeVertex (const Vector3< T > &normal) const
 Computes the negative vertex of one direction. More...
 
Vector3< T > GetPosition () const
 Gets a Vector3 of the position. More...
 
Vector3< T > GetPositiveVertex (const Vector3< T > &normal) const
 Computes the positive vertex of one direction. More...
 
bool Intersect (const Box< T > &box) const
 Checks whether or not this sphere intersects a box. More...
 
bool Intersect (const Sphere &sphere) const
 Checks whether or not this sphere intersects another sphere. More...
 
bool IsValid () const
 Checks whether this sphere is valid. More...
 
SphereMakeUnit ()
 Makes the sphere position (0, 0, 0) and radius 1. More...
 
SphereMakeZero ()
 Makes the sphere position (0, 0, 0) and radius 0. More...
 
SphereSet (T X, T Y, T Z, T Radius)
 Sets the components of the sphere with center and radius. More...
 
SphereSet (const Sphere &sphere)
 Sets the components of the sphere with center and radius from another. More...
 
SphereSet (const Vector3< T > &center, T Radius)
 Sets the components of the sphere with center and radius. More...
 
SphereSet (const T sphere[4])
 Sets the components of the sphere from an array of four elements. More...
 
template<typename U >
SphereSet (const Sphere< U > &sphere)
 
String ToString () const
 Gives a string representation. More...
 
T & operator[] (std::size_t i)
 Returns the ith element of the sphere. More...
 
operator[] (std::size_t i) const
 Returns the ith element of the sphere. More...
 
Sphere operator* (T scalar) const
 Multiplies the radius of the sphere with a scalar. More...
 
Sphereoperator= (const Sphere &other)=default
 
Sphereoperator*= (T scalar)
 Multiplies the radius of other sphere with a scalar. More...
 
bool operator== (const Sphere &sphere) const
 Compares the sphere to other one. More...
 
bool operator!= (const Sphere &sphere) const
 Compares the sphere to other one. More...
 
template<typename U >
Sphere< T > & Set (const Sphere< U > &sphere)
 Sets the components of the sphere from another type of Sphere. More...
 

Static Public Member Functions

static Sphere Lerp (const Sphere &from, const Sphere &to, T interpolation)
 Interpolates the sphere to other one with a factor of interpolation. More...
 
static Sphere Unit ()
 Shorthand for the sphere (0, 0, 0, 1) More...
 
static Sphere Zero ()
 Shorthand for the sphere (0, 0, 0, 0) More...
 

Public Attributes

x
 
y
 
z
 
radius
 

Detailed Description

template<typename T>
class Nz::Sphere< T >

Math class that represents a sphere "S2" in a three dimensional euclidean space.

Constructor & Destructor Documentation

◆ Sphere() [1/4]

template<typename T>
Nz::Sphere< T >::Sphere ( X,
Y,
Z,
Radius 
)

Constructs a Sphere object from its center position and radius.

Parameters
XX position
YY position
ZZ position
Radiushalf of the diameter

◆ Sphere() [2/4]

template<typename T>
Nz::Sphere< T >::Sphere ( const Vector3< T > &  center,
Radius 
)

Constructs a Sphere object from its position and radius.

Parameters
centerCenter of the sphere
RadiusHalf of the diameter

◆ Sphere() [3/4]

template<typename T>
Nz::Sphere< T >::Sphere ( const T  sphere[4])

Constructs a Sphere object from an array of four elements.

Parameters
sphere[4]sphere[0] is X component, sphere[1] is Y component, sphere[2] is Z component and sphere[3] is radius

◆ Sphere() [4/4]

template<typename T >
template<typename U >
Nz::Sphere< T >::Sphere ( const Sphere< U > &  sphere)
explicit

Constructs a Sphere object from another type of Sphere.

Parameters
sphereSphere of type U to convert to type T

Member Function Documentation

◆ Contains() [1/3]

template<typename T>
bool Nz::Sphere< T >::Contains ( X,
Y,
Z 
) const

Tests whether the sphere contains the provided point inclusive of the edge of the sphere.

Returns
true if inclusive
Parameters
XX position of the point
YY position of the point
ZZ position of the point
See also
Contains

◆ Contains() [2/3]

template<typename T>
bool Nz::Sphere< T >::Contains ( const Box< T > &  box) const

Tests whether the sphere contains the provided box inclusive of the edge of the sphere.

Returns
true if all inclusive
Parameters
boxThree dimensional box
See also
Contains

◆ Contains() [3/3]

template<typename T>
bool Nz::Sphere< T >::Contains ( const Vector3< T > &  point) const

Tests whether the sphere contains the provided point inclusive of the edge of the sphere.

Returns
true if inclusive
Parameters
pointPosition of the point

◆ Distance() [1/2]

template<typename T>
T Nz::Sphere< T >::Distance ( X,
Y,
Z 
) const

Returns the distance from the sphere to the point (is negative when the point is inside the sphere)

Returns
Distance to the point
Parameters
XX position of the point
YY position of the point
ZZ position of the point

◆ Distance() [2/2]

template<typename T>
T Nz::Sphere< T >::Distance ( const Vector3< T > &  point) const

Returns the distance from the sphere to the point (is negative when the point is inside the sphere)

Returns
Distance to the point
Parameters
pointPosition of the point

◆ ExtendTo() [1/2]

template<typename T>
Sphere< T > & Nz::Sphere< T >::ExtendTo ( X,
Y,
Z 
)

Extends the sphere to contain the point in the boundary.

Returns
A reference to this sphere extended
Parameters
XX position of the point
YY position of the point
ZZ position of the point
See also
ExtendTo

◆ ExtendTo() [2/2]

template<typename T>
Sphere< T > & Nz::Sphere< T >::ExtendTo ( const Vector3< T > &  point)

Extends the sphere to contain the point in the boundary.

Returns
A reference to this sphere extended
Parameters
pointPosition of the point
See also
ExtendTo

◆ GetNegativeVertex()

template<typename T>
Vector3< T > Nz::Sphere< T >::GetNegativeVertex ( const Vector3< T > &  normal) const

Computes the negative vertex of one direction.

Returns
The position of the vertex on the sphere in the opposite way of the normal while considering the center
Parameters
normalVector normalized indicating a direction
See also
GetPositiveVertex

◆ GetPosition()

template<typename T >
Vector3< T > Nz::Sphere< T >::GetPosition ( ) const

Gets a Vector3 of the position.

Returns
The position of the center of the sphere

◆ GetPositiveVertex()

template<typename T>
Vector3< T > Nz::Sphere< T >::GetPositiveVertex ( const Vector3< T > &  normal) const

Computes the positive vertex of one direction.

Returns
The position of the vertex on the sphere in the same way of the normal while considering the center
Parameters
normalVector normalized indicating a direction
See also
GetNegativeVertex

◆ Intersect() [1/2]

template<typename T>
bool Nz::Sphere< T >::Intersect ( const Box< T > &  box) const

Checks whether or not this sphere intersects a box.

Returns
true if the box intersects
Parameters
boxBox to check

◆ Intersect() [2/2]

template<typename T>
bool Nz::Sphere< T >::Intersect ( const Sphere< T > &  sphere) const

Checks whether or not this sphere intersects another sphere.

Returns
true if the spheres intersect or if one is in the other
Parameters
sphereSphere to check

◆ IsValid()

template<typename T >
bool Nz::Sphere< T >::IsValid ( ) const

Checks whether this sphere is valid.

Returns
true if the sphere has a strictly positive radius

◆ Lerp()

template<typename T>
Sphere< T > Nz::Sphere< T >::Lerp ( const Sphere< T > &  from,
const Sphere< T > &  to,
interpolation 
)
static

Interpolates the sphere to other one with a factor of interpolation.

Returns
A new sphere which is the interpolation of two spheres
Parameters
fromInitial sphere
toTarget sphere
interpolationFactor of interpolation
Remarks
interpolation is meant to be between 0 and 1, other values are potentially undefined behavior
With NAZARA_DEBUG, a NazaraError is thrown and Zero() is returned
See also
Lerp

◆ MakeUnit()

template<typename T >
Sphere< T > & Nz::Sphere< T >::MakeUnit ( )

Makes the sphere position (0, 0, 0) and radius 1.

Returns
A reference to this vector with position (0, 0, 0) and radius 1
See also
Unit

◆ MakeZero()

template<typename T >
Sphere< T > & Nz::Sphere< T >::MakeZero ( )

Makes the sphere position (0, 0, 0) and radius 0.

Returns
A reference to this vector with position (0, 0, 0) and radius 0
See also
Zero

◆ operator!=()

template<typename T >
bool Nz::Sphere< T >::operator!= ( const Sphere< T > &  sphere) const

Compares the sphere to other one.

Returns
false if the spheres are the same
Parameters
sphereOther sphere to compare with

◆ operator*()

template<typename T>
Sphere< T > Nz::Sphere< T >::operator* ( scalar) const

Multiplies the radius of the sphere with a scalar.

Returns
A sphere where the center is the same and radius is the product of this radius and the scalar
Parameters
scaleThe scalar to multiply radius with

◆ operator*=()

template<typename T>
Sphere< T > & Nz::Sphere< T >::operator*= ( scalar)

Multiplies the radius of other sphere with a scalar.

Returns
A reference to this sphere where the center is the same and radius is the product of this radius and the scalar
Parameters
scaleThe scalar to multiply radius with

◆ operator==()

template<typename T >
bool Nz::Sphere< T >::operator== ( const Sphere< T > &  sphere) const

Compares the sphere to other one.

Returns
true if the spheres are the same
Parameters
sphereOther sphere to compare with

◆ operator[]() [1/2]

template<typename T >
T & Nz::Sphere< T >::operator[] ( std::size_t  i)

Returns the ith element of the sphere.

Returns
A reference to the ith element of the sphere
Remarks
Access to index greater than 4 is undefined behavior
Produce a NazaraError if you try to access to index greater than 4 with NAZARA_MATH_SAFE defined
Exceptions
std::domain_errorif NAZARA_MATH_SAFE is defined and one of you try to acces to index greather than 4

◆ operator[]() [2/2]

template<typename T >
T Nz::Sphere< T >::operator[] ( std::size_t  i) const

Returns the ith element of the sphere.

Returns
A value to the ith element of the sphere
Remarks
Access to index greater than 4 is undefined behavior
Produce a NazaraError if you try to access to index greater than 4 with NAZARA_MATH_SAFE defined
Exceptions
std::domain_errorif NAZARA_MATH_SAFE is defined and one of you try to acces to index greather than 4

◆ Set() [1/5]

template<typename T>
Sphere< T > & Nz::Sphere< T >::Set ( X,
Y,
Z,
Radius 
)

Sets the components of the sphere with center and radius.

Returns
A reference to this sphere
Parameters
XX position
YY position
ZZ position
Radiushalf of the diameter

◆ Set() [2/5]

template<typename T>
Sphere< T > & Nz::Sphere< T >::Set ( const Sphere< T > &  sphere)

Sets the components of the sphere with center and radius from another.

Returns
A reference to this sphere
Parameters
sphereThe other sphere

◆ Set() [3/5]

template<typename T>
Sphere< T > & Nz::Sphere< T >::Set ( const Vector3< T > &  center,
Radius 
)

Sets the components of the sphere with center and radius.

Returns
A reference to this sphere
Parameters
centerCenter of the sphere
RadiusHalf of the diameter

◆ Set() [4/5]

template<typename T>
Sphere< T > & Nz::Sphere< T >::Set ( const T  sphere[4])

Sets the components of the sphere from an array of four elements.

Returns
A reference to this sphere
Parameters
sphere[4]sphere[0] is X position, sphere[1] is Y position, sphere[2] is Z position and sphere[3] is radius

◆ Set() [5/5]

template<typename T>
template<typename U >
Sphere<T>& Nz::Sphere< T >::Set ( const Sphere< U > &  sphere)

Sets the components of the sphere from another type of Sphere.

Returns
A reference to this sphere
Parameters
sphereSphere of type U to convert its components

◆ ToString()

template<typename T >
String Nz::Sphere< T >::ToString ( ) const

Gives a string representation.

Returns
A string representation of the object: "Sphere(x, y, z; radius)"

◆ Unit()

template<typename T >
Sphere< T > Nz::Sphere< T >::Unit ( )
static

Shorthand for the sphere (0, 0, 0, 1)

Returns
A sphere with center (0, 0, 0) and radius 1
See also
MakeUnit

◆ Zero()

template<typename T >
Sphere< T > Nz::Sphere< T >::Zero ( )
static

Shorthand for the sphere (0, 0, 0, 0)

Returns
A sphere with center (0, 0, 0) and radius 0
See also
MakeZero

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