40 #ifndef _matrix3x3_cpp
41 #define _matrix3x3_cpp
43 #include "matrix3x3.h"
44 #include "MathTools/mathtools.h"
47 #include "btBulletDynamicsCommon.h"
48 #include <OgreMatrix3.h>
114 Cos = MathTools::Cos(Yaw);
115 Sin = MathTools::Sin(Yaw);
116 Matrix3x3 ZMat(Cos,-Sin,0.0,Sin,Cos,0.0,0.0,0.0,1.0);
118 Cos = MathTools::Cos(Pitch);
119 Sin = MathTools::Sin(Pitch);
120 Matrix3x3 YMat(Cos,0.0,Sin,0.0,1.0,0.0,-Sin,0.0,Cos);
122 Cos = MathTools::Cos(Roll);
123 Sin = MathTools::Sin(Roll);
124 Matrix3x3 XMat(1.0,0.0,0.0,0.0,Cos,-Sin,0.0,Sin,Cos);
126 *
this = ZMat * (YMat * XMat);
132 if(Dist ==
Real(0.0))
135 Real XS = Rot.
X * Sc, YS = Rot.
Y * Sc, ZS = Rot.
Z * Sc;
136 Real WX = Rot.
W * XS, WY = Rot.
W * YS, WZ = Rot.
W * ZS;
137 Real XX = Rot.
X * XS, XY = Rot.
X * YS, XZ = Rot.
X * ZS;
138 Real YY = Rot.
Y * YS, YZ = Rot.
Y * ZS, ZZ = Rot.
Z * ZS;
140 XY + WZ,
Real(1.0) - (XX + ZZ), YZ - WX,
141 XZ - WY, YZ + WX,
Real(1.0) - (XX + YY));
146 Real Cos = MathTools::Cos(Angle);
147 Real Sin = MathTools::Sin(Angle);
148 Real OneMinusCos = 1.0 - Cos;
149 Real X2 = Axis.
X * Axis.
X;
150 Real Y2 = Axis.
Y * Axis.
Y;
151 Real Z2 = Axis.
Z * Axis.
Z;
152 Real XYM = Axis.
X * Axis.
Y * OneMinusCos;
153 Real XZM = Axis.
X * Axis.
Z * OneMinusCos;
154 Real YZM = Axis.
Y * Axis.
Z * OneMinusCos;
155 Real XSin = Axis.
X * Sin;
156 Real YSin = Axis.
Y * Sin;
157 Real ZSin = Axis.
Z * Sin;
159 Matrix[0][0] = X2 * OneMinusCos + Cos;
160 Matrix[0][1] = XYM - ZSin;
161 Matrix[0][2] = XZM + YSin;
162 Matrix[1][0] = XYM + ZSin;
163 Matrix[1][1] = Y2 * OneMinusCos + Cos;
164 Matrix[1][2] = YZM - XSin;
165 Matrix[2][0] = XZM - YSin;
166 Matrix[2][1] = YZM + XSin;
167 Matrix[2][2] = Z2 * OneMinusCos + Cos;
190 Real Cofactor10 = Matrix[1][2] * Matrix[2][0] - Matrix[1][0] * Matrix[2][2];
191 Real Cofactor20 = Matrix[1][0] * Matrix[2][1] - Matrix[1][1] * Matrix[2][0];
193 Real Det = Matrix[0][0] * Cofactor00 + Matrix[0][1] * Cofactor10 + Matrix[0][2] * Cofactor20;
203 if (Trace >
Real(0.0))
205 Real Sc = MathTools::Sqrt(Trace +
Real(1.0));
206 Ret.
W = (Sc *
Real(0.5));
209 Ret.
X = ( (Matrix[2][1] - Matrix[1][2]) * Sc );
210 Ret.
Y = ( (Matrix[0][2] - Matrix[2][0]) * Sc );
211 Ret.
Z = ( (Matrix[1][0] - Matrix[0][1]) * Sc );
215 int I = Matrix[0][0] < Matrix[1][1] ?
216 ( Matrix[1][1] < Matrix[2][2] ? 2 : 1 ) :
217 ( Matrix[0][0] < Matrix[2][2] ? 2 : 0 );
221 Real Sc = MathTools::Sqrt(Matrix[I][I] - Matrix[J][J] - Matrix[K][K] +
Real(1.0));
222 Ret[I] = Sc *
Real(0.5);
225 Ret[J] = ( Matrix[J][I] + Matrix[I][J] ) * Sc;
226 Ret[K] = ( Matrix[K][I] + Matrix[I][K] ) * Sc;
227 Ret[3] = ( Matrix[K][J] - Matrix[J][K] ) * Sc;
234 btVector3 Col1 = temp.getColumn(0);
235 btVector3 Col2 = temp.getColumn(1);
236 btVector3 Col3 = temp.getColumn(2);
256 Ogre::Vector3 Col1 = temp.GetColumn(0);
257 Ogre::Vector3 Col2 = temp.GetColumn(1);
258 Ogre::Vector3 Col3 = temp.GetColumn(2);
281 for(
Whole Row = 0 ; Row < 3 ; ++Row )
283 for(
Whole Col = 0 ; Col < 3 ; ++Col )
294 for(
Whole Row = 0 ; Row < 3 ; ++Row )
296 for(
Whole Col = 0 ; Col < 3 ; ++Col )
311 for(
Whole Row = 0 ; Row < 3 ; ++Row )
313 for(
Whole Col = 0 ; Col < 3 ; ++Col )
324 for(
Whole Row = 0 ; Row < 3 ; ++Row )
326 for(
Whole Col = 0 ; Col < 3 ; ++Col )
337 for(
Whole Row = 0 ; Row < 3 ; ++Row )
339 for(
Whole Col = 0 ; Col < 3 ; ++Col )
352 for(
Whole Row = 0 ; Row < 3 ; ++Row )
354 for(
Whole Col = 0 ; Col < 3 ; ++Col )
364 for(
Whole Row = 0 ; Row < 3 ; ++Row )
366 for(
Whole Col = 0 ; Col < 3 ; ++Col )
376 (*this) = (*this) * Other;
397 for(
Whole Row = 0 ; Row < 3 ; ++Row )
399 for(
Whole Col = 0 ; Col < 3 ; ++Col )
409 for(
Whole Row = 0 ; Row < 3 ; ++Row )
411 for(
Whole Col = 0 ; Col < 3 ; ++Col )
413 Matrix[Row][Col] *= Scaler;
424 for(
Whole Row = 0 ; Row < 3 ; ++Row )
426 for(
Whole Col = 0 ; Col < 3 ; ++Col )
436 for(
Whole Row = 0 ; Row < 3 ; ++Row )
438 for(
Whole Col = 0 ; Col < 3 ; ++Col )
447 {
return this->
Matrix[Row]; }
450 {
return this->
Matrix[Row]; }
458 for(
Whole Row = 0 ; Row < 3 ; Row++ )
460 for(
Whole Col = 0 ; Col < 3 ; Col++ )
468 return Matrix3x3(
CoFactor(1,1,2,2),
CoFactor(0,2,2,1),
CoFactor(0,1,1,2),
469 CoFactor(1,2,2,0),
CoFactor(0,0,2,2),
CoFactor(0,2,1,0),
470 CoFactor(1,0,2,1),
CoFactor(0,1,2,0),
CoFactor(0,0,1,1));
477 Ret.
Matrix[0][1] = Matrix[0][2] * Matrix[2][1] - Matrix[0][1] * Matrix[2][2];
478 Ret.
Matrix[0][2] = Matrix[0][1] * Matrix[1][2] - Matrix[0][2] * Matrix[1][1];
479 Ret.
Matrix[1][0] = Matrix[1][2] * Matrix[2][0] - Matrix[1][0] * Matrix[2][2];
480 Ret.
Matrix[1][1] = Matrix[0][0] * Matrix[2][2] - Matrix[0][2] * Matrix[2][0];
481 Ret.
Matrix[1][2] = Matrix[0][2] * Matrix[1][0] - Matrix[0][0] * Matrix[1][2];
482 Ret.
Matrix[2][0] = Matrix[1][0] * Matrix[2][1] - Matrix[1][1] * Matrix[2][0];
483 Ret.
Matrix[2][1] = Matrix[0][1] * Matrix[2][0] - Matrix[0][0] * Matrix[2][1];
484 Ret.
Matrix[2][2] = Matrix[0][0] * Matrix[1][1] - Matrix[0][1] * Matrix[1][0];
486 Real Det = Matrix[0][0] * Ret.
Matrix[0][0] + Matrix[0][1] * Ret.
Matrix[1][0] + Matrix[0][2] * Ret.
Matrix[2][0];
491 Real InvDet = 1.0 / Det;
492 for(
Whole Row = 0 ; Row < 3 ; Row++)
494 for(
Whole Col = 0 ; Col < 3 ; Col++)
495 Ret.
Matrix[Row][Col] *= InvDet;
521 if (!MathTools::WithinTolerance(Test,1.0,(
Real)1e-04))
523 Test = Matrix[0][1] * Matrix[0][1] + Matrix[1][1] * Matrix[1][1] + Matrix[2][1] * Matrix[2][1];
524 if (!MathTools::WithinTolerance(Test,1.0,(
Real)1e-04))
526 Test = Matrix[0][2] * Matrix[0][2] + Matrix[1][2] * Matrix[1][2] + Matrix[2][2] * Matrix[2][2];
527 if (!MathTools::WithinTolerance(Test,1.0,(
Real)1e-04))
void ExtractBulletMatrix3x3(const btMatrix3x3 &temp)
Gets the data from a Bullet Matrix3x3 and applies it to this.
void SetScale(const Vector3 &Scaling)
Scales this Matrix.
Matrix3x3 Adjoint() const
Gets the Adjoint of this Matrix.
This is a 3x3 Matrix class used for representing rotations and scaling in an object.
bool Boole
Generally acts a single bit, true or false.
Real GetDeterminant() const
Gets the Determinant of this Matrix.
Real X
Coordinate on the X vector.
Real Z
Coordinate on the Z vector.
void SetFromAxisAngle(const Vector3 &Axis, const Real &Angle)
Sets the Matrix from an Axis Angle.
Ogre::Matrix3 GetOgreMatrix3x3() const
Gets an Ogre copy of this Matrix3x3.
Matrix3x3 & operator-=(const Matrix3x3 &Other)
Subtraction Assignment operator.
void SetValues(const Real &XX, const Real &XY, const Real &XZ, const Real &YX, const Real &YY, const Real &YZ, const Real &ZX, const Real &ZY, const Real &ZZ)
Sets the values for every number in the matrix.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Matrix3x3 Transpose() const
Gets the Transpose of this Matrix.
Real LengthSqrd() const
Gets the squared length(len^2) of the quaternion.
Real Y
The Y component of the Axis.
Matrix3x3 operator-() const
Negative Unary operator.
Matrix3x3 Inverse() const
Gets the Inverse of this Matrix.
Boole operator!=(const Matrix3x3 &Other) const
Inequality comparison operator.
Quaternion GetAsQuaternion() const
Gets this Matrix as a Quaternion.
Boole operator==(const Matrix3x3 &Other) const
Equality comparison operator.
void SetZero()
Sets all values in this Matrix to zero.
void operator=(const Matrix3x3 &Other)
Assignment operator.
Boole HasScaling() const
Checks to see if this Matrix has any scaling applied to it.
float Real
A Datatype used to represent a real floating point number.
Matrix3x3 & operator+=(const Matrix3x3 &Other)
Addition Assignment operator.
btMatrix3x3 GetBulletMatrix3x3() const
Gets a Bullet copy of this Matrix3x3.
Matrix3x3 & operator*=(const Matrix3x3 &Other)
Multiplication Assignment operator.
void ExtractOgreMatrix3x3(const Ogre::Matrix3 &temp)
Gets the data from an Ogre Matrix3x3 and applies it to this.
Real W
Rotation on the Axis X, Y and Z defined.
Real Matrix[3][3]
The Matrix. Fo' Reals.
Real Y
Coordinate on the Y vector.
Matrix3x3 operator*(const Matrix3x3 &Other) const
Multiplication operator.
void SetIdentity()
Sets all values in this Matrix to Identity values.
This is used to represent a point in space, or a vector through space.
Thrown when Math has failed.
The bulk of the engine components go in this namspace.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Real X
The X component of the Axis.
This is used to store information about rotation in 3d space.
void SetFromQuaternion(const Quaternion &Rot)
Sets the Matrix from a quaternion.
Real Z
The Z component of the Axis.
Real * operator[](const Whole Row)
Array access operator.
Real CoFactor(const Whole &Row1, const Whole &Col1, const Whole &Row2, const Whole &Col2) const
Gets the cofactor between two sets of rows/columns.
Matrix3x3 operator+(const Matrix3x3 &Other) const
Addition operator.
Matrix3x3()
Non-Initialization constructor.
void SetFromEulerZYX(const Real &Yaw, const Real &Pitch, const Real &Roll)
Sets the Matrix based on Euler angles.
~Matrix3x3()
Class destructor.