SA_Maths
Sapphire Suite's C++ Maths Library
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
SA::Vec3< T > Struct Template Reference

Vector 3 Sapphire-Maths class. More...

#include <Vector3.hpp>

Public Types

using Type = T
 Type of the Vector.
 

Public Member Functions

 Vec3 ()=default
 Default constructor.
 
constexpr Vec3 (T _x, T _y, T _z) noexcept
 Value constructor.
 
constexpr Vec3 (T _scale) noexcept
 Scale Value constructor.
 
 Vec3 (Vec3 &&)=default
 Default move constructor.
 
 Vec3 (const Vec3 &)=default
 Default copy constructor.
 
template<typename TIn >
constexpr Vec3 (const Vec3< TIn > &_other) noexcept
 Value constructor from another Vec3 type.
 
template<typename TIn >
constexpr Vec3 (const Vec2< TIn > &_other, T _z=T(0)) noexcept
 Value constructor from Vec2.
 
template<typename TIn >
constexpr Vec3 (const Vec4< TIn > &_other) noexcept
 Value constructor from Vec4.
 
constexpr bool IsZero () const noexcept
 Whether this vector is a zero vector.
 
constexpr bool Equals (const Vec3 &_other, T _epsilon=std::numeric_limits< T >::epsilon()) const noexcept
 Compare 2 vector.
 
constexpr bool operator== (const Vec3 &_rhs) const noexcept
 Compare 2 vector equality.
 
constexpr bool operator!= (const Vec3 &_rhs) const noexcept
 Compare 2 vector inequality.
 
T * Data () noexcept
 Getter of vector data
 
const T * Data () const noexcept
  Const Getter of vector data
 
T & operator[] (uint32_t _index)
 Access operator by index: x, y, z using 0, 1, 2.
 
const T & operator[] (uint32_t _index) const
  Const Access operator by index: x, y, z using 0, 1, 2.
 
constexpr T Length () const
 Getter of the length of this vector.
 
constexpr T SqrLength () const noexcept
 Getter of the Squared Length of this vector.
 
Vec3Normalize ()
 Normalize this vector.
 
Vec3 GetNormalized () const
 Normalize this vector.
 
constexpr bool IsNormalized () const noexcept
 Whether this vector is normalized.
 
Vec3 Reflect (const Vec3 &_normal, float _elasticity=1.0f) const noexcept
 Reflect this vector over the normal.
 
Vec3 ProjectOnTo (const Vec3 &_other) const noexcept
 Project this vector onto an other vector.
 
Vec3 ProjectOnToNormal (const Vec3 &_normal) const noexcept
 Project this vector onto s normal.
 
Vec3operator= (Vec3 &&)=default
 Default assignment move operator.
 
Vec3operator= (const Vec3 &)=default
 Default assignment copy operator.
 
constexpr Vec3 operator- () const noexcept
 Getter of the opposite signed vector.
 
Vec3 operator* (T _scale) const noexcept
 Scale each vector axis by _scale.
 
Vec3 operator/ (T _scale) const
  Inverse Scale each vector axis by _scale.
 
constexpr Vec3 operator+ (const Vec3 &_rhs) const noexcept
 Add term by term vector values.
 
constexpr Vec3 operator- (const Vec3 &_rhs) const noexcept
 Subtract term by term vector values.
 
constexpr Vec3 operator* (const Vec3 &_rhs) const noexcept
 Multiply term by term vector values.
 
Vec3 operator/ (const Vec3 &_rhs) const
 Divide term by term vector values.
 
constexpr T operator| (const Vec3 &_rhs) const noexcept
 Compute the Dot product between this and _rhs.
 
constexpr Vec3 operator^ (const Vec3 &_rhs) const noexcept
 Compute the Cross product between this and _rhs.
 
Vec3operator*= (T _scale) noexcept
 Scale each vector axis by _scale.
 
