40 #ifndef _quaternion_cpp
41 #define _quaternion_cpp
43 #include "stringtool.h"
44 #include "quaternion.h"
48 #include "matrix3x3.h"
49 #include "exception.h"
52 #include "btBulletDynamicsCommon.h"
114 Real HalfAngle ( 0.5*Angle );
117 this->
X = AngleSin * Axis.
X;
118 this->
Y = AngleSin * Axis.
Y;
119 this->
Z = AngleSin * Axis.
Z;
130 this->
W = Root * 0.5;
136 static size_t s_iNext[3] = { 1, 2, 0 };
142 size_t J = s_iNext[I];
143 size_t K = s_iNext[J];
146 Real* QuatMem[3] = { &
X, &
Y, &
Z };
147 *QuatMem[I] = 0.5 * Root;
150 *QuatMem[J] = (Mat.
Matrix[J][I] + Mat.
Matrix[I][J]) * Root;
151 *QuatMem[K] = (Mat.
Matrix[K][I] + Mat.
Matrix[I][K]) * Root;
174 return this->
X * Other.
X + this->
Y * Other.
Y + this->
Z * Other.
Z + this->
W * Other.
W;
194 {
return *
this /
Length(); }
202 Real InvNorm = 1.f/Norm;
203 return Quaternion(
W*InvNorm,-
X*InvNorm,-
Y*InvNorm,-Z*InvNorm);
220 { Other.normalize(); }
234 Ogre::Quaternion Other;
240 { Other.normalise(); }
286 return Quaternion(this->
X * Scalar,this->
Y * Scalar,this->
Z * Scalar,this->
W * Scalar);
293 return *
this * ( 1.0 / Scalar );
300 {
return Quaternion(this->
X+Other.
X, this->Y+Other.
Y, this->Z+Other.
Z, this->W+Other.
W); }
303 {
return Quaternion(this->
X+Other.x, this->Y+Other.y, this->Z+Other.z, this->W+Other.w); }
306 {
return Quaternion(this->
X+Other.x(), this->
Y+Other.y(), this->
Z+Other.z(), this->
W+Other.w()); }
309 {
return Quaternion(this->
X-Other.
X, this->Y-Other.
Y, this->Z-Other.
Z, this->W-Other.
W); }
312 {
return Quaternion(this->
X-Other.x, this->Y-Other.y, this->Z-Other.z, this->W-Other.w); }
315 {
return Quaternion(this->
X-Other.x(), this->
Y-Other.y(), this->
Z-Other.z(), this->
W-Other.w()); }
321 this->
W * Other.
X + this->X * Other.
W + this->Y * Other.
Z - this->Z * Other.
Y,
322 this->W * Other.
Y + this->Y * Other.
W + this->Z * Other.
X - this->X * Other.
Z,
323 this->W * Other.
Z + this->Z * Other.
W + this->X * Other.
Y - this->Y * Other.
X,
324 this->W * Other.
W - this->X * Other.
X + this->Y * Other.
Y - this->Z * Other.
Z
332 this->
W * Other.x + this->X * Other.w + this->Y * Other.z - this->Z * Other.y,
333 this->W * Other.y + this->Y * Other.w + this->Z * Other.x - this->X * Other.z,
334 this->W * Other.z + this->Z * Other.w + this->X * Other.y - this->Y * Other.x,
335 this->W * Other.w - this->X * Other.x + this->Y * Other.y - this->Z * Other.z
343 this->
W * Other.x() + this->
X * Other.w() + this->
Y * Other.z() - this->
Z * Other.y(),
344 this->
W * Other.y() + this->
Y * Other.w() + this->
Z * Other.x() - this->
X * Other.z(),
345 this->
W * Other.z() + this->
Z * Other.w() + this->
X * Other.y() - this->
Y * Other.x(),
346 this->
W * Other.w() - this->
X * Other.x() + this->
Y * Other.y() - this->
Z * Other.z()
361 return Other + UV + UUV;
369 this->
X=this->
X+Other.
X;
370 this->
Y=this->
Y+Other.
Y;
371 this->
Z=this->
Z+Other.
Z;
372 this->
W=this->
W+Other.
W;
378 this->
X=this->
X+Other.x;
379 this->
Y=this->
Y+Other.y;
380 this->
Z=this->
Z+Other.z;
381 this->
W=this->
W+Other.w;
387 this->
X=this->
X+Other.x();
388 this->
Y=this->
Y+Other.y();
389 this->
Z=this->
Z+Other.z();
390 this->
W=this->
W+Other.w();
396 this->
X=this->
X-Other.
X;
397 this->
Y=this->
Y-Other.
Y;
398 this->
Z=this->
Z-Other.
Z;
399 this->
W=this->
W-Other.
W;
405 this->
X=this->
X-Other.x;
406 this->
Y=this->
Y-Other.y;
407 this->
Z=this->
Z-Other.z;
408 this->
W=this->
W-Other.w;
414 this->
X=this->
X-Other.x();
415 this->
Y=this->
Y-Other.y();
416 this->
Z=this->
Z-Other.z();
417 this->
W=this->
W-Other.w();
448 {
return (this->
X==Other.
X && this->Y==Other.
Y && this->Z==Other.
Z && this->W==Other.
W); }
451 {
return (this->
X==Other.x && this->Y==Other.y && this->Z==Other.z && this->W==Other.w); }
454 {
return (this->
X==Other.getX() && this->
Y==Other.getY() && this->
Z==Other.getZ() && this->
W==Other.getW()); }
457 {
return (this->
X!=Other.
X || this->Y!=Other.
Y || this->Z!=Other.
Z || this->W!=Other.
W); }
460 {
return (this->
X!=Other.x || this->Y!=Other.y || this->Z!=Other.z || this->W!=Other.w); }
463 {
return (this->
X!=Other.getX() || this->
Y!=Other.getY() || this->
Z!=Other.getZ() || this->
W!=Other.getW()); }
466 {
return (this->X<=Other.X && this->Y<=Other.Y && this->Z<=Other.Z && this->
W<=Other.
W); }
468 {
return (this->
X>=Other.
X && this->Y>=Other.
Y && this->Z>=Other.
Z && this->W>=Other.
W); }
481 if( VersionAttr && XAttr && YAttr && ZAttr && WAttr)
514 {
return String(
"Quaternion"); }
522 {
return Other2+Other; }
525 {
return Other2+Other; }
531 {
return Mezzanine::Quaternion(Other.getX()-Other2.
X, Other.getY()-Other2.
Y, Other.getZ()-Other2.
Z, Other.getW()-Other2.
W); }
542 btQuaternion& operator<< ( btQuaternion& Other,
const Ogre::Quaternion& Other2)
544 Other.setX(Other2.x);
545 Other.setY(Other2.y);
546 Other.setZ(Other2.z);
547 Other.setW(Other2.w);
569 Ogre::Quaternion& operator<< ( Ogre::Quaternion& Other,
const btQuaternion& Other2)
571 Other.x=Other2.getX();
572 Other.y=Other2.getY();
573 Other.z=Other2.getZ();
574 Other.w=Other2.getW();
595 #endif // \_quaternion_cpp