#include <quat.h>
Nevrax France
Definition at line 74 of file quat.h.
Public Member Functions | |
Basic Quaternions operations. | |
CQuatT | conjugate () const |
return the conjugate of this quaternion. | |
void | invert () |
Invert this quaternion. If normalized, conjugate is faster and does same thing. | |
CQuatT | inverted () const |
return the quaternion inverted. | |
CQuatT | operator * (const CQuatT &) const |
Quaternion multiplication/composition. | |
CQuatT & | operator *= (const CQuatT &) |
return the conjugate of this quaternion. | |
Object | |
CQuatT (const CAngleAxis &aa) | |
ctor of a UNIT quaternion, from an angle axis. | |
CQuatT (const CVector &axis, float angle) | |
ctor of a UNIT quaternion, from an angle axis. | |
CQuatT (T X, T Y, T Z, T W) | |
ctor of a UNIT quaternion, from an angle axis. | |
CQuatT () | |
ctor of a UNIT quaternion, from an angle axis. | |
Comparison | |
bool | equal (const CQuatT &a, float epsilon=1E-6f) const |
void | identity () |
bool | isIdentity () const |
bool | operator== (const CQuatT &a) const |
Misc. | |
CQuatT | exp () |
compute quaternion exponent. | |
CQuatT | log () |
compute logn quaternion. | |
void | makeClosest (const CQuatT &o) |
ensure that *this and q are on same side of hypersphere, ie dotProduct(*this,q) is >0, modifying this if necessary. | |
void | serial (IStream &f) |
serial. | |
To/From other orientation. | |
float | getAngle () const |
Return the equivalent angle of this quaternion. (in radian). | |
CAngleAxis | getAngleAxis () const |
Return the equivalent Unit AngleAxis of this quaternion. | |
CVector | getAxis () const |
Return the equivalent Unit axis of this quaternion. | |
void | setAngleAxis (const CAngleAxis &angAxis) |
Build a UNIT quaternion from an AngleAxis. | |
void | setAngleAxis (const CVector &axis, float angle) |
Build a UNIT quaternion from an AngleAxis. | |
4D vector operations. | |
T | norm () const |
return the norm of the 4D vector. | |
void | normalize () |
Normalize the quaternion. | |
CQuatT | normed () const |
Return the quaternion normalized. | |
CQuatT | operator * (T f) const |
return the norm of the 4D vector. | |
CQuatT & | operator *= (T f) |
return the norm of the 4D vector. | |
CQuatT | operator+ () const |
return the norm of the 4D vector. | |
CQuatT | operator+ (const CQuatT &o) const |
return the norm of the 4D vector. | |
CQuatT & | operator+= (const CQuatT &o) |
return the norm of the 4D vector. | |
CQuatT | operator- () const |
return the norm of the 4D vector. | |
CQuatT | operator- (const CQuatT &o) const |
return the norm of the 4D vector. | |
CQuatT & | operator-= (const CQuatT &o) |
return the norm of the 4D vector. | |
CQuatT | operator/ (T f) const |
return the norm of the 4D vector. | |
CQuatT & | operator/= (T f) |
return the norm of the 4D vector. | |
T | sqrnorm () const |
return the square of the norm of the 4D vector. | |
Sets. | |
void | set (T X, T Y, T Z, T W) |
Static Public Member Functions | |
Quaternions static functions. | |
T | dotProduct (const CQuatT< T > &q0, const CQuatT< T > &q1) |
Return the dotProduct of 2 quaternions. | |
CQuatT | lnDif (const CQuatT &q0, const CQuatT &q1) |
compute lnDiff of q0.inverted()*q1. | |
CQuatT | slerp (const CQuatT< T > &q0, const CQuatT< T > &q1, float t) |
CQuatT | squad (const CQuatT< T > &q0, const CQuatT< T > &tgtQ0, const CQuatT< T > &tgtQ1, const CQuatT< T > &q1, float t) |
CQuatT | squadrev (const CAngleAxis &rot, const CQuatT< T > &q0, const CQuatT< T > &tgtQ0, const CQuatT< T > &tgtQ1, const CQuatT< T > &q1, float t) |
Data Fields | |
T | w |
T | x |
T | y |
T | z |
|
ctor of a UNIT quaternion, from an angle axis.
Definition at line 84 of file quat.h. Referenced by NLMISC::CQuatT< float >::conjugate(), NLMISC::CQuatT< float >::operator *(), NLMISC::CQuatT< float >::operator+(), NLMISC::CQuatT< float >::operator-(), and NLMISC::CQuatT< float >::operator/().
|
|
ctor of a UNIT quaternion, from an angle axis.
Definition at line 85 of file quat.h.
|
|
ctor of a UNIT quaternion, from an angle axis.
Definition at line 87 of file quat.h.
00087 {setAngleAxis(axis, angle);} |
|
ctor of a UNIT quaternion, from an angle axis.
Definition at line 89 of file quat.h.
00089 {setAngleAxis(aa);} |
|
return the conjugate of this quaternion.
Definition at line 139 of file quat.h. Referenced by NLMISC::CQuatT< T >::invert().
|
|
Return the dotProduct of 2 quaternions.
Definition at line 309 of file quat.h. References NLMISC::CQuatT< T >::w, NLMISC::CQuatT< T >::x, NLMISC::CQuatT< T >::y, and NLMISC::CQuatT< T >::z. Referenced by NLMISC::CQuatT< T >::makeClosest().
00310 {
00311 return q0.x*q1.x + q0.y*q1.y + q0.z*q1.z + q0.w*q1.w;
00312 }
|
|
Definition at line 227 of file quat.h. References NLMISC::CQuatT< T >::w, w, NLMISC::CQuatT< T >::x, x, NLMISC::CQuatT< T >::y, y, NLMISC::CQuatT< T >::z, and z.
|
|
compute quaternion exponent.
Definition at line 445 of file quat.h. References len, NLMISC::QuatEpsilon, x, y, and z.
|
|
Return the equivalent angle of this quaternion. (in radian).
Definition at line 148 of file quat.h. Referenced by NLMISC::CQuatT< float >::getAngleAxis().
|
|
Return the equivalent Unit AngleAxis of this quaternion.
Definition at line 150 of file quat.h.
|
|
Return the equivalent Unit axis of this quaternion.
Definition at line 146 of file quat.h. Referenced by NLMISC::CQuatT< float >::getAngleAxis().
|
|
Definition at line 102 of file quat.h. Referenced by NLMISC::CQuatT< T >::normalize().
|
|
Invert this quaternion. If normalized, conjugate is faster and does same thing.
Definition at line 265 of file quat.h. References NLMISC::CQuatT< T >::conjugate(), and NLMISC::CQuatT< T >::sqrnorm(). Referenced by NLMISC::CQuatT< float >::inverted().
|
|
return the quaternion inverted.
Definition at line 137 of file quat.h. Referenced by NLMISC::CQuatT< T >::lnDif().
00137 {CQuatT ret= *this; ret.invert(); return ret;} |
|
Definition at line 103 of file quat.h.
|
|
compute lnDiff of q0.inverted()*q1.
Definition at line 462 of file quat.h. References NLMISC::CQuatT< T >::inverted(), NLMISC::CQuatT< T >::log(), and NLMISC::CQuatT< T >::normalize().
00463 {
00464 CQuatT<T> dif = q0.inverted()*q1;
00465 dif.normalize();
00466
00467 return dif.log();
00468 }
|
|
compute logn quaternion.
Definition at line 427 of file quat.h. References len, NLMISC::QuatEpsilon, w, x, y, and z. Referenced by NLMISC::CQuatT< T >::lnDif().
|
|
ensure that *this and q are on same side of hypersphere, ie dotProduct(*this,q) is >0, modifying this if necessary.
Definition at line 473 of file quat.h. References NLMISC::CQuatT< T >::dotProduct().
00474 { 00475 if( dotProduct(*this, o) < 0 ) 00476 *this= -(*this); 00477 } |
|
return the norm of the 4D vector.
Definition at line 121 of file quat.h. Referenced by NLMISC::CQuatT< float >::getAngle(), and NLMISC::CQuatT< T >::normalize().
00121 {return (T)sqrt(sqrnorm());} |
|
Normalize the quaternion.
Definition at line 280 of file quat.h. References NLMISC::CQuatT< T >::identity(), and NLMISC::CQuatT< T >::norm(). Referenced by NLMISC::CQuatT< T >::lnDif(), and NLMISC::CQuatT< float >::normed().
|
|
Return the quaternion normalized.
Definition at line 125 of file quat.h.
00125 {CQuatT ret= *this; ret.normalize(); return ret;} |
|
Quaternion multiplication/composition.
Definition at line 242 of file quat.h. References NLMISC::CQuatT< T >::w, w, x, NLMISC::CQuatT< T >::x, NLMISC::CQuatT< T >::y, y, z, and NLMISC::CQuatT< T >::z.
|
|
return the norm of the 4D vector.
Definition at line 114 of file quat.h.
|
|
return the conjugate of this quaternion.
Definition at line 256 of file quat.h.
00257 { 00258 *this= *this * o; 00259 return *this; 00260 } |
|
return the norm of the 4D vector.
Definition at line 110 of file quat.h.
|
|
return the norm of the 4D vector.
Definition at line 117 of file quat.h.
00117 {return *this; } |
|
return the norm of the 4D vector.
Definition at line 112 of file quat.h.
|
|
return the norm of the 4D vector.
Definition at line 108 of file quat.h.
|
|
return the norm of the 4D vector.
Definition at line 116 of file quat.h.
|
|
return the norm of the 4D vector.
Definition at line 113 of file quat.h.
|
|
return the norm of the 4D vector.
Definition at line 109 of file quat.h.
|
|
return the norm of the 4D vector.
Definition at line 115 of file quat.h.
|
|
return the norm of the 4D vector.
Definition at line 111 of file quat.h.
|
|
Definition at line 100 of file quat.h.
|
|
serial.
Definition at line 168 of file quat.h.
|
|
Definition at line 95 of file quat.h. Referenced by NLMISC::CQuatT< T >::squadrev().
|
|
Build a UNIT quaternion from an AngleAxis.
Definition at line 155 of file quat.h.
00155 {setAngleAxis(angAxis.Axis, angAxis.Angle);} |
|
Build a UNIT quaternion from an AngleAxis.
Definition at line 294 of file quat.h. Referenced by NLMISC::CQuatT< float >::CQuatT(), and NLMISC::CQuatT< float >::setAngleAxis().
|
|
Quaternion spherical linear interpolation. when t==0, ret==q0, when t==1, ret==q1. No hemisphere correction is made. Definition at line 317 of file quat.h. References t. Referenced by NLMISC::CQuatT< T >::squad().
00318 { 00319 // omega is the 4D angle between q0 and q1. 00320 double omega, cosom,sinom; 00321 T factq0= 1; 00322 T s0,s1; 00323 00324 cosom = CQuatT<T>::dotProduct(q0, q1); 00325 00326 // Make q0 and q1 on the same hemisphere. 00327 /*if(cosom<0) 00328 { 00329 cosom= -cosom; 00330 factq0= -1; 00331 }*/ 00332 // ???? 00333 00334 if ( cosom < 1.0 - NLMISC::QuatEpsilon) 00335 { 00336 omega = acos(cosom); 00337 sinom = sin(omega); 00338 s0 = (T) (sin((1.0f - t)*omega) / sinom); 00339 s1 = (T) (sin(t*omega) / sinom); 00340 } 00341 else 00342 { // q0 and q1 are nearly the same => sinom nearly 0. We can't slerp. 00343 // just linear interpolate. 00344 s0 = (T)(1.0 - t); 00345 s1 = t; 00346 } 00347 00348 return q0*(factq0*s0) + q1*s1; 00349 00350 } |
|
return the square of the norm of the 4D vector.
Definition at line 119 of file quat.h. Referenced by NLMISC::CQuatT< T >::invert(), and NLMISC::CQuatT< float >::norm().
|
|
Quaternion Quadratic spherical linear interpolation. when t==0, ret==q0, when t==1, ret==q1. No hemisphere correction is made. Definition at line 355 of file quat.h. References NLMISC::CQuatT< T >::slerp(), and t.
|
|
Quaternion Quadratic spherical linear interpolation, with multi revision support. Definition at line 366 of file quat.h. References NLMISC::CAngleAxis::Angle, NLMISC::CAngleAxis::Axis, NLMISC::Pi, NLMISC::QuatEpsilon, s, NLMISC::CQuatT< T >::set(), t, v, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z.
00367 { 00368 float s,v; 00369 float omega = rot.Angle* 0.5f; 00370 float nrevs = 0.0f; 00371 CQuatT<T> ret,qaxis,pp,qq; 00372 00373 // just one rev? 00374 //============== 00375 if (omega<Pi-QuatEpsilon) 00376 { 00377 ret = CQuatT<T>::squad(q0,tgtQ0,tgtQ1,q1,t); 00378 return ret; 00379 } 00380 00381 00382 // multirev. 00383 //============== 00384 00385 // rotation of 180deg around rot.Axis. (=> sin(a/2)==sin(Pi/2)==1, and c(a/2)=0). 00386 qaxis.set(rot.Axis.x, rot.Axis.y, rot.Axis.z, 0); 00387 00388 // the number of revisions (float!) 00389 nrevs= (float)(omega/Pi); 00390 // Angle>2Pi. squad from 0 to Pi, slerp from Pi to Angle-Pi, squad from Angle-Pi to Angle. 00391 s = t*2*nrevs; 00392 00393 00394 // So for s, squad from 0 to 1, slerp from 1 to 2*nrevs-1, squad from 2*nrevs-1 to 2*nrevs. 00395 if (s < 1.0f) 00396 { 00397 // first part. 00398 pp = q0*qaxis; 00399 ret = CQuatT<T>::squad(q0,tgtQ0,pp,pp,s); 00400 } 00401 else 00402 { 00403 v = s - (2.0f*nrevs - 1.0f); 00404 if( v <= 0.0f) 00405 { 00406 // middle part 00407 while (s >= 2.0f) s -= 2.0f; 00408 pp = q0*qaxis; 00409 // s vary from 1 to 2. This is still correct for slerp(). 00410 ret = CQuatT<T>::slerp(q0,pp,s); 00411 } 00412 else 00413 { 00414 // Last part. 00415 qq = - q1*qaxis; 00416 ret= CQuatT<T>::squad(qq,qq,tgtQ1,q1,v); 00417 } 00418 } 00419 00420 return ret; 00421 } |
|
|
|
|