Vec3operator/= (T _scale)
  Inverse Scale each vector axis by _scale.
 
Vec3operator+= (const Vec3 &_rhs) noexcept
 Add term by term vector values.
 
Vec3operator-= (const Vec3 &_rhs) noexcept
 Substract term by term vector values.
 
Vec3 operator*= (const Vec3 &_rhs) noexcept
 Multiply term by term vector values.
 
Vec3 operator/= (const Vec3 &_rhs)
 Divide term by term vector values.
 

Static Public Member Functions

static constexpr T Dot (const Vec3 &_lhs, const Vec3 &_rhs) noexcept
 Compute the Dot product between _lhs and _rhs.
 
static constexpr Vec3< T > Cross (const Vec3 &_lhs, const Vec3 &_rhs) noexcept
 Compute the Cross product between _lhs and _rhs.
 
static Deg< T > Angle (const Vec3 &_start, const Vec3 &_end, const Vec3 &_normal=Vec3::Up) noexcept
 Compute the Signed Angle between _lhs and _rhs.
 
static Deg< T > AngleUnsigned (const Vec3 &_start, const Vec3 &_end) noexcept
 Compute the Unsigned Angle between _lhs and _rhs.
 
static constexpr T Dist (const Vec3 &_start, const Vec3 &_end)
 Compute the Distance between _lhs and _rhs.
 
static constexpr T SqrDist (const Vec3 &_start, const Vec3 &_end) noexcept
 Compute the Squared Distance between _lhs and _rhs.
 
static constexpr Vec3 Dir (const Vec3 &_start, const Vec3 &_end) noexcept
 Compute the Non-Normalized Direction from _lhs and _rhs.
 
static constexpr Vec3 DirN (const Vec3 &_start, const Vec3 &_end)
 Compute the Normalized Direction from _start to _end.
 
static Vec3 Lerp (const Vec3 &_start, const Vec3 &_end, float _alpha) noexcept
  Clamped Lerp from _start to _end at _alpha.
 
static Vec3 LerpUnclamped (const Vec3 &_start, const Vec3 &_end, float _alpha) noexcept
  Unclamped Lerp from _start to _end at _alpha.
 
static Vec3 SLerp (const Vec3 &_start, const Vec3 &_end, float _alpha) noexcept
  Clamped SLerp from _start to _end at _alpha.
 
static Vec3 SLerpUnclamped (const Vec3 &_start, const Vec3 &_end, float _alpha) noexcept
  Unclamped SLerp from _start to _end at _alpha.
 

Public Attributes

x = T()
 Vector's X component (axis value).
 
y = T()
 Vector's Y component (axis value).
 
z = T()
 Vector's Z component (axis value).
 

Static Public Attributes

static const Vec3 Zero
 Zero vector constant {0, 0, 0}.
 
static const Vec3 One
 One vector constant {1, 1, 1}.
 
static const Vec3 Right
 Right vector constant {1, 0, 0}.
 
static const Vec3 Left
 Left vector constant {-1, 0, 0}.
 
static const Vec3 Up
 Up vector constant {0, 1, 0}.
 
static const Vec3 Down
 Down vector constant {0, -1, 0}.
 
static const Vec3 Forward
 Down vector constant {0, 0, 1}.
 
static const Vec3 Backward
 Down vector constant {0, 0, -1}.
 

Detailed Description

template<typename T>
struct SA::Vec3< T >

Vector 3 Sapphire-Maths class.

Template Parameters
TType of the vector.

Constructor & Destructor Documentation

◆ Vec3() [1/5]

template<typename T >
constexpr SA::Vec3< T >::Vec3 ( T _x,
T _y,
T _z )
constexprnoexcept

Value constructor.

Parameters
[in]_xX axis value.
[in]_yY axis value.
[in]_zZ axis value.

◆ Vec3() [2/5]

template<typename T >
constexpr SA::Vec3< T >::Vec3 ( T _scale)
constexprnoexcept

