Allolib  1.0
C++ Components For Interactive Multimedia
al::Quat< T > Class Template Reference

#include <C:/Users/Andres/source/repos/casm_viewer/external/tinc/external/allolib/include/al/math/al_Quat.hpp>

Public Member Functions

 Quat (const T &w=T(1), const T &x=T(0), const T &y=T(0), const T &z=T(0))
 Default constructor creates an identity quaternion.
 
template<class U >
 Quat (const Quat< U > &v)
 
template<class U >
 Quat (const Vec< 3, U > &xyz)
 Construct 'pure imaginary' quaternion. More...
 
template<class U >
 Quat (const T &w, const Vec< 3, U > &xyz)
 Construct quaternion from real and imaginary parts. More...
 
T & operator[] (int i)
 Set component with index.
 
const T & operator[] (int i) const
 Get component with index.
 
bool operator== (const Quat &v) const
 Returns true if all components are equal.
 
bool operator!= (const Quat &v) const
 Returns true if any components are not equal.
 
Quat operator- () const
 
Quat operator+ (const Quat &v) const
 
Quat operator+ (const T &v) const
 
Quat operator- (const Quat &v) const
 
Quat operator- (const T &v) const
 
Quat operator/ (const Quat &v) const
 
Quat operator/ (const T &v) const
 
Quat operator* (const Quat &v) const
 
Quat operator* (const T &v) const
 
template<class U >
Quatoperator= (const Quat< U > &v)
 
Quatoperator= (const T &v)
 
Quatoperator+= (const Quat &v)
 
Quatoperator+= (const T &v)
 
Quatoperator-= (const Quat &v)
 
Quatoperator-= (const T &v)
 
Quatoperator*= (const Quat &v)
 
Quatoperator*= (const T &v)
 
Quatoperator/= (const Quat &v)
 
Quatoperator/= (const T &v)
 
Quat conj () const
 Returns the conjugate.
 
dot (const Quat &v) const
 Returns dot product with another quaternion.
 
Quat inverse () const
 Returns inverse (same as conjugate if normalized as q^-1 = q_conj/q_mag^2)
 
mag () const
 Get magnitude.
 
magSqr () const
 Get magnitude squared.
 
Quat pow (T v) const
 Return quaternion raised to a power.
 
Quat recip () const
 Returns multiplicative inverse.
 
Quat sgn () const
 Returns signum, q/|q|, the closest point on unit 3-sphere.
 
Quat multiply (const Quat &q2) const
 
Quat reverseMultiply (const Quat &q2) const
 
Quatnormalize ()
 Normalize magnitude to one. More...
 
Quatset (const T &w, const T &x, const T &y, const T &z)
 Set components.
 
template<class U >
Quatset (const Quat< U > &q)
 Set from other quaternion.
 
QuatsetIdentity ()
 Set to identity.
 
QuatfromAxisAngle (const T &angle, const T &ux, const T &uy, const T &uz)
 Set as versor rotated by angle, in radians, around unit vector (ux,uy,uz)
 
QuatfromAxisAngle (const T &angle, const Vec< 3, T > &axis)
 Set as versor rotated by angle, in radians, around unit vector.
 
QuatfromAxisX (const T &angle)
 Set as versor rotated by angle, in radians, around x-axis.
 
QuatfromAxisY (const T &angle)
 Set as versor rotated by angle, in radians, around y-axis.
 
QuatfromAxisZ (const T &angle)
 Set as versor rotated by angle, in radians, around z-axis.
 
QuatfromEuler (const Vec< 3, T > &aeb)
 Set as versor rotated by YXZ Euler angles, in radians.
 
QuatfromEuler (const T &az, const T &el, const T &ba)
 Set as versor rotated by YXZ Euler angles, in radians.
 
QuatfromMatrix (const T *matrix)
 
QuatfromMatrix (const Mat< 4, T > &v)
 
QuatfromMatrixTransposed (const T *matrix)
 Set as versor from row-major 4-by-4 projective space transformation matrix.
 
QuatfromMatrixTransposed (const Mat< 4, T > &v)
 Set as versor from row-major 4-by-4 projective space transformation matrix.
 
void toCoordinateFrame (Vec< 3, T > &ux, Vec< 3, T > &uy, Vec< 3, T > &uz) const
 Convert to coordinate frame unit vectors.
 
template<typename T2 >
void toMatrix (T2 *matrix) const
 Convert to column-major 4-by-4 projective space transformation matrix.
 
template<typename T2 >
void toMatrixTransposed (T2 *matrix) const
 Convert to row-major 4-by-4 projective space transformation matrix.
 
