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

Math class that represents an element of the quaternions. More...

Public Member Functions

 Quaternion (T W, T X, T Y, T Z)
 Constructs a Quaternion object from its components. More...
 
 Quaternion (const EulerAngles< T > &angles)
 Constructs a Quaternion object from a EulerAngles. More...
 
 Quaternion (T angle, const Vector3< T > &axis)
 Constructs a Quaternion object from an angle and a direction. More...
 
 Quaternion (const T quat[4])
 Constructs a Quaternion object from an array of four elements. More...
 
template<typename U >
 Quaternion (const Quaternion< U > &quat)
 Constructs a Quaternion object from another type of Quaternion. More...
 
 Quaternion (const Quaternion &quat)=default
 
QuaternionComputeW ()
 Computes the w component of the quaternion to make it unit. More...
 
QuaternionConjugate ()
 Returns the rotational conjugate of this quaternion. More...
 
DotProduct (const Quaternion &vec) const
 Calculates the dot (scalar) product with two quaternions. More...
 
Quaternion GetConjugate () const
 Gets the rotational conjugate of this quaternion. More...
 
Quaternion GetInverse () const
 Gets the inverse of this quaternion. More...
 
Quaternion GetNormal (T *length=nullptr) const
 Gets the normalization of this quaternion. More...
 
QuaternionInverse ()
 Inverts this quaternion. More...
 
QuaternionMakeIdentity ()
 Makes the quaternion (1, 0, 0, 0) More...
 
QuaternionMakeRotationBetween (const Vector3< T > &from, const Vector3< T > &to)
 Makes this quaternion to the rotation required to rotate direction Vector3 from to direction Vector3 to. More...
 
QuaternionMakeZero ()
 Makes the quaternion (0, 0, 0, 0) More...
 
Magnitude () const
 Calculates the magnitude (length) of the quaternion. More...
 
QuaternionNormalize (T *length=nullptr)
 Normalizes the current quaternion. More...
 
QuaternionSet (T W, T X, T Y, T Z)
 Sets the components of the quaternion. More...
 
QuaternionSet (const EulerAngles< T > &angles)
 Sets this quaternion from rotation specified by Euler angle. More...
 
QuaternionSet (T angle, const Vector3< T > &normalizedAxis)
 Sets this quaternion from rotation specified by axis and angle. More...
 
QuaternionSet (const T quat[4])
 Sets the components of the quaternion from an array of four elements. More...
 
QuaternionSet (const Quaternion &quat)
 Sets the components of the quaternion from another quaternion. More...
 
template<typename U >
QuaternionSet (const Quaternion< U > &quat)
 
SquaredMagnitude () const
 Calculates the squared magnitude (length) of the quaternion. More...
 
EulerAngles< T > ToEulerAngles () const
 Converts this quaternion to Euler angles representation. More...
 
String ToString () const
 Gives a string representation. More...
 
Quaternionoperator= (const Quaternion &quat)=default
 
Quaternion operator+ (const Quaternion &quat) const
 Adds the components of the quaternion with other quaternion. More...
 
Quaternion operator* (const Quaternion &quat) const
 Multiplies of the quaternion with other quaternion. More...
 
Vector3< T > operator* (const Vector3< T > &vec) const
 Apply the quaternion to the Vector3. More...
 
Quaternion operator* (T scale) const
 Multiplies the components of the quaternion with a scalar. More...
 
Quaternion operator/ (const Quaternion &quat) const
 Divides the quaternion with other quaternion. More...
 
Quaternionoperator+= (const Quaternion &quat)
 Adds the components of the quaternion with other quaternion. More...
 
Quaternionoperator*= (const Quaternion &quat)
 Multiplies of the quaternion with other quaternion. More...
 
Quaternionoperator*= (T scale)
 Multiplies the components of the quaternion with a scalar. More...
 
Quaternionoperator/= (const Quaternion &quat)
 Divides the quaternion with other quaternion. More...
 
bool operator== (const Quaternion &quat) const
 Compares the quaternion to other one. More...
 
bool operator!= (const Quaternion &quat) const
 Compares the quaternion to other one. More...
 
template<typename U >
Quaternion< T > & Set (const Quaternion< U > &quat)
 Sets the components of the quaternion from another type of Quaternion. More...
 

Static Public Member Functions

static Quaternion Identity ()
 Shorthand for the quaternion (1, 0, 0, 0) More...
 
static Quaternion Lerp (const Quaternion &from, const Quaternion &to, T interpolation)
 Interpolates the quaternion to other one with a factor of interpolation. More...
 