Scale Value constructor.

Parameters
[in]_scaleAxis value to apply on all axis.

◆ Vec3() [3/5]

template<typename T >
template<typename TIn >
constexpr SA::Vec3< T >::Vec3 ( const Vec3< TIn > & _other)
constexprnoexcept

Value constructor from another Vec3 type.

Template Parameters
TInType of the input Vec3.
Parameters
[in]_otherVec3 to construct from.

◆ Vec3() [4/5]

template<typename T >
template<typename TIn >
constexpr SA::Vec3< T >::Vec3 ( const Vec2< TIn > & _other,
T _z = T(0) )
constexprnoexcept

Value constructor from Vec2.

Template Parameters
TInType of the in Vec2.
Parameters
[in]_otherVec2 to construct from.
[in]_zZ axis value.

◆ Vec3() [5/5]

template<typename T >
template<typename TIn >
constexpr SA::Vec3< T >::Vec3 ( const Vec4< TIn > & _other)
constexprnoexcept

Value constructor from Vec4.

Template Parameters
TInType of the in Vec4.
Parameters
[in]_otherVec4 to construct from.

Member Function Documentation

◆ Angle()

template<typename T >
static Deg< T > SA::Vec3< T >::Angle ( const Vec3< T > & _start,
const Vec3< T > & _end,
const Vec3< T > & _normal = Vec3< T >::Up )
staticnoexcept

Compute the Signed Angle between _lhs and _rhs.

Parameters
[in]_startLeft hand side operand to compute angle with.
[in]_endRight hand side operand to compute angle with.
[in]_normalNormal of the plan between _lhs and _rhs, used to determine angle's sign.
Returns
Signed Angle between _start and _end.

◆ AngleUnsigned()

template<typename T >
static Deg< T > SA::Vec3< T >::AngleUnsigned ( const Vec3< T > & _start,
const Vec3< T > & _end )
staticnoexcept

Compute the Unsigned Angle between _lhs and _rhs.

Parameters
[in]_startLeft hand side operand to compute angle with.
[in]_endRight hand side operand to compute angle with.
Returns
Unsigned Angle between _start and _end.

◆ Cross()

template<typename T >
static constexpr Vec3< T > SA::Vec3< T >::Cross ( const Vec3< T > & _lhs,
const Vec3< T > & _rhs )
staticconstexprnoexcept

Compute the Cross product between _lhs and _rhs.

Parameters
[in]_lhsLeft hand side operand to compute cross product with.
[in]_rhsRight hand side operand to compute cross product with.
Returns
Cross product between _lhs and _rhs.

◆ Data() [1/2]

template<typename T >
const T * SA::Vec3< T >::Data ( ) const
noexcept

Const Getter of vector data

Returns
this vector as a const T*.

◆ Data() [2/2]

template<typename T >
T * SA::Vec3< T >::Data ( )
noexcept

Getter of vector data

Returns
this vector as a T*.

◆ Dir()

template<typename T >
static constexpr Vec3 SA::Vec3< T >::Dir ( const Vec3< T > & _start,
const Vec3< T > & _end )
staticconstexprnoexcept

Compute the Non-Normalized Direction from _lhs and _rhs.

Direction get not normalized. Use DirN instead.

Parameters
[in]_startLeft hand side operand to compute direction from.
[in]_endRight hand side operand to compute direction to
Returns
Non-Normalized Direction from _start and _end.

◆ DirN()

template<typename T >
static constexpr Vec3 SA::Vec3< T >::DirN ( const Vec3< T > & _start,
const Vec3< T > & _end )
staticconstexpr

Compute the Normalized Direction from _start to _end.

Parameters
[in]_startStarting point to compute direction from.
[in]_endending point to compute direction to.
Returns
Normalized Direction from _start to _end.

◆ Dist()

