#include <GLQuaternion.h>
Collaboration diagram for mathglpp::GLQuaternion< T >:
It behaves mathematically much like a plane in 3D, where a rotation is a reflection about two planes, one with the normal at half the angle and another at the angle. It is useful for rotations in 3D space because multiplications of quaternions are commutative, ie. it doesn't matter in which order you do them.
Definition at line 34 of file GLQuaternion.h.
Public Member Functions | |
GLQuaternion () | |
Create a unit quaternion. | |
GLQuaternion (T f, const GLVector3< T > &gv) | |
Create a scaled directed quaternion. | |
GLQuaternion (const GLVector3< T > &gv) | |
Create a directed quaternion. | |
GLQuaternion (const T *gq) | |
Create from array, must be at least 4 elements long. | |
GLQuaternion (const GLQuaternion &gq) | |
Copy a quaternion. | |
GLQuaternion (GLVector3< T > gv, T degrees) | |
Create a rotation quaternion, *MOST PEOPLE WILL WANT TO USE THIS CONSTRUCTOR ONLY* NB. | |
~GLQuaternion () | |
Default destructor. | |
T | getW () |
Get real or plane constant. | |
const GLVector3< T > & | getV () |
Get imaginary or plane normal. | |
void | set (T _w, const GLVector3< T > &gv) |
set from a scaled vector. | |
void | set (T _w, T x, T y, T z) |
Set from immediates. | |
void | set (const T *gq) |
Set from array, must be at least 4 elements long. | |
void | set (GLVector3< T > vec, T degrees) |
Set from angle and normal, NB. | |
GLQuaternion | operator+ (GLQuaternion gq) |
Quaternion addition. | |
GLQuaternion | operator- (GLQuaternion gq) |
Quaternion subtraction. | |
GLQuaternion & | operator+= (GLQuaternion gq) |
Quaternion self referenced addition. | |
GLQuaternion & | operator-= (GLQuaternion gq) |
Quaternion self referenced subtraction. | |
GLQuaternion | operator * (GLQuaternion gq) |
Quaternion multiplication. | |
GLQuaternion | operator/ (T f) |
Quaternion division, NB. Do not divide by 0, there are no safety catches for that. | |
GLQuaternion & | operator *= (GLQuaternion gq) |
Quaternion self referenced multiplication. | |
GLQuaternion & | operator/= (T f) |
Quaternion self referenced division. | |
T | dot (GLQuaternion gq) |
Quaternion dot product. | |
GLQuaternion | getCross (GLQuaternion gq) |
Quaternion cross product. | |
GLQuaternion | getConjugate () |
Quaternion complex conjugate. | |
GLQuaternion & | conjugate () |
Quaternion self referenced complex conjugate. | |
GLQuaternion | getInverse () |
Quaternion inverse (more like a normalised conjugate). | |
GLQuaternion & | inverse () |
Quaternion self referenced inverse (more like a normalised conjugate). | |
T | selection () |
Real part. | |
T | norm () |
Quaternion norm (similar to vector length). | |
GLQuaternion | unit () const |
Quaternion unit. | |
GLQuaternion & | normalise () |
Quaternion self referenced unit. | |
GLQuaternion & | normalize () |
GLVector3< T > | rotateVector (const GLVector3< T > &gv) |
GLVector interface method for ease of use. | |
GLMatrix< T > | matrix (void) |
GLMatrix interface method for obtaining an equivalent rotation matrix. |
mathglpp::GLQuaternion< T >::GLQuaternion | ( | ) | [inline] |
Create a unit quaternion.
Definition at line 38 of file GLQuaternion.h.
Referenced by mathglpp::GLQuaternion< T >::getCross(), and mathglpp::GLQuaternion< T >::rotateVector().
mathglpp::GLQuaternion< T >::GLQuaternion | ( | T | f, | |
const GLVector3< T > & | gv | |||
) | [inline] |
mathglpp::GLQuaternion< T >::GLQuaternion | ( | const GLVector3< T > & | gv | ) | [inline] |
mathglpp::GLQuaternion< T >::GLQuaternion | ( | const T * | gq | ) | [inline] |
mathglpp::GLQuaternion< T >::GLQuaternion | ( | const GLQuaternion< T > & | gq | ) | [inline] |
mathglpp::GLQuaternion< T >::GLQuaternion | ( | GLVector3< T > | gv, | |
T | degrees | |||
) | [inline] |
Create a rotation quaternion, *MOST PEOPLE WILL WANT TO USE THIS CONSTRUCTOR ONLY* NB.
Do not halve angle, this is done within the constructor. *TO CONFORM WITH THE OpenGL INTERFACE THE ANGLES MUST BE GIVEN IN DEGREES
Definition at line 66 of file GLQuaternion.h.
References mathglpp::GLVector3< T >::unit().
Here is the call graph for this function:
mathglpp::GLQuaternion< T >::~GLQuaternion | ( | ) | [inline] |
T mathglpp::GLQuaternion< T >::getW | ( | ) | [inline] |
const GLVector3<T>& mathglpp::GLQuaternion< T >::getV | ( | ) | [inline] |
void mathglpp::GLQuaternion< T >::set | ( | T | _w, | |
const GLVector3< T > & | gv | |||
) | [inline] |
void mathglpp::GLQuaternion< T >::set | ( | T | _w, | |
T | x, | |||
T | y, | |||
T | z | |||
) | [inline] |
void mathglpp::GLQuaternion< T >::set | ( | const T * | gq | ) | [inline] |
void mathglpp::GLQuaternion< T >::set | ( | GLVector3< T > | vec, | |
T | degrees | |||
) | [inline] |
Set from angle and normal, NB.
Do not halve angle it is done internally. TO CONFORM WITH THE OpenGL INTERFACE THE ANGLES MUST BE GIVEN IN DEGREES
Definition at line 94 of file GLQuaternion.h.
GLQuaternion mathglpp::GLQuaternion< T >::operator+ | ( | GLQuaternion< T > | gq | ) | [inline] |
Quaternion addition.
Definition at line 98 of file GLQuaternion.h.
00099 { GLQuaternion temp(*this); temp += gq; return temp; }
GLQuaternion mathglpp::GLQuaternion< T >::operator- | ( | GLQuaternion< T > | gq | ) | [inline] |
Quaternion subtraction.
Definition at line 102 of file GLQuaternion.h.
00103 { GLQuaternion temp(*this); temp -= gq; return temp; }
GLQuaternion& mathglpp::GLQuaternion< T >::operator+= | ( | GLQuaternion< T > | gq | ) | [inline] |
Quaternion self referenced addition.
Definition at line 106 of file GLQuaternion.h.
References mathglpp::GLQuaternion< T >::v, and mathglpp::GLQuaternion< T >::w.
GLQuaternion& mathglpp::GLQuaternion< T >::operator-= | ( | GLQuaternion< T > | gq | ) | [inline] |
Quaternion self referenced subtraction.
Definition at line 110 of file GLQuaternion.h.
References mathglpp::GLQuaternion< T >::v, and mathglpp::GLQuaternion< T >::w.
GLQuaternion mathglpp::GLQuaternion< T >::operator * | ( | GLQuaternion< T > | gq | ) | [inline] |
Quaternion multiplication.
Definition at line 114 of file GLQuaternion.h.
00115 { GLQuaternion temp(*this); temp *= gq; return temp; }
GLQuaternion mathglpp::GLQuaternion< T >::operator/ | ( | T | f | ) | [inline] |
Quaternion division, NB. Do not divide by 0, there are no safety catches for that.
Definition at line 118 of file GLQuaternion.h.
Referenced by mathglpp::GLQuaternion< T >::unit().
00119 { GLQuaternion temp(*this); temp /= f; return temp; }
GLQuaternion& mathglpp::GLQuaternion< T >::operator *= | ( | GLQuaternion< T > | gq | ) | [inline] |
Quaternion self referenced multiplication.
Definition at line 122 of file GLQuaternion.h.
References mathglpp::GLQuaternion< T >::v, and mathglpp::GLQuaternion< T >::w.
GLQuaternion& mathglpp::GLQuaternion< T >::operator/= | ( | T | f | ) | [inline] |
Quaternion self referenced division.
Definition at line 126 of file GLQuaternion.h.
Referenced by mathglpp::GLQuaternion< T >::normalize().
T mathglpp::GLQuaternion< T >::dot | ( | GLQuaternion< T > | gq | ) | [inline] |
Quaternion dot product.
Definition at line 130 of file GLQuaternion.h.
References mathglpp::GLQuaternion< T >::v, and mathglpp::GLQuaternion< T >::w.
GLQuaternion mathglpp::GLQuaternion< T >::getCross | ( | GLQuaternion< T > | gq | ) | [inline] |
Quaternion cross product.
Definition at line 134 of file GLQuaternion.h.
References mathglpp::GLQuaternion< T >::GLQuaternion(), mathglpp::GLQuaternion< T >::v, and mathglpp::GLQuaternion< T >::w.
Referenced by mathglpp::GLQuaternion< T >::rotateVector().
00135 { return GLQuaternion( w * gq.w - v.dot(gq.v) , (gq.v * w) + (v * gq.w) + v.getCross(gq.v) ); }
Here is the call graph for this function:
GLQuaternion mathglpp::GLQuaternion< T >::getConjugate | ( | ) | [inline] |
Quaternion complex conjugate.
Definition at line 138 of file GLQuaternion.h.
References mathglpp::GLQuaternion< T >::conjugate().
Referenced by mathglpp::GLQuaternion< T >::rotateVector().
00139 { GLQuaternion temp(*this); temp.conjugate(); return temp; }
Here is the call graph for this function:
GLQuaternion& mathglpp::GLQuaternion< T >::conjugate | ( | ) | [inline] |
Quaternion self referenced complex conjugate.
Definition at line 142 of file GLQuaternion.h.
Referenced by mathglpp::GLQuaternion< T >::getConjugate(), and mathglpp::GLQuaternion< T >::inverse().
GLQuaternion mathglpp::GLQuaternion< T >::getInverse | ( | ) | [inline] |
Quaternion inverse (more like a normalised conjugate).
Definition at line 146 of file GLQuaternion.h.
References mathglpp::GLQuaternion< T >::inverse().
00147 { GLQuaternion temp(*this); temp.inverse(); return temp; }
Here is the call graph for this function:
GLQuaternion& mathglpp::GLQuaternion< T >::inverse | ( | ) | [inline] |
Quaternion self referenced inverse (more like a normalised conjugate).
Definition at line 150 of file GLQuaternion.h.
References mathglpp::GLQuaternion< T >::conjugate(), and mathglpp::GLQuaternion< T >::norm().
Referenced by mathglpp::GLQuaternion< T >::getInverse().
Here is the call graph for this function:
T mathglpp::GLQuaternion< T >::selection | ( | ) | [inline] |
T mathglpp::GLQuaternion< T >::norm | ( | ) | [inline] |
Quaternion norm (similar to vector length).
Definition at line 158 of file GLQuaternion.h.
Referenced by mathglpp::GLQuaternion< T >::inverse(), mathglpp::GLQuaternion< T >::normalize(), and mathglpp::GLQuaternion< T >::unit().
GLQuaternion mathglpp::GLQuaternion< T >::unit | ( | ) | const [inline] |
Quaternion unit.
Definition at line 162 of file GLQuaternion.h.
References mathglpp::GLQuaternion< T >::norm(), and mathglpp::GLQuaternion< T >::operator/().
00163 { return this->operator /(norm()); }
Here is the call graph for this function:
GLQuaternion& mathglpp::GLQuaternion< T >::normalise | ( | ) | [inline] |
Quaternion self referenced unit.
Definition at line 166 of file GLQuaternion.h.
References mathglpp::GLQuaternion< T >::normalize().
00166 { return normalize(); }
Here is the call graph for this function:
GLVector3<T> mathglpp::GLQuaternion< T >::rotateVector | ( | const GLVector3< T > & | gv | ) | [inline] |
GLVector interface method for ease of use.
THIS IS PROBABLY THE ONLY METHOD YOU WOULD NORMALLY USE. NB. Don't forget to normalise the quaternion unless you want axial translation as well as rotation.
Definition at line 173 of file GLQuaternion.h.
References mathglpp::GLQuaternion< T >::getConjugate(), mathglpp::GLQuaternion< T >::getCross(), mathglpp::GLQuaternion< T >::GLQuaternion(), and mathglpp::GLQuaternion< T >::v.
00174 { GLQuaternion temp = getCross(GLQuaternion(gv)); temp *= getConjugate(); return temp.v; }
Here is the call graph for this function:
GLMatrix<T> mathglpp::GLQuaternion< T >::matrix | ( | void | ) | [inline] |
GLMatrix interface method for obtaining an equivalent rotation matrix.
You would se this for interfacing with the OpenGL matrix stacks.
Definition at line 178 of file GLQuaternion.h.
00179 { 00180 GLMatrix<T> temp; 00181 00182 T xx=v.x*v.x; T xy=v.x*v.y; T xz=v.x*v.z; T xw=v.x*w; 00183 T yy=v.y*v.y; T yz=v.y*v.z; T yw=v.y*w; 00184 T zz=v.z*v.z; T zw=v.z*w; 00185 00186 temp[0] = 1 - 2*(zz + yy); 00187 temp[1] = 2*(xy + zw); 00188 temp[2] = 2*(xz - yw); 00189 temp[3] = 0; 00190 00191 temp[4] = 2*(xy - zw); 00192 temp[5] = 1 - 2*(zz + xx); 00193 temp[6] = 2*(yz + xw); 00194 temp[7] = 0; 00195 00196 temp[8] = 2*(yw + xz); 00197 temp[9] = 2*(yz - xw); 00198 temp[10] = 1 - 2*(yy + xx); 00199 temp[11] = 0; 00200 00201 temp[12] = 0; 00202 temp[13] = 0; 00203 temp[14] = 0; 00204 temp[15] = 1; 00205 00206 return temp; 00207 }