static Quaternion Normalize (const Quaternion &quat, T *length=nullptr)
 Gives the normalized quaternion. More...
 
static Quaternion RotationBetween (const Vector3< T > &from, const Vector3< T > &to)
 Gets the rotation required to rotate direction Vector3 from to direction Vector3 to. More...
 
static Quaternion Slerp (const Quaternion &from, const Quaternion &to, T interpolation)
 Interpolates spherically the quaternion to other one with a factor of interpolation. More...
 
static Quaternion Zero ()
 Shorthand for the quaternion (0, 0, 0, 0) More...
 

Public Attributes

w
 
x
 
y
 
z
 

Detailed Description

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

Math class that represents an element of the quaternions.

Remarks
The quaternion is meant to be 'unit' to represent rotations in a three dimensional space

Constructor & Destructor Documentation

◆ Quaternion() [1/5]

template<typename T>
Nz::Quaternion< T >::Quaternion ( W,
X,
Y,
Z 
)

Constructs a Quaternion object from its components.

Parameters
WW component
XX component
YY component
ZZ component

◆ Quaternion() [2/5]

template<typename T>
Nz::Quaternion< T >::Quaternion ( const EulerAngles< T > &  angles)

Constructs a Quaternion object from a EulerAngles.

Parameters
anglesEasier representation of rotation of space
See also
EulerAngles

◆ Quaternion() [3/5]

template<typename T>
Nz::Quaternion< T >::Quaternion ( angle,
const Vector3< T > &  axis 
)

Constructs a Quaternion object from an angle and a direction.

Parameters
angleUnit depends of NAZARA_MATH_ANGLE_RADIAN
axisVector3 which represents a direction, no need to be normalized

◆ Quaternion() [4/5]

template<typename T>
Nz::Quaternion< T >::Quaternion ( const T  quat[4])

Constructs a Quaternion object from an array of four elements.

Parameters
quat[4]quat[0] is W component, quat[1] is X component, quat[2] is Y component and quat[3] is Z component

◆ Quaternion() [5/5]

template<typename T >
template<typename U >
Nz::Quaternion< T >::Quaternion ( const Quaternion< U > &  quat)
explicit

Constructs a Quaternion object from another type of Quaternion.

Parameters
quatQuaternion of type U to convert to type T

Member Function Documentation

◆ ComputeW()

template<typename T >
Quaternion< T > & Nz::Quaternion< T >::ComputeW ( )

Computes the w component of the quaternion to make it unit.

Returns
A reference to this quaternion

◆ Conjugate()

template<typename T >
Quaternion< T > & Nz::Quaternion< T >::Conjugate ( )

Returns the rotational conjugate of this quaternion.

Returns
A reference to this quaternion

The conjugate of a quaternion represents the same rotation in the opposite direction about the rotational axis

See also
GetConjugate

◆ DotProduct()

template<typename T >
T Nz::Quaternion< T >::DotProduct ( const Quaternion< T > &  quat) const

Calculates the dot (scalar) product with two quaternions.

Returns
The value of the dot product
Parameters
quatThe other quaternion to calculate the dot product with

◆ GetConjugate()

template<typename T >
Quaternion< T > Nz::Quaternion< T >::GetConjugate ( ) const

Gets the rotational conjugate of this quaternion.

Returns
A new quaternion which is the conjugate of this quaternion

The conjugate of a quaternion represents the same rotation in the opposite direction about the rotational axis

See also
Conjugate

◆ GetInverse()

template<typename T >
Quaternion< T > Nz::Quaternion< T >::GetInverse ( ) const

Gets the inverse of this quaternion.

Returns
A new quaternion which is the inverse of this quaternion
Remarks
If this quaternion is (0, 0, 0, 0), then it returns (0, 0, 0, 0)
See also
Inverse

◆ GetNormal()

template<typename T>
Quaternion< T > Nz::Quaternion< T >::GetNormal ( T *  length = nullptr) const

Gets the normalization of this quaternion.

Returns
A new quaternion which is the normalization of this quaternion
Parameters
lengthOptional argument to obtain the length's ratio of the quaternion and the unit-length
Remarks
If this quaternion is (0, 0, 0, 0), then it returns (0, 0, 0, 0) and length is 0
See also
Normalize

◆ Identity()

template<typename T >
Quaternion< T > Nz::Quaternion< T >::Identity ( )
static

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

Returns
A quaternion with components (1, 0, 0, 0)
See also
MakeIdentity

◆ Inverse()