template<typename T >
static constexpr T SA::Vec3< T >::Dist ( const Vec3< T > & _start,
const Vec3< T > & _end )
staticconstexpr

Compute the Distance between _lhs and _rhs.

Parameters
[in]_startLeft hand side operand to compute distance with.
[in]_endRight hand side operand to compute distance with.
Returns
Distance between _start and _end.

◆ Dot()

template<typename T >
static constexpr T SA::Vec3< T >::Dot ( const Vec3< T > & _lhs,
const Vec3< T > & _rhs )
staticconstexprnoexcept

Compute the Dot product between _lhs and _rhs.

Parameters
[in]_lhsLeft hand side operand to compute dot product with.
[in]_rhsRight hand side operand to compute dot product with.
Returns
Dot product between _lhs and _rhs.

◆ Equals()

template<typename T >
constexpr bool SA::Vec3< T >::Equals ( const Vec3< T > & _other,
T _epsilon = std::numeric_limits< T >::epsilon() ) const
constexprnoexcept

Compare 2 vector.

Parameters
[in]_otherOther vector to compare to.
[in]_epsilonEpsilon value for threshold comparison.
Returns
Whether this and _other are equal.

◆ GetNormalized()

template<typename T >
Vec3 SA::Vec3< T >::GetNormalized ( ) const

Normalize this vector.

Returns
new normalized vector.

◆ IsNormalized()

template<typename T >
constexpr bool SA::Vec3< T >::IsNormalized ( ) const
constexprnoexcept

Whether this vector is normalized.

Returns
True if this vector is normalized, otherwise false.

◆ IsZero()

template<typename T >
constexpr bool SA::Vec3< T >::IsZero ( ) const
constexprnoexcept

Whether this vector is a zero vector.

Returns
True if this is a zero vector.

◆ Length()

template<typename T >
constexpr T SA::Vec3< T >::Length ( ) const
constexpr

Getter of the length of this vector.

Returns
Length of this vector.

◆ Lerp()

template<typename T >
static Vec3 SA::Vec3< T >::Lerp ( const Vec3< T > & _start,
const Vec3< T > & _end,
float _alpha )
staticnoexcept

Clamped Lerp from _start to _end at _alpha.

Reference: https://en.wikipedia.org/wiki/Linear_interpolation

Parameters
_startStarting point of the lerp.
_endEnding point of the lerp.
_alphaAlpha of the lerp.
Returns
interpolation between _start and _end. return _start when _alpha == 0.0f and _end when _alpha == 1.0f.

◆ LerpUnclamped()

template<typename T >
static Vec3 SA::Vec3< T >::LerpUnclamped ( const Vec3< T > & _start,
const Vec3< T > & _end,
float _alpha )
staticnoexcept

Unclamped Lerp from _start to _end at _alpha.

Reference: https://en.wikipedia.org/wiki/Linear_interpolation

Parameters
_startStarting point of the lerp.
_endEnding point of the lerp.
_alphaAlpha of the lerp.
Returns
interpolation between _start and _end. return _start when _alpha == 0.0f and _end when _alpha == 1.0f.

◆ Normalize()

template<typename T >
Vec3 & SA::Vec3< T >::Normalize ( )

Normalize this vector.

Returns
self vector normalized.

◆ operator!=()

template<typename T >
constexpr bool SA::Vec3< T >::operator!= ( const Vec3< T > & _rhs) const
constexprnoexcept

Compare 2 vector inequality.

Parameters
[in]_rhsOther vector to compare to.
Returns
Whether this and _rhs are non-equal.

◆ operator*() [1/2]

template<typename T >
constexpr Vec3 SA::Vec3< T >::operator* ( const Vec3< T > & _rhs) const
constexprnoexcept

Multiply term by term vector values.

Parameters
[in]_rhsVector to multiply.
Returns
new vector result.

◆ operator*() [2/2]

template<typename T >
Vec3 SA::Vec3< T >::operator* ( T _scale) const
noexcept