void toAxisAngle (T &angle, T &ax, T &ay, T &az) const
 Convert to axis-angle form, in radians.
 
void toAxisAngle (T &angle, Vec< 3, T > &axis) const
 
void toEuler (T &az, T &el, T &ba) const
 Convert to YXZ Euler angles (azimuth, elevation, bank), in radians.
 
void toEuler (T *aeb) const
 Convert to YXZ Euler angle vector (azimuth, elevation, bank), in radians.
 
void toEuler (Vec< 3, T > &aeb) const
 Convert to YXZ Euler angle vector (azimuth, elevation, bank), in radians.
 
template<typename T2 >
void toVectorX (T2 &ax, T2 &ay, T2 &az) const
 Get local x unit vector (1,0,0) in absolute coordinates.
 
template<typename T2 >
void toVectorX (Vec< 3, T2 > &v) const
 
template<typename T2 = T>
Vec< 3, T2 > toVectorX () const
 
template<typename T2 >
void toVectorY (T2 &ax, T2 &ay, T2 &az) const
 Get local y unit vector (0,1,0) in absolute coordinates.
 
template<typename T2 >
void toVectorY (Vec< 3, T2 > &v) const
 
template<typename T2 = T>
Vec< 3, T2 > toVectorY () const
 
template<typename T2 >
void toVectorZ (T2 &ax, T2 &ay, T2 &az) const
 Get local z unit vector (0,0,1) in absolute coordinates.
 
template<typename T2 >
void toVectorZ (Vec< 3, T2 > &v) const
 
template<typename T2 = T>
Vec< 3, T2 > toVectorZ () const
 
Vec< 3, T > rotate (const Vec< 3, T > &v) const
 
Vec< 3, T > rotateTransposed (const Vec< 3, T > &v) const
 This is rotation by the quaternion's conjugate.
 
Quat slerp (const Quat &target, T amt) const
 Spherical interpolation.
 
void slerpTo (const Quat &target, T amt)
 In-place spherical interpolation.
 
void towardPoint (const Vec< 3, T > &pos, const Quat< T > &q, const Vec< 3, T > &v, float amt)
 Get the quaternion from a given point and quaterion toward another point. More...
 
void print (std::ostream &stream) const
 utility for debug printing:
 

Static Public Member Functions

static Quat getRotationTo (const Vec< 3, T > &usrc, const Vec< 3, T > &udst)
 
static Quat getBillboardRotation (const Vec< 3, T > &forward, const Vec< 3, T > &up)
 
static Quat identity ()
 Returns identity.
 
static Quat rotor (const Vec< 3, T > &v1, const Vec< 3, T > &v2)
 Get rotor from two unit vectors. More...
 
static Quat slerp (const Quat &from, const Quat &to, T amt)
 Spherical linear interpolation of a quaternion. More...
 
static void slerpBuffer (const Quat &from, const Quat &to, Quat< T > *buffer, int numFrames)
 Fill an array of Quats with a full spherical interpolation. More...
 
static T accuracyMax ()
 
static T accuracyMin ()
 
static T eps ()
 

Public Attributes

union {
   struct {
      T   w
 w component
 
      T   x
 x component
 
      T   y
 y component
 
      T   z
 z component
 
   } 
 
   T   components [4]
 component vector
 
}; 
 

Detailed Description

template<typename T = double>
class al::Quat< T >

Quaternion

Definition at line 63 of file al_Quat.hpp.

Constructor & Destructor Documentation

◆ Quat() [1/3]

template<typename T = double>
template<class U >
al::Quat< T >::Quat ( const Quat< U > &  v)
inline
Parameters
[in]vquaternion to set values from

Definition at line 82 of file al_Quat.hpp.

◆ Quat() [2/3]

template<typename T = double>
template<class U >
al::Quat< T >::Quat ( const Vec< 3, U > &  xyz)
inline

Construct 'pure imaginary' quaternion.

Parameters
[in]xyzvector to set x,y,z components from; w is set to 0

Definition at line 89 of file al_Quat.hpp.

◆ Quat() [3/3]

template<typename T = double>
template<class U >
al::Quat< T >::Quat ( const T &  w,
const Vec< 3, U > &  xyz 
)
inline

Construct quaternion from real and imaginary parts.

Parameters
[in]wreal part (w)
[in]xyzvector to set imaginary (x,y,z) components from

Definition at line 96 of file al_Quat.hpp.

Member Function Documentation

◆ fromMatrix() [1/2]

template<typename T = double>
Quat& al::Quat< T >::fromMatrix ( const Mat< 4, T > &  v)
inline