template<typename T >
Quaternion< T > & Nz::Quaternion< T >::Inverse ( )

Inverts this quaternion.

Returns
A reference to this quaternion which is now inverted
Remarks
If this quaternion is (0, 0, 0, 0), then it returns (0, 0, 0, 0)
See also
GetInverse

◆ Lerp()

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

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

Returns
A new quaternion which is the interpolation of two quaternions
Parameters
fromInitial quaternion
toTarget quaternion
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, Slerp

◆ Magnitude()

template<typename T >
T Nz::Quaternion< T >::Magnitude ( ) const

Calculates the magnitude (length) of the quaternion.

Returns
The magnitude
See also
SquaredMagnitude

◆ MakeIdentity()

template<typename T >
Quaternion< T > & Nz::Quaternion< T >::MakeIdentity ( )

Makes the quaternion (1, 0, 0, 0)

Returns
A reference to this vector with components (1, 0, 0, 0)
See also
Unit

◆ MakeRotationBetween()

template<typename T>
Quaternion< T > & Nz::Quaternion< T >::MakeRotationBetween ( const Vector3< T > &  from,
const Vector3< T > &  to 
)

Makes this quaternion to the rotation required to rotate direction Vector3 from to direction Vector3 to.

Returns
A reference to this vector which is the rotation needed
Parameters
fromInitial vector
toTarget vector
See also
RotationBetween

◆ MakeZero()

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

Makes the quaternion (0, 0, 0, 0)

Returns
A reference to this vector with components (0, 0, 0, 0)
See also
Zero

◆ Normalize() [1/2]

template<typename T>
Quaternion< T > & Nz::Quaternion< T >::Normalize ( T *  length = nullptr)

Normalizes the current quaternion.

Returns
A reference to this quaternion which is now normalized
Parameters
lengthOptional argument to obtain the length's ratio of the quaternion and the unit-length
Remarks
If the quaternion is (0, 0, 0, 0), then it returns (0, 0, 0, 0) and length is 0
See also
GetNormal

◆ Normalize() [2/2]

template<typename T>
Quaternion< T > Nz::Quaternion< T >::Normalize ( const Quaternion< T > &  quat,
T *  length = nullptr 
)
static

Gives the normalized quaternion.

Returns
A normalized quaternion from the quat
Parameters
quatQuaternion to normalize
lengthOptional argument to obtain the length's ratio of the vector and the unit-length
See also
GetNormal

◆ operator!=()

template<typename T >
bool Nz::Quaternion< T >::operator!= ( const Quaternion< T > &  quat) const

Compares the quaternion to other one.

Returns
false if the quaternions are the same
Parameters
vecOther quaternion to compare with

◆ operator*() [1/3]

template<typename T >
Quaternion< T > Nz::Quaternion< T >::operator* ( const Quaternion< T > &  quat) const

Multiplies of the quaternion with other quaternion.

Returns
A quaternion which is the product of those two according to operator* in quaternions
Parameters
quatThe other quaternion to multiply with

◆ operator*() [2/3]

template<typename T>
Vector3< T > Nz::Quaternion< T >::operator* ( const Vector3< T > &  vec) const

Apply the quaternion to the Vector3.

Returns
A Vector3f which is the vector rotated by this quaternion
Parameters
vecThe vector to multiply with

◆ operator*() [3/3]

template<typename T>
Quaternion< T > Nz::Quaternion< T >::operator* ( scale) const

Multiplies the components of the quaternion with a scalar.

Returns
A quaternion where components are the product of this quaternion and the scalar
Parameters
scaleThe scalar to multiply components with

◆ operator*=() [1/2]

template<typename T >
Quaternion< T > & Nz::Quaternion< T >::operator*= ( const Quaternion< T > &  quat)

Multiplies of the quaternion with other quaternion.

Returns
A reference to this quaternion which is the product of those two according to operator* in quaternions
Parameters
quatThe other quaternion to multiply with

◆ operator*=() [2/2]

template<typename T>
Quaternion< T > & Nz::Quaternion< T >::operator*= ( scale)

Multiplies the components of the quaternion with a scalar.

Returns
A reference to this quaternion where components are the product of this quaternion and the scalar
Parameters
scaleThe scalar to multiply components with

◆ operator+()

template<typename T >
Quaternion< T > Nz::Quaternion< T >::operator+ ( const Quaternion< T > &  quat) const

Adds the components of the quaternion with other quaternion.

Returns
A quaternion where components are the sum of this quaternion and the other one
Parameters
quatThe other quaternion to add components with