Scale each vector axis by _scale.

Parameters
[in]_scaleScale value to apply on all axis.
Returns
new vector scaled.

◆ operator*=() [1/2]

template<typename T >
Vec3 SA::Vec3< T >::operator*= ( const Vec3< T > & _rhs)
noexcept

Multiply term by term vector values.

Parameters
[in]_rhsVector to multiply.
Returns
self vector result.

◆ operator*=() [2/2]

template<typename T >
Vec3 & SA::Vec3< T >::operator*= ( T _scale)
noexcept

Scale each vector axis by _scale.

Parameters
[in]_scaleScale value to apply on all axis.
Returns
self vector scaled.

◆ operator+()

template<typename T >
constexpr Vec3 SA::Vec3< T >::operator+ ( const Vec3< T > & _rhs) const
constexprnoexcept

Add term by term vector values.

Parameters
[in]_rhsVector to add.
Returns
new vector result.

◆ operator+=()

template<typename T >
Vec3 & SA::Vec3< T >::operator+= ( const Vec3< T > & _rhs)
noexcept

Add term by term vector values.

Parameters
[in]_rhsVector to add.
Returns
self vector result.

◆ operator-() [1/2]

template<typename T >
constexpr Vec3 SA::Vec3< T >::operator- ( ) const
constexprnoexcept

Getter of the opposite signed vector.

Returns
new opposite signed vector.

◆ operator-() [2/2]

template<typename T >
constexpr Vec3 SA::Vec3< T >::operator- ( const Vec3< T > & _rhs) const
constexprnoexcept

Subtract term by term vector values.

Parameters
[in]_rhsVector to substract.
Returns
new vector result.

◆ operator-=()

template<typename T >
Vec3 & SA::Vec3< T >::operator-= ( const Vec3< T > & _rhs)
noexcept

Substract term by term vector values.

Parameters
[in]_rhsVector to substract.
Returns
self vector result.

◆ operator/() [1/2]

template<typename T >
Vec3 SA::Vec3< T >::operator/ ( const Vec3< T > & _rhs) const

Divide term by term vector values.

Parameters
[in]_rhsVector to divide.
Returns
new vector result.

◆ operator/() [2/2]

template<typename T >
Vec3 SA::Vec3< T >::operator/ ( T _scale) const

Inverse Scale each vector axis by _scale.

Parameters
[in]_scaleInverse scale value to apply on all axis.
Returns
new vector inverse-scaled.

◆ operator/=() [1/2]

template<typename T >
Vec3 SA::Vec3< T >::operator/= ( const Vec3< T > & _rhs)

Divide term by term vector values.

Parameters
[in]_rhsVector to divide.
Returns
self vector result.

◆ operator/=() [2/2]

template<typename T >
Vec3 & SA::Vec3< T >::operator/= ( T _scale)

Inverse Scale each vector axis by _scale.

Parameters
[in]_scaleScale value to apply on all axis.
Returns
self vector inverse-scaled.

◆ operator=() [1/2]

template<typename T >
Vec3 & SA::Vec3< T >::operator= ( const Vec3< T > & )
default

Default assignment copy operator.

Returns
self vector assigned.

◆ operator=() [2/2]

template<typename T >
Vec3 & SA::Vec3< T >::operator= ( Vec3< T > && )
default

Default assignment move operator.

Returns
self vector assigned.

◆ operator==()

template<typename T >
constexpr bool SA::Vec3< T >::operator== ( const Vec3< T > & _rhs) const
constexprnoexcept

Compare 2 vector equality.

Parameters
[in]_rhsOther vector to compare to.
Returns
Whether this and _rhs are equal.

◆ operator[]() [1/2]

template<typename T >
T & SA::Vec3< T >::operator[] ( uint32_t _index)

Access operator by index: x, y, z using 0, 1, 2.

