Spinning Topp Logo BlackTopp Studios
inc
quaternion.cpp
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _quaternion_cpp
41 #define _quaternion_cpp
42 
43 #include "stringtool.h"
44 #include "quaternion.h"
45 #include "MathTools/mathtools.h"
46 #include "serialization.h"
47 #include "vector3.h"
48 #include "matrix3x3.h"
49 #include "exception.h"
50 
51 #include <Ogre.h>
52 #include "btBulletDynamicsCommon.h"
53 
54 #include <cmath>
55 #include <memory>
56 
57 namespace Mezzanine
58 {
59  ///////////////////////////////////////////////////////////////////////////////
60  // Constructors
62  { this->SetIdentity(); }
63 
64  Quaternion::Quaternion(const Real& X, const Real& Y, const Real& Z, const Real& W)
65  { this->SetValues(X,Y,Z,W); }
66 
67  Quaternion::Quaternion(const Real& Angle, const Vector3& Axis)
68  { this->SetFromAxisAngle(Angle,Axis); }
69 
71  { this->SetFromMatrix3x3(Mat); }
72 
73  Quaternion::Quaternion(const Vector3& AxisX, const Vector3& AxisY, const Vector3& AxisZ)
74  { this->SetFromAxes(AxisX,AxisY,AxisZ); }
75 
76  Quaternion::Quaternion(const Vector3& DirectionAxis, const Vector3& UpAxis)
77  { this->SetFromAxisToZ(DirectionAxis,UpAxis); }
78 
79  Quaternion::Quaternion(const btQuaternion& Other)
80  { this->ExtractBulletQuaternion(Other); }
81 
82  Quaternion::Quaternion(const Ogre::Quaternion& Other)
83  { this->ExtractOgreQuaternion(Other); }
84 
86  {
87  this->X = Other.X;
88  this->Y = Other.Y;
89  this->Z = Other.Z;
90  this->W = Other.W;
91  }
92 
94  { this->ProtoDeSerialize(OneNode); }
95 
96  ///////////////////////////////////////////////////////////////////////////////
97  // Fancy Math and Utilities
98 
100  {
101  this->X = 0;
102  this->Y = 0;
103  this->Z = 0;
104  this->W = 1;
105  }
106 
107  void Quaternion::SetValues(const Real& X, const Real& Y, const Real& Z, const Real& W)
108  {
109  this->X = X;
110  this->Y = Y;
111  this->Z = Z;
112  this->W = W;
113  }
114 
115  void Quaternion::SetFromAxisAngle(const Real& Angle, const Vector3& Axis)
116  {
117  Real HalfAngle ( 0.5*Angle );
118  Real AngleSin = MathTools::Sin(HalfAngle);
119  this->W = MathTools::Cos(HalfAngle);
120  this->X = AngleSin * Axis.X;
121  this->Y = AngleSin * Axis.Y;
122  this->Z = AngleSin * Axis.Z;
123  }
124 
126  {
127  Real Trace = Mat.Matrix[0][0]+Mat.Matrix[1][1]+Mat.Matrix[2][2];
128  Real Root;
129 
130  if(Trace > 0.0)
131  {
132  Root = MathTools::Sqrt(Trace + 1.0);
133  this->W = Root * 0.5;
134  Root = 0.5/Root;
135  this->X = (Mat.Matrix[2][1] - Mat.Matrix[1][2]) * Root;
136  this->Y = (Mat.Matrix[0][2] - Mat.Matrix[2][0]) * Root;
137  this->Z = (Mat.Matrix[1][0] - Mat.Matrix[0][1]) * Root;
138  }else{
139  static size_t s_iNext[3] = { 1, 2, 0 };
140  size_t I = 0;
141  if ( Mat.Matrix[1][1] > Mat.Matrix[0][0] )
142  I = 1;
143  if ( Mat.Matrix[2][2] > Mat.Matrix[I][I] )
144  I = 2;
145  size_t J = s_iNext[I];
146  size_t K = s_iNext[J];
147 
148  Root = MathTools::Sqrt(Mat.Matrix[I][I] - Mat.Matrix[J][J] - Mat.Matrix[K][K] + 1.0);
149  Real* QuatMem[3] = { &X, &Y, &Z };
150  *QuatMem[I] = 0.5 * Root;
151  Root = 0.5 / Root;
152  this->W = (Mat.Matrix[K][J] - Mat.Matrix[J][K]) * Root;
153  *QuatMem[J] = (Mat.Matrix[J][I] + Mat.Matrix[I][J]) * Root;
154  *QuatMem[K] = (Mat.Matrix[K][I] + Mat.Matrix[I][K]) * Root;
155  }
156  }
157 
158  void Quaternion::SetFromAxes(const Vector3& AxisX, const Vector3& AxisY, const Vector3& AxisZ)
159  {
160  Matrix3x3 Mat3;
161 
162  Mat3.Matrix[0][0] = AxisX.X;
163  Mat3.Matrix[1][0] = AxisX.Y;
164  Mat3.Matrix[2][0] = AxisX.Z;
165  Mat3.Matrix[0][1] = AxisY.X;
166  Mat3.Matrix[1][1] = AxisY.Y;
167  Mat3.Matrix[2][1] = AxisY.Z;
168  Mat3.Matrix[0][2] = AxisZ.X;
169  Mat3.Matrix[1][2] = AxisZ.Y;
170  Mat3.Matrix[2][2] = AxisZ.Z;
171 
172  this->SetFromMatrix3x3(Mat3);
173  }
174 
175  void Quaternion::SetFromAxisToZ(const Vector3& DirectionAxis, const Vector3& UpAxis)
176  {
177  Quaternion q;
178  Vector3 zVec = DirectionAxis;
179  zVec.Normalize();
180  Vector3 xVec = UpAxis.CrossProduct( zVec );
181  if( xVec.IsZeroLength() ) {
182  xVec = Vector3::Unit_X();
183  }
184  xVec.Normalize();
185  Vector3 yVec = zVec.CrossProduct( xVec );
186  yVec.Normalize();
187  this->SetFromAxes( xVec, yVec, zVec );
188  }
189 
190  void Quaternion::ConvertToAngleAxis(Real& Angle, Vector3& Axis) const
191  {
192  Real SquareLength = this->X * this->X + this->Y * this->Y + this->Z * this->Z;
193  if( SquareLength < 0.0 ) {
194  Angle = 2.0 * MathTools::ACos(this->W);
195  Real InvLength = 1 / MathTools::Sqrt(SquareLength);
196  Axis.SetValues(this->X * InvLength, this->Y * InvLength, this->Z * InvLength);
197  }else{
198  Angle = 0.0;
199  Axis.SetValues(1.0,0.0,0.0);
200  }
201  }
202 
204  {
205  return this->X * Other.X + this->Y * Other.Y + this->Z * Other.Z + this->W * Other.W;
206  }
207 
209  {
210  return sqrt(LengthSqrd());
211  }
212 
214  {
215  return DotProduct(*this);
216  }
217 
219  {
220  *this = *this / Length();
221  return *this;
222  }
223 
225  { return *this / Length(); }
226 
227 
229  {
230  Real Norm = W*W+X*X+Y*Y+Z*Z;
231  if ( Norm > 0.0 )
232  {
233  Real InvNorm = 1.f/Norm;
234  return Quaternion(W*InvNorm,-X*InvNorm,-Y*InvNorm,-Z*InvNorm);
235  }else{
236  return Quaternion(0,0,0,0);
237  }
238  }
239 
240  ///////////////////////////////////////////////////////////////////////////////
241  // Explicit Conversion
242 
243  btQuaternion Quaternion::GetBulletQuaternion(Boole normalize) const
244  {
245  btQuaternion Other;
246  Other.setX(this->X);
247  Other.setY(this->Y);
248  Other.setZ(this->Z);
249  Other.setW(this->W);
250  if(normalize)
251  { Other.normalize(); }
252  return Other;
253  }
254 
255  void Quaternion::ExtractBulletQuaternion(const btQuaternion &Other)
256  {
257  this->X=Other.x();
258  this->Y=Other.y();
259  this->Z=Other.z();
260  this->W=Other.w();
261  }
262 
263  Ogre::Quaternion Quaternion::GetOgreQuaternion(Boole normalize) const
264  {
265  Ogre::Quaternion Other;
266  Other.x=this->X;
267  Other.y=this->Y;
268  Other.z=this->Z;
269  Other.w=this->W;
270  if(normalize)
271  { Other.normalise(); }
272  return Other;
273  }
274 
275  void Quaternion::ExtractOgreQuaternion(const Ogre::Quaternion &Other)
276  {
277  this->X=Other.x;
278  this->Y=Other.y;
279  this->Z=Other.z;
280  this->W=Other.w;
281  }
282 
283  ///////////////////////////////////////////////////////////////////////////////
284  // Access Operators
285 
286  Real Quaternion::operator[](const Whole& Index) const
287  {
288  switch(Index)
289  {
290  case 0: return X;
291  case 1: return Y;
292  case 2: return Z;
293  case 3: return W;
294  default:
295  { MEZZ_EXCEPTION(ExceptionBase::MM_OUT_OF_BOUNDS_EXCEPTION,"Attempting to get invalid index."); }
296  }
297  }
298 
300  {
301  switch(Index)
302  {
303  case 0: return X;
304  case 1: return Y;
305  case 2: return Z;
306  case 3: return W;
307  default:
308  { MEZZ_EXCEPTION(ExceptionBase::MM_OUT_OF_BOUNDS_EXCEPTION,"Attempting to get invalid index."); }
309  }
310  }
311 
312  ///////////////////////////////////////////////////////////////////////////////
313  // Arithmetic By Real Operators
314 
316  {
317  return Quaternion(this->X * Scalar,this->Y * Scalar,this->Z * Scalar,this->W * Scalar);
318  }
319 
321  {
322  if( 0 == Scalar )
323  { MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Dividing by zero in 'Quaternion::operator/', Quit it."); }
324  return *this * ( 1.0 / Scalar );
325  }
326 
327  ///////////////////////////////////////////////////////////////////////////////
328  // Left Hand Basic Arithmetic Operators
329 
331  { return Quaternion(this->X+Other.X, this->Y+Other.Y, this->Z+Other.Z, this->W+Other.W); }
332 
333  Quaternion Quaternion::operator+ (const Ogre::Quaternion& Other) const
334  { return Quaternion(this->X+Other.x, this->Y+Other.y, this->Z+Other.z, this->W+Other.w); }
335 
336  Quaternion Quaternion::operator+ (const btQuaternion& Other) const
337  { return Quaternion(this->X+Other.x(), this->Y+Other.y(), this->Z+Other.z(), this->W+Other.w()); }
338 
340  { return Quaternion(this->X-Other.X, this->Y-Other.Y, this->Z-Other.Z, this->W-Other.W); }
341 
342  Quaternion Quaternion::operator- (const Ogre::Quaternion& Other) const
343  { return Quaternion(this->X-Other.x, this->Y-Other.y, this->Z-Other.z, this->W-Other.w); }
344 
345  Quaternion Quaternion::operator- (const btQuaternion& Other) const
346  { return Quaternion(this->X-Other.x(), this->Y-Other.y(), this->Z-Other.z(), this->W-Other.w()); }
347 
349  {
350  return Quaternion
351  (
352  this->W * Other.X + this->X * Other.W + this->Y * Other.Z - this->Z * Other.Y,
353  this->W * Other.Y + this->Y * Other.W + this->Z * Other.X - this->X * Other.Z,
354  this->W * Other.Z + this->Z * Other.W + this->X * Other.Y - this->Y * Other.X,
355  this->W * Other.W - this->X * Other.X + this->Y * Other.Y - this->Z * Other.Z
356  );
357  }
358 
359  Quaternion Quaternion::operator* (const Ogre::Quaternion& Other) const
360  {
361  return Quaternion
362  (
363  this->W * Other.x + this->X * Other.w + this->Y * Other.z - this->Z * Other.y,
364  this->W * Other.y + this->Y * Other.w + this->Z * Other.x - this->X * Other.z,
365  this->W * Other.z + this->Z * Other.w + this->X * Other.y - this->Y * Other.x,
366  this->W * Other.w - this->X * Other.x + this->Y * Other.y - this->Z * Other.z
367  );
368  }
369 
370  Quaternion Quaternion::operator* (const btQuaternion& Other) const
371  {
372  return Quaternion
373  (
374  this->W * Other.x() + this->X * Other.w() + this->Y * Other.z() - this->Z * Other.y(),
375  this->W * Other.y() + this->Y * Other.w() + this->Z * Other.x() - this->X * Other.z(),
376  this->W * Other.z() + this->Z * Other.w() + this->X * Other.y() - this->Y * Other.x(),
377  this->W * Other.w() - this->X * Other.x() + this->Y * Other.y() - this->Z * Other.z()
378  );
379  }
380 
381  ///////////////////////////////////////////////////////////////////////////////
382  // Vector Rotation Operators
383 
385  {
386  Vector3 UV, UUV;
387  Vector3 QuatVec(X,Y,Z);
388  UV = QuatVec.CrossProduct(Other);
389  UUV = QuatVec.CrossProduct(UV);
390  UV *= (2.f * W);
391  UUV *= 2.f;
392  return Other + UV + UUV;
393  }
394 
395  ///////////////////////////////////////////////////////////////////////////////
396  // Increment and Decrement Operators
397 
399  {
400  this->X=this->X+Other.X;
401  this->Y=this->Y+Other.Y;
402  this->Z=this->Z+Other.Z;
403  this->W=this->W+Other.W;
404  return *this;
405  }
406 
407  Quaternion& Quaternion::operator+= (const Ogre::Quaternion& Other)
408  {
409  this->X=this->X+Other.x;
410  this->Y=this->Y+Other.y;
411  this->Z=this->Z+Other.z;
412  this->W=this->W+Other.w;
413  return *this;
414  }
415 
416  Quaternion& Quaternion::operator+= (const btQuaternion& Other)
417  {
418  this->X=this->X+Other.x();
419  this->Y=this->Y+Other.y();
420  this->Z=this->Z+Other.z();
421  this->W=this->W+Other.w();
422  return *this;
423  }
424 
426  {
427  this->X=this->X-Other.X;
428  this->Y=this->Y-Other.Y;
429  this->Z=this->Z-Other.Z;
430  this->W=this->W-Other.W;
431  return *this;
432  }
433 
434  Quaternion& Quaternion::operator-= (const Ogre::Quaternion& Other)
435  {
436  this->X=this->X-Other.x;
437  this->Y=this->Y-Other.y;
438  this->Z=this->Z-Other.z;
439  this->W=this->W-Other.w;
440  return *this;
441  }
442 
443  Quaternion& Quaternion::operator-= (const btQuaternion& Other)
444  {
445  this->X=this->X-Other.x();
446  this->Y=this->Y-Other.y();
447  this->Z=this->Z-Other.z();
448  this->W=this->W-Other.w();
449  return *this;
450  }
451 
452  ///////////////////////////////////////////////////////////////////////////////
453  // Assignment Operators
455  {
456  this->X=Other.X;
457  this->Y=Other.Y;
458  this->Z=Other.Z;
459  this->W=Other.W;
460  return *this;
461  }
462 
463  Quaternion& Quaternion::operator= (const btQuaternion& Other)
464  {
466  return *this;
467  }
468 
469  Quaternion& Quaternion::operator= (const Ogre::Quaternion& Other)
470  {
471  ExtractOgreQuaternion(Other);
472  return *this;
473  }
474 
475  ///////////////////////////////////////////////////////////////////////////////
476  // Equality Comparison Operators
477 
479  { return (this->X==Other.X && this->Y==Other.Y && this->Z==Other.Z && this->W==Other.W); }
480 
481  Boole Quaternion::operator==(const Ogre::Quaternion& Other) const
482  { return (this->X==Other.x && this->Y==Other.y && this->Z==Other.z && this->W==Other.w); }
483 
484  Boole Quaternion::operator==(const btQuaternion& Other) const
485  { return (this->X==Other.getX() && this->Y==Other.getY() && this->Z==Other.getZ() && this->W==Other.getW()); }
486 
488  { return (this->X!=Other.X || this->Y!=Other.Y || this->Z!=Other.Z || this->W!=Other.W); }
489 
490  Boole Quaternion::operator!=(const Ogre::Quaternion& Other) const
491  { return (this->X!=Other.x || this->Y!=Other.y || this->Z!=Other.z || this->W!=Other.w); }
492 
493  Boole Quaternion::operator!=(const btQuaternion& Other) const
494  { return (this->X!=Other.getX() || this->Y!=Other.getY() || this->Z!=Other.getZ() || this->W!=Other.getW()); }
495 
497  { return (this->X<=Other.X && this->Y<=Other.Y && this->Z<=Other.Z && this->W<=Other.W); }
499  { return (this->X>=Other.X && this->Y>=Other.Y && this->Z>=Other.Z && this->W>=Other.W); }
500 
501  // Serializable
502  void Quaternion::ProtoSerialize(XML::Node& CurrentRoot) const
503  {
504  Mezzanine::XML::Node VecNode = CurrentRoot.AppendChild(GetSerializableName());
505  VecNode.SetName(GetSerializableName());
506 
507  Mezzanine::XML::Attribute VersionAttr = VecNode.AppendAttribute("Version");
508  Mezzanine::XML::Attribute XAttr = VecNode.AppendAttribute("X");
509  Mezzanine::XML::Attribute YAttr = VecNode.AppendAttribute("Y");
510  Mezzanine::XML::Attribute ZAttr = VecNode.AppendAttribute("Z");
511  Mezzanine::XML::Attribute WAttr = VecNode.AppendAttribute("W");
512  if( VersionAttr && XAttr && YAttr && ZAttr && WAttr)
513  {
514  if( VersionAttr.SetValue("1") && XAttr.SetValue(this->X) && YAttr.SetValue(this->Y) && ZAttr.SetValue(this->Z) && WAttr.SetValue(this->W))
515  {
516  return;
517  }else{
518  SerializeError("Create XML Attribute Values", GetSerializableName(),true);
519  }
520  }else{
521  SerializeError("Create XML Attributes", GetSerializableName(),true);
522  }
523  }
524 
525  // DeSerializable
527  {
529  {
530  if(OneNode.GetAttribute("Version").AsInt() == 1)
531  {
532  this->X=OneNode.GetAttribute("X").AsReal();
533  this->Y=OneNode.GetAttribute("Y").AsReal();
534  this->Z=OneNode.GetAttribute("Z").AsReal();
535  this->W=OneNode.GetAttribute("W").AsReal();
536  }else{
537  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + GetSerializableName() + ": Not Version 1.");
538  }
539  }else{
540  MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_INVALID_EXCEPTION,"Attempting to deserialize a " + GetSerializableName() + ", found a " + Mezzanine::String(OneNode.Name()));
541  }
542  }
543 
545  { return String("Quaternion"); }
546 
547 }
548 
549 ///////////////////////////////////////////////////////////////////////////////
550 // Right Hand Addition Operators
551 
552 Mezzanine::Quaternion operator+ (const Ogre::Quaternion& Other, const Mezzanine::Quaternion& Other2)
553  { return Other2+Other; }
554 
555 Mezzanine::Quaternion operator+ (const btQuaternion& Other, const Mezzanine::Quaternion& Other2)
556  { return Other2+Other; }
557 
558 Mezzanine::Quaternion operator- (const Ogre::Quaternion& Other, const Mezzanine::Quaternion& Other2)
559  { return Mezzanine::Quaternion(Other.x-Other2.X, Other.y-Other2.Y, Other.z-Other2.Z, Other.w-Other2.W); }
560 
561 Mezzanine::Quaternion operator- (const btQuaternion& Other, const Mezzanine::Quaternion& Other2)
562  { return Mezzanine::Quaternion(Other.getX()-Other2.X, Other.getY()-Other2.Y, Other.getZ()-Other2.Z, Other.getW()-Other2.W); }
563 
564 ///////////////////////////////////////////////////////////////////////////////
565 // Class External << Operators for streaming or assignment
566 
567 btQuaternion& operator<< ( btQuaternion& Other, const Mezzanine::Quaternion& Other2)
568 {
569  Other=Other2.GetBulletQuaternion();
570  return Other;
571 }
572 
573 btQuaternion& operator<< ( btQuaternion& Other, const Ogre::Quaternion& Other2)
574 {
575  Other.setX(Other2.x);
576  Other.setY(Other2.y);
577  Other.setZ(Other2.z);
578  Other.setW(Other2.w);
579  return Other;
580 }
581 
582 Mezzanine::Quaternion& operator<< ( Mezzanine::Quaternion& Other, const Ogre::Quaternion& Other2)
583 {
584  Other=Other2;
585  return Other;
586 }
587 
588 Mezzanine::Quaternion& operator<< ( Mezzanine::Quaternion& Other, const btQuaternion& Other2)
589 {
590  Other=Other2;
591  return Other;
592 }
593 
594 Ogre::Quaternion& operator<< ( Ogre::Quaternion& Other, const Mezzanine::Quaternion& Other2)
595 {
596  Other=Other2.GetOgreQuaternion();
597  return Other;
598 }
599 
600 Ogre::Quaternion& operator<< ( Ogre::Quaternion& Other, const btQuaternion& Other2)
601 {
602  Other.x=Other2.getX();
603  Other.y=Other2.getY();
604  Other.z=Other2.getZ();
605  Other.w=Other2.getW();
606  return Other;
607 }
608 
609 std::ostream& operator << (std::ostream& stream, const Mezzanine::Quaternion& x)
610 {
611 
612  Serialize(stream, x);
613  // '"<Quaternion Version=\"1\" X=\"" << x.X << "\" Y=\"" << x.Y << "\" Z=\"" << x.Z << "\" W=\"" << x.W << "\" />";
614 
615  return stream;
616 }
617 
618 std::istream& operator >> (std::istream& stream, Mezzanine::Quaternion& Ev)
619  { return DeSerialize(stream,Ev); }
620 
622  { Ev.ProtoDeSerialize(OneNode); }
623 
624 
625 
626 #endif // \_quaternion_cpp
Real Length() const
Gets the length of the quaternion.
Definition: quaternion.cpp:208
std::ostream & operator<<(std::ostream &stream, const Mezzanine::LinearInterpolator< T > &Lint)
Used to Serialize an Mezzanine::LinearInterpolator to a human readable stream.
Definition: interpolator.h:433
Attribute AppendAttribute(const Char8 *Name)
Creates an Attribute and puts it at the end of this Nodes attributes.
A light-weight handle for manipulating attributes in DOM tree.
Definition: attribute.h:74
This is a 3x3 Matrix class used for representing rotations and scaling in an object.
Definition: matrix3x3.h:62
Vector3 CrossProduct(const Vector3 &Vec) const
This is used to calculate the crossproduct of this and another vector.
Definition: vector3.cpp:338
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
Real operator[](const Whole &Index) const
Allows Array style access to the members of this class.
Definition: quaternion.cpp:286
Real X
Coordinate on the X vector.
Definition: vector3.h:85
Real Z
Coordinate on the Z vector.
Definition: vector3.h:89
Boole operator>=(const Mezzanine::Quaternion &Other) const
Is every value in this Quaternion greater than or equal to its corresponding value in another...
Definition: quaternion.cpp:498
void SetFromAxisAngle(const Real &Angle, const Vector3 &Axis)
Generates and sets the values of this quaternion to describe a rotation from an axis and angle on tha...
Definition: quaternion.cpp:115
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Definition: exception.h:3048
std::ostream & Serialize(std::ostream &Stream, const T &Converted, const String &Indent=String(""))
Convert any class that supports serialization or has a serializer to a string of chars in a stream...
Real LengthSqrd() const
Gets the squared length(len^2) of the quaternion.
Definition: quaternion.cpp:213
Real Y
The Y component of the Axis.
Definition: quaternion.h:77
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
Definition: exception.h:112
Quaternion operator-(const Mezzanine::Quaternion &Other) const
Subtraction operator with Mezzanine::Quaternion and Mezzanine::Quaternion.
Definition: quaternion.cpp:339
void SetFromMatrix3x3(const Matrix3x3 &Mat)
Sets this quaternions values to express the same rotation as a Matrix3x3.
Definition: quaternion.cpp:125
static String GetSerializableName()
Get the name of the the XML tag this class will leave behind as its instances are serialized...
Definition: quaternion.cpp:544
Quaternion GetInverse() const
Inverses this Quaternion.
Definition: quaternion.cpp:228
void ConvertToAngleAxis(Real &Angle, Vector3 &Axis) const
Converts the rotation expressed by this Quaternion into it's individual rotation and axis components...
Definition: quaternion.cpp:190
Real DotProduct(const Quaternion &Other) const
Gets the Dot Product of this quaternion and another quaternion.
Definition: quaternion.cpp:203
Quaternion & Normalize()
Normalizes this Quaternion.
Definition: quaternion.cpp:218
This implements the exception hiearchy for Mezzanine.
void ExtractOgreQuaternion(const Ogre::Quaternion &Ours)
Copies an existing Ogre quaternion.
Definition: quaternion.cpp:275
btQuaternion GetBulletQuaternion(Boole normalize=false) const
Gets a Bullet quaternion.
Definition: quaternion.cpp:243
Quaternion & operator=(const Mezzanine::Quaternion &Other)
Assignment Operator from Mezzanine::Quaternion.
Definition: quaternion.cpp:454
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
The interface for serialization.
bool SetValue(const Char8 *rhs)
Set the value of this.
void SetValues(const Real &X, const Real &Y, const Real &Z, const Real &W)
Sets the individual values of this quaterion directly.
Definition: quaternion.cpp:107
bool SetName(const Char8 *rhs)
Set the name of .
Ogre::Quaternion GetOgreQuaternion(Boole normalize=false) const
Gets a Ogre quaternion.
Definition: quaternion.cpp:263
void ExtractBulletQuaternion(const btQuaternion &Ours)
Copies an existing Bullet quaternion.
Definition: quaternion.cpp:255
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
void SetFromAxisToZ(const Vector3 &DirectionAxis, const Vector3 &UpAxis)
Generates and sets the values of this quaternion to describe a rotation from the direction axis to th...
Definition: quaternion.cpp:175
Real W
Rotation on the Axis X, Y and Z defined.
Definition: quaternion.h:81
int AsInt(int def=0) const
Attempts to convert the value of the attribute to an int and returns the results. ...
Boole operator==(const Mezzanine::Quaternion &Other) const
Equality Comparison Operator from Mezzanine::Quaternion.
Definition: quaternion.cpp:478
Quaternion()
Blank Constructor.
Definition: quaternion.cpp:61
Real Matrix[3][3]
The Matrix. Fo' Reals.
Definition: matrix3x3.h:66
Vector3 & Normalize()
This will change this point into it's own normal relative to the origin.
Definition: vector3.cpp:352
Real AsReal(Real def=0) const
Attempts to convert the value of the attribute to a Real and returns the results. ...
Real Y
Coordinate on the Y vector.
Definition: vector3.h:87
void SetValues(const Real &X, const Real &Y, const Real &Z)
Manually sets all the members of this vector3.
Definition: vector3.cpp:524
Quaternion & operator-=(const Mezzanine::Quaternion &Other)
Decrementing operator with Mezzanine::Quaternion and Mezzanine::Quaternion.
Definition: quaternion.cpp:425
std::istream & DeSerialize(std::istream &Stream, T &Converted)
Deserialize the next xml tag in the stream into a specific in memory class instance.
Quaternion & operator+=(const Mezzanine::Quaternion &Other)
Incrementing operator with Mezzanine::Quaternion and Mezzanine::Quaternion.
Definition: quaternion.cpp:398
Quaternion operator/(const Real &Scalar) const
Scaling by division.
Definition: quaternion.cpp:320
Thrown when parameters are checked at runtime and found invalid.
Definition: exception.h:108
static Vector3 Unit_X()
Gets a vector representing the X unit of a Vector3.
Definition: vector3.cpp:131
Boole operator<=(const Mezzanine::Quaternion &Other) const
Is every value in this Quaternion less than or equal to its corresponding value in another...
Definition: quaternion.cpp:496
Thrown when the identity string wasn't valid at all.
Definition: exception.h:93
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
void SetIdentity()
Sets default/identity values to the members of this quaternion.
Definition: quaternion.cpp:99
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
void SetFromAxes(const Vector3 &AxisX, const Vector3 &AxisY, const Vector3 &AxisZ)
Generates and sets the values of this quaternion from 3 Axis vectors.
Definition: quaternion.cpp:158
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
std::istream & operator>>(std::istream &stream, Mezzanine::LinearInterpolator< T > &Lint)
Used to de-serialize an Mezzanine::LinearInterpolator from a stream.
Definition: interpolator.h:448
void ProtoSerialize(XML::Node &CurrentRoot) const
Convert this class to an XML::Node ready for serialization.
Definition: quaternion.cpp:502
Boole IsZeroLength() const
Checks to see if the length of this vector is zero.
Definition: vector3.cpp:469
Real X
The X component of the Axis.
Definition: quaternion.h:75
const Char8 * Name() const
ptrdiff_tGet the name of this Node.
Thrown when attempted to access something that really should note be accessed.
Definition: exception.h:98
This is used to store information about rotation in 3d space.
Definition: quaternion.h:68
void SerializeError(const String &FailedTo, const String &ClassName, Boole SOrD)
Simply does some string concatenation, then throws an Exception.
Node AppendChild(NodeType Type=NodeElement)
Creates a Node and makes it a child of this one.
Real Z
The Z component of the Axis.
Definition: quaternion.h:79
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
void ProtoDeSerialize(const XML::Node &OneNode)
Take the data stored in an XML and overwrite this instance of this object with it.
Definition: quaternion.cpp:526
Quaternion operator+(const Mezzanine::Quaternion &Other) const
Addition operator with Mezzanine::Quaternion and Mezzanine::Quaternion.
Definition: quaternion.cpp:330
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
Quaternion GetNormalizedCopy() const
Get a normalized copy of this Quaternion without changing this one.
Definition: quaternion.cpp:224
Boole operator!=(const Mezzanine::Quaternion &Other) const
Inequality Comparison Operator from Mezzanine::Quaternion.
Definition: quaternion.cpp:487
Quaternion operator*(const Real &Scalar) const
Scaling by multiplication.
Definition: quaternion.cpp:315