◆ operator+=()

template<typename T >
Quaternion< T > & Nz::Quaternion< T >::operator+= ( const Quaternion< T > &  quat)

Adds the components of the quaternion with other quaternion.

Returns
A reference to this quaternion where components are the sum of this quaternion and the other one
Parameters
quatThe other quaternion to add components with

◆ operator/()

template<typename T >
Quaternion< T > Nz::Quaternion< T >::operator/ ( const Quaternion< T > &  quat) const

Divides the quaternion with other quaternion.

Returns
A quaternion which is the quotient of those two according to operator* in quaternions
Parameters
quatThe other quaternion to divide with

◆ operator/=()

template<typename T >
Quaternion< T > & Nz::Quaternion< T >::operator/= ( const Quaternion< T > &  quat)

Divides the quaternion with other quaternion.

Returns
A reference to this quaternion which is the quotient of those two according to operator* in quaternions
Parameters
quatThe other quaternion to divide with

◆ operator==()

template<typename T >
bool Nz::Quaternion< T >::operator== ( const Quaternion< T > &  quat) const

Compares the quaternion to other one.

Returns
true if the quaternions are the same
Parameters
vecOther quaternion to compare with

◆ RotationBetween()

template<typename T>
Quaternion< T > Nz::Quaternion< T >::RotationBetween ( const Vector3< T > &  from,
const Vector3< T > &  to 
)
static

Gets the rotation required to rotate direction Vector3 from to direction Vector3 to.

Returns
A quaternion which is the rotation needed between those two Vector3
Parameters
fromInitial vector
toTarget vector
See also
MakeRotationBetween

◆ Set() [1/6]

template<typename T>
Quaternion< T > & Nz::Quaternion< T >::Set ( W,
X,
Y,
Z 
)

Sets the components of the quaternion.

Returns
A reference to this quaternion
Parameters
WW component
XX component
YY component
ZZ component

◆ Set() [2/6]

template<typename T>
Quaternion< T > & Nz::Quaternion< T >::Set ( const EulerAngles< T > &  angles)

Sets this quaternion from rotation specified by Euler angle.

Returns
A reference to this quaternion
Parameters
anglesEasier representation of rotation of space
See also
EulerAngles

◆ Set() [3/6]

template<typename T>
Quaternion< T > & Nz::Quaternion< T >::Set ( angle,
const Vector3< T > &  axis 
)

Sets this quaternion from rotation specified by axis and angle.

Returns
A reference to this quaternion
Parameters
angleUnit depends of NAZARA_MATH_ANGLE_RADIAN
axisVector3 which represents a direction, no need to be normalized

◆ Set() [4/6]

template<typename T>
Quaternion< T > & Nz::Quaternion< T >::Set ( const T  quat[4])

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

Returns
A reference to this quaternion
Parameters
quat[4]quat[0] is W component, quat[1] is X component, quat[2] is Y component and quat[3] is Z component

◆ Set() [5/6]

template<typename T>
Quaternion< T > & Nz::Quaternion< T >::Set ( const Quaternion< T > &  quat)

Sets the components of the quaternion from another quaternion.

Returns
A reference to this quaternion
Parameters
vecThe other quaternion

◆ Set() [6/6]

template<typename T>
template<typename U >
Quaternion<T>& Nz::Quaternion< T >::Set ( const Quaternion< U > &  quat)

Sets the components of the quaternion from another type of Quaternion.

Returns
A reference to this quaternion
Parameters
quatQuaternion of type U to convert its components

◆ Slerp()

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

Interpolates spherically the quaternion to other one with a factor of interpolation.

Returns
A new quaternion which is the interpolation of two quaternions
Parameters
fromInitial quaternion
toTarget quaternion
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

◆ SquaredMagnitude()

template<typename T >
T Nz::Quaternion< T >::SquaredMagnitude ( ) const

Calculates the squared magnitude (length) of the quaternion.

Returns
The squared magnitude
See also
Magnitude

◆ ToEulerAngles()

template<typename T >
EulerAngles< T > Nz::Quaternion< T >::ToEulerAngles ( ) const

Converts this quaternion to Euler angles representation.

Returns
EulerAngles which is the representation of this rotation
Remarks
Rotation are "left-handed"

◆ ToString()

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

Gives a string representation.

Returns
A string representation of the object: "Quaternion(w | x, y, z)"

◆ Zero()

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

Shorthand for the quaternion (0, 0, 0, 0)

Returns
A quaternion with components (0, 0, 0, 0)
See also
MakeZero

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