Parameters
[in]_indexIndex to access.
Returns
T value at index.

◆ operator[]() [2/2]

template<typename T >
const T & SA::Vec3< T >::operator[] ( uint32_t _index) const

Const Access operator by index: x, y, z using 0, 1, 2.

Parameters
[in]_indexIndex to access.
Returns
T value at index.

◆ operator^()

template<typename T >
constexpr Vec3 SA::Vec3< T >::operator^ ( const Vec3< T > & _rhs) const
constexprnoexcept

Compute the Cross product between this and _rhs.

Parameters
[in]_rhsRight hand side operand vector to compute cross product with.
Returns
Cross product between this vector and _other.

◆ operator|()

template<typename T >
constexpr T SA::Vec3< T >::operator| ( const Vec3< T > & _rhs) const
constexprnoexcept

Compute the Dot product between this and _rhs.

Parameters
[in]_rhsRight hand side operand vector to compute dot product with.
Returns
Dot product between this vector and _other.

◆ ProjectOnTo()

template<typename T >
Vec3 SA::Vec3< T >::ProjectOnTo ( const Vec3< T > & _other) const
noexcept

Project this vector onto an other vector.

Reference: https://en.wikipedia.org/wiki/Vector_projection

Parameters
[in]_otherVector used for projection.
Returns
new vector projected.

◆ ProjectOnToNormal()

template<typename T >
Vec3 SA::Vec3< T >::ProjectOnToNormal ( const Vec3< T > & _normal) const
noexcept

Project this vector onto s normal.

Assume _normal is normalized. Use GetProjectOnTo() for non normalized vector. Reference: https://en.wikipedia.org/wiki/Vector_projection

Parameters
[in]_normalNormal used for projection.
Returns
new vector projected.

◆ Reflect()

template<typename T >
Vec3 SA::Vec3< T >::Reflect ( const Vec3< T > & _normal,
float _elasticity = 1.0f ) const
noexcept

Reflect this vector over the normal.

Parameters
[in]_normalNormal used for reflection.
[in]_elasticityElasticity reflection coefficient (use 1.0f for full reflection).
Returns
new vector reflected.

◆ SLerp()

template<typename T >
static Vec3 SA::Vec3< T >::SLerp ( const Vec3< T > & _start,
const Vec3< T > & _end,
float _alpha )
staticnoexcept

Clamped SLerp from _start to _end at _alpha.

Reference: https://en.wikipedia.org/wiki/Slerp

Parameters
_startStarting point of the lerp.
_endEnding point of the lerp.
_alphaAlpha of the lerp.
Returns
interpolation between _start and _end. return _start when _alpha == 0.0f and _end when _alpha == 1.0f.

◆ SLerpUnclamped()

template<typename T >
static Vec3 SA::Vec3< T >::SLerpUnclamped ( const Vec3< T > & _start,
const Vec3< T > & _end,
float _alpha )
staticnoexcept

Unclamped SLerp from _start to _end at _alpha.

Reference: https://en.wikipedia.org/wiki/Slerp

Parameters
_startStarting point of the lerp.
_endEnding point of the lerp.
_alphaAlpha of the lerp.
Returns
interpolation between _start and _end. return _start when _alpha == 0.0f and _end when _alpha == 1.0f.

◆ SqrDist()

template<typename T >
static constexpr T SA::Vec3< T >::SqrDist ( const Vec3< T > & _start,
const Vec3< T > & _end )
staticconstexprnoexcept

Compute the Squared Distance between _lhs and _rhs.

Parameters
[in]_startLeft hand side operand to compute squared distance with.
[in]_endRight hand side operand to compute squared distance with.
Returns
Squared Distance between _start and _end.

◆ SqrLength()

template<typename T >
constexpr T SA::Vec3< T >::SqrLength ( ) const
constexprnoexcept

Getter of the Squared Length of this vector.

Returns
Squared Length of this vector.

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