40 #ifndef _quaternion_cpp
41 #define _quaternion_cpp
43 #include "stringtool.h"
44 #include "quaternion.h"
45 #include "MathTools/mathtools.h"
48 #include "matrix3x3.h"
52 #include "btBulletDynamicsCommon.h"
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;
132 Root = MathTools::Sqrt(Trace + 1.0);
133 this->
W = Root * 0.5;
139 static size_t s_iNext[3] = { 1, 2, 0 };
145 size_t J = s_iNext[I];
146 size_t K = s_iNext[J];
149 Real* QuatMem[3] = { &
X, &
Y, &
Z };
150 *QuatMem[I] = 0.5 * 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;
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);
205 return this->
X * Other.
X + this->
Y * Other.
Y + this->
Z * Other.
Z + this->
W * Other.
W;
225 {
return *
this /
Length(); }
233 Real InvNorm = 1.f/Norm;
234 return Quaternion(
W*InvNorm,-
X*InvNorm,-
Y*InvNorm,-Z*InvNorm);
251 { Other.normalize(); }
265 Ogre::Quaternion Other;
271 { Other.normalise(); }
317 return Quaternion(this->
X * Scalar,this->
Y * Scalar,this->
Z * Scalar,this->
W * Scalar);
324 return *
this * ( 1.0 / Scalar );
331 {
return Quaternion(this->
X+Other.
X, this->Y+Other.
Y, this->Z+Other.
Z, this->W+Other.
W); }
334 {
return Quaternion(this->
X+Other.x, this->Y+Other.y, this->Z+Other.z, this->W+Other.w); }
337 {
return Quaternion(this->
X+Other.x(), this->
Y+Other.y(), this->
Z+Other.z(), this->
W+Other.w()); }
340 {
return Quaternion(this->
X-Other.
X, this->Y-Other.
Y, this->Z-Other.
Z, this->W-Other.
W); }
343 {
return Quaternion(this->
X-Other.x, this->Y-Other.y, this->Z-Other.z, this->W-Other.w); }
346 {
return Quaternion(this->
X-Other.x(), this->
Y-Other.y(), this->
Z-Other.z(), this->
W-Other.w()); }
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
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
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()
392 return Other + UV + UUV;
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;
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;
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();
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;
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;
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();
479 {
return (this->
X==Other.
X && this->Y==Other.
Y && this->Z==Other.
Z && this->W==Other.
W); }
482 {
return (this->
X==Other.x && this->Y==Other.y && this->Z==Other.z && this->W==Other.w); }
485 {
return (this->
X==Other.getX() && this->
Y==Other.getY() && this->
Z==Other.getZ() && this->
W==Other.getW()); }
488 {
return (this->
X!=Other.
X || this->Y!=Other.
Y || this->Z!=Other.
Z || this->W!=Other.
W); }
491 {
return (this->
X!=Other.x || this->Y!=Other.y || this->Z!=Other.z || this->W!=Other.w); }
494 {
return (this->
X!=Other.getX() || this->
Y!=Other.getY() || this->
Z!=Other.getZ() || this->
W!=Other.getW()); }
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); }
512 if( VersionAttr && XAttr && YAttr && ZAttr && WAttr)
545 {
return String(
"Quaternion"); }
553 {
return Other2+Other; }
556 {
return Other2+Other; }
562 {
return Mezzanine::Quaternion(Other.getX()-Other2.
X, Other.getY()-Other2.
Y, Other.getZ()-Other2.
Z, Other.getW()-Other2.
W); }
573 btQuaternion&
operator<< ( btQuaternion& Other,
const Ogre::Quaternion& Other2)
575 Other.setX(Other2.x);
576 Other.setY(Other2.y);
577 Other.setZ(Other2.z);
578 Other.setW(Other2.w);
600 Ogre::Quaternion&
operator<< ( Ogre::Quaternion& Other,
const btQuaternion& Other2)
602 Other.x=Other2.getX();
603 Other.y=Other2.getY();
604 Other.z=Other2.getZ();
605 Other.w=Other2.getW();
626 #endif // \_quaternion_cpp
Real Length() const
Gets the length of the quaternion.
std::ostream & operator<<(std::ostream &stream, const Mezzanine::LinearInterpolator< T > &Lint)
Used to Serialize an Mezzanine::LinearInterpolator to a human readable stream.
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.
This is a 3x3 Matrix class used for representing rotations and scaling in an object.
Vector3 CrossProduct(const Vector3 &Vec) const
This is used to calculate the crossproduct of this and another vector.
bool Boole
Generally acts a single bit, true or false.
Real operator[](const Whole &Index) const
Allows Array style access to the members of this class.
Real X
Coordinate on the X vector.
Real Z
Coordinate on the Z vector.
Boole operator>=(const Mezzanine::Quaternion &Other) const
Is every value in this Quaternion greater than or equal to its corresponding value in another...
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...
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
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.
Real Y
The Y component of the Axis.
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
Quaternion operator-(const Mezzanine::Quaternion &Other) const
Subtraction operator with Mezzanine::Quaternion and Mezzanine::Quaternion.
void SetFromMatrix3x3(const Matrix3x3 &Mat)
Sets this quaternions values to express the same rotation as a Matrix3x3.
static String GetSerializableName()
Get the name of the the XML tag this class will leave behind as its instances are serialized...
Quaternion GetInverse() const
Inverses this Quaternion.
void ConvertToAngleAxis(Real &Angle, Vector3 &Axis) const
Converts the rotation expressed by this Quaternion into it's individual rotation and axis components...
Real DotProduct(const Quaternion &Other) const
Gets the Dot Product of this quaternion and another quaternion.
Quaternion & Normalize()
Normalizes this Quaternion.
This implements the exception hiearchy for Mezzanine.
void ExtractOgreQuaternion(const Ogre::Quaternion &Ours)
Copies an existing Ogre quaternion.
btQuaternion GetBulletQuaternion(Boole normalize=false) const
Gets a Bullet quaternion.
Quaternion & operator=(const Mezzanine::Quaternion &Other)
Assignment Operator from Mezzanine::Quaternion.
float Real
A Datatype used to represent a real floating point number.
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.
bool SetName(const Char8 *rhs)
Set the name of .
Ogre::Quaternion GetOgreQuaternion(Boole normalize=false) const
Gets a Ogre quaternion.
void ExtractBulletQuaternion(const btQuaternion &Ours)
Copies an existing Bullet quaternion.
A light-weight handle for manipulating nodes in DOM tree.
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...
Real W
Rotation on the Axis X, Y and Z defined.
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.
Quaternion()
Blank Constructor.
Real Matrix[3][3]
The Matrix. Fo' Reals.
Vector3 & Normalize()
This will change this point into it's own normal relative to the origin.
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.
void SetValues(const Real &X, const Real &Y, const Real &Z)
Manually sets all the members of this vector3.
Quaternion & operator-=(const Mezzanine::Quaternion &Other)
Decrementing operator with Mezzanine::Quaternion and Mezzanine::Quaternion.
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.
Quaternion operator/(const Real &Scalar) const
Scaling by division.
Thrown when parameters are checked at runtime and found invalid.
static Vector3 Unit_X()
Gets a vector representing the X unit of a Vector3.
Boole operator<=(const Mezzanine::Quaternion &Other) const
Is every value in this Quaternion less than or equal to its corresponding value in another...
Thrown when the identity string wasn't valid at all.
This is used to represent a point in space, or a vector through space.
void SetIdentity()
Sets default/identity values to the members of this quaternion.
The bulk of the engine components go in this namspace.
void SetFromAxes(const Vector3 &AxisX, const Vector3 &AxisY, const Vector3 &AxisZ)
Generates and sets the values of this quaternion from 3 Axis vectors.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
std::istream & operator>>(std::istream &stream, Mezzanine::LinearInterpolator< T > &Lint)
Used to de-serialize an Mezzanine::LinearInterpolator from a stream.
void ProtoSerialize(XML::Node &CurrentRoot) const
Convert this class to an XML::Node ready for serialization.
Boole IsZeroLength() const
Checks to see if the length of this vector is zero.
Real X
The X component of the Axis.
const Char8 * Name() const
ptrdiff_tGet the name of this Node.
Thrown when attempted to access something that really should note be accessed.
This is used to store information about rotation in 3d space.
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.
std::string String
A datatype used to a series of characters.
void ProtoDeSerialize(const XML::Node &OneNode)
Take the data stored in an XML and overwrite this instance of this object with it.
Quaternion operator+(const Mezzanine::Quaternion &Other) const
Addition operator with Mezzanine::Quaternion and Mezzanine::Quaternion.
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.
Boole operator!=(const Mezzanine::Quaternion &Other) const
Inequality Comparison Operator from Mezzanine::Quaternion.
Quaternion operator*(const Real &Scalar) const
Scaling by multiplication.