DubiousEngine  0.2.0
Simple Game Engine
Dubious::Math::Unit_quaternionT< T > Class Template Reference

Unit Quaternions are used to represent rotation. More...

#include <Unit_quaternion.h>

Public Member Functions

 Unit_quaternionT ()=default
 Default Constructor. More...
 
 Unit_quaternionT (const QuaternionT< T > &q)
 Copy Constructor. More...
 
 Unit_quaternionT (const Unit_vectorT< T > &axis, float angle)
 Construct from axis and angle. More...
 
float w () const
 real component accessor More...
 
const VectorT< T > & v () const
 imaginary component accessor More...
 
Unit_quaternionT conjugate () const
 The conjugate. More...
 
void get_matrix (float matrix[16]) const
 Get the rotation matrix. More...
 
std::tuple< Unit_vectorT< T >, float > get_axis_angle () const
 Get the Axis and Angle. More...
 
Unit_quaternionT< T > operator- () const
 

Friends

class Math_test::Unit_quaternion_test
 
class Physics_test::Collision_solver_test
 
class Coordinate_space
 
Unit_quaternionT< T > operator* (const Unit_quaternionT< T > &a, const Unit_quaternionT< T > &b)
 

Detailed Description

template<int T>
class Dubious::Math::Unit_quaternionT< T >

Unit Quaternions are used to represent rotation.

Everyone's favorite 4 dimensional, completely mysterious mathmatical construct. Quaternions with magnitude 1, Unit Quaternions, can be used to represent rotations in 3D space. This class implements all of the basic math (basically copy and paste of that found in Quaternion) but with more careful considerations for type conversions back to non-Unit Quaternions. It goes a bit further to include some functions for converting to other rotation representations.

Here are some resources I found useful in understanding Quaternions https://www.youtube.com/watch?v=mHVwd8gYLnI https://www.3dgep.com/understanding-quaternions/

Constructor & Destructor Documentation

template<int T>
Dubious::Math::Unit_quaternionT< T >::Unit_quaternionT ( )
default

Default Constructor.

Will create a Quaternion that has X, Y, Z axis aligned with the global X, Y, and Z.

template<int T>
Dubious::Math::Unit_quaternionT< T >::Unit_quaternionT ( const QuaternionT< T > &  q)

Copy Constructor.

template<int T>
Dubious::Math::Unit_quaternionT< T >::Unit_quaternionT ( const Unit_vectorT< T > &  axis,
float  angle 
)

Construct from axis and angle.

This is a more useful constructor where you can specify an axis and an angle around that axis. This is a right hand coordinate system, so the angle is counter-clockwise rotation around the axis

Parameters
axis- [in] The axis around which we will rotate
angle- [in] Magnitude of Rotation (in radians)

Member Function Documentation

template<int T>
Unit_quaternionT Dubious::Math::Unit_quaternionT< T >::conjugate ( ) const
inline

The conjugate.

The conjugate is simply (w, -v) The magnitude of the Unit Quaternion is maintained

Returns
the conjugate
template<int T>
std::tuple< Unit_vectorT< T >, float > Dubious::Math::Unit_quaternionT< T >::get_axis_angle ( ) const

Get the Axis and Angle.

Return a unit vector representing the axis of rotation, as well as a float representing the angle around that axis, in radians

Returns
tuple of axis and angle
template<int T>
void Dubious::Math::Unit_quaternionT< T >::get_matrix ( float  matrix[16]) const

Get the rotation matrix.

Return the rotation matrix representation of this quaternion. This is basically a shortcut for OpenGL rotation as it takes this same matrix as an input. It's also handy for finding the three axis of rotation in one call

Parameters
matrix- [out] Will be filled with the rotation matrix
template<int T>
Unit_quaternionT<T> Dubious::Math::Unit_quaternionT< T >::operator- ( ) const
inline
template<int T>
const VectorT<T>& Dubious::Math::Unit_quaternionT< T >::v ( ) const
inline

imaginary component accessor

template<int T>
float Dubious::Math::Unit_quaternionT< T >::w ( ) const
inline

real component accessor

Friends And Related Function Documentation

template<int T>
friend class Coordinate_space
friend
template<int T>
friend class Math_test::Unit_quaternion_test
friend
template<int T>
Unit_quaternionT<T> operator* ( const Unit_quaternionT< T > &  a,
const Unit_quaternionT< T > &  b 
)
friend
template<int T>
friend class Physics_test::Collision_solver_test
friend

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