Set as versor from column-major 4-by-4 projective space transformation matrix

Definition at line 314 of file al_Quat.hpp.

◆ fromMatrix() [2/2]

template<typename T >
Quat< T > & al::Quat< T >::fromMatrix ( const T *  matrix)

Set as versor from column-major 4-by-4 projective space transformation matrix

Definition at line 579 of file al_Quat.hpp.

◆ getBillboardRotation()

template<typename T >
Quat< T > al::Quat< T >::getBillboardRotation ( const Vec< 3, T > &  forward,
const Vec< 3, T > &  up 
)
static

Similar to getRotationTo, but this function maintains an up vector Intended for billboarding in omni

Typical use case for omni billboarding:

Vec3d forward = Vec3d(pose.pos() - src.pos()).normalize();
Quatd rot = Quatd::getBillboardRotation(forward, pose.uu());
g.rotate(rot);
static Quat getBillboardRotation(const Vec< 3, double > &forward, const Vec< 3, double > &up)
Definition: al_Quat.hpp:1031
Vec & normalize(T scale=T(1))
Set magnitude to one without changing direction.
Definition: al_Vec.hpp:729
Vec< 3, double > Vec3d
double 3-vector
Definition: al_Vec.hpp:60
Quat< double > Quatd
Double-precision quaternion.
Definition: al_Quat.hpp:57

Definition at line 1031 of file al_Quat.hpp.

◆ getRotationTo()

template<typename T >
Quat< T > al::Quat< T >::getRotationTo ( const Vec< 3, T > &  usrc,
const Vec< 3, T > &  udst 
)
static

Calculate the rotation required to move from unit vector src to unit vector dst NOTE: both arguments must be UNIT VECTORS (normalized) rotation occurs around the axis created by the cross product of src and dst if the vectors are nearly opposing, the Y axis is used instead if the Y axis isn't suitable, the Z axis is used instead

a typical use case: rotate object A to face object B:

Vec3d src = Vec3d(A.quat().toVectorZ()).normalize();
Vec3d dst = Vec3d(B.pos() - A.pos()).normalize();
Quatd rot = Quatd::getRotationTo(src, dst);
A.quat() = rot * A.quat();
static Quat getRotationTo(const Vec< 3, double > &usrc, const Vec< 3, double > &udst)
Definition: al_Quat.hpp:985

Definition at line 985 of file al_Quat.hpp.

◆ normalize()

template<typename T >
Quat< T > & al::Quat< T >::normalize
inline

Normalize magnitude to one.

Implementation.

Definition at line 443 of file al_Quat.hpp.

◆ rotate()

template<typename T >
Vec< 3, T > al::Quat< T >::rotate ( const Vec< 3, T > &  v) const
inline

Rotate vector NOTE: quaternion should be normalized for accurate results.

Definition at line 841 of file al_Quat.hpp.

◆ rotor()

template<typename T >
Quat< T > al::Quat< T >::rotor ( const Vec< 3, T > &  v1,
const Vec< 3, T > &  v2 
)
static

Get rotor from two unit vectors.

Alternatively expressed as Q = (1+gp(v1, v2))/sqrt(2*(1+dot(b, a))).

Definition at line 1134 of file al_Quat.hpp.

◆ slerp()

template<typename T >
Quat< T > al::Quat< T >::slerp ( const Quat< T > &  from,
const Quat< T > &  to,
amt 
)
static

Spherical linear interpolation of a quaternion.

Parameters
[in]fromThe quaternion to interpolate from
[in]toThe quaternion to interpolate to
[in]amtThe amount to interpolate, range [0, 1]
Returns
resulting interpolated quaternion

Definition at line 863 of file al_Quat.hpp.

◆ slerpBuffer()

template<typename T >
void al::Quat< T >::slerpBuffer ( const Quat< T > &  from,
const Quat< T > &  to,
Quat< T > *  buffer,
int  numFrames 
)
static

Fill an array of Quats with a full spherical interpolation.

Sinusoidal generator based on recursive formula x0 = c x1 - x2

Constructor

Generate next value.

< Multiplication factor. [-2, 2] range gives stable sinusoids.

Definition at line 913 of file al_Quat.hpp.

◆ towardPoint()

template<typename T >
void al::Quat< T >::towardPoint ( const Vec< 3, T > &  pos,
const Quat< T > &  q,
const Vec< 3, T > &  v,
float  amt 
)

Get the quaternion from a given point and quaterion toward another point.

Get the quaternion from a given point and quaterion toward another point

Definition at line 1088 of file al_Quat.hpp.


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