Spinning Topp Logo BlackTopp Studios
inc
matrix3x3.h
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 _matrix3x3_h
41 #define _matrix3x3_h
42 
43 #include "vector3.h"
44 #include "quaternion.h"
45 
46 class btMatrix3x3;
47 
48 namespace Ogre
49 {
50  class Matrix3;
51 }
52 
53 namespace Mezzanine
54 {
55  /// @class Matrix3x3
56  /// @headerfile matrix3x3.h
57  /// @brief This is a 3x3 Matrix class used for representing rotations and scaling in an object.
58  /// @details The utility of this class overlaps with that of the Quaternion, for the most part the use of
59  /// either class is a matter of preference. The Mezzanine engine for the most part prefer's use of the
60  /// Quaternion class since it deals with fewer numbers, but this class is still made available for others
61  /// that may prefer it.
63  {
64  public:
65  /// @brief The Matrix. Fo' Reals.
66  Real Matrix[3][3];
67 
68  /// @brief Non-Initialization constructor.
69  Matrix3x3();
70  /// @brief Class destructor.
71  ~Matrix3x3();
72 
73  ///////////////////////////////////////////////////////////////////////////////
74  // Additional Constructors
75 
76  /// @brief Explict Initialization constructor.
77  /// @details Provides initialization for every number in the matrix.
78  Matrix3x3(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);
79  /// @brief Euler Initialization constructor.
80  /// @param Yaw The number of degree's on the Yaw in Degrees to rotate.
81  /// @param Pitch The number of degree's on the Pitch in Degrees to rotate.
82  /// @param Roll The number of degree's on the Roll in Degrees to rotate.
83  Matrix3x3(const Real& Yaw, const Real& Pitch, const Real& Roll);
84  /// @brief Quaternion Initialization constructor.
85  /// @param Rot The rotation to apply to this Matrix expressed as a Quaternion.
86  Matrix3x3(const Quaternion& Rot);
87  /// @brief Axis Angle Initialization constructor.
88  /// @param Axis The axis on which to apply the rotation.
89  /// @param Angle The amount of rotation to apply in Radians.
90  Matrix3x3(const Vector3& Axis, const Real& Angle);
91  /// @brief Bullet Matrix3x3 constructor.
92  /// @param Mat The Bullet 3x3 Matrix.
93  Matrix3x3(const btMatrix3x3& Mat);
94  /// @brief Ogre Matrix3x3 constructor.
95  /// @param Mat The Ogre 3x3 Matrix.
96  Matrix3x3(const Ogre::Matrix3& Mat);
97 
98  ///////////////////////////////////////////////////////////////////////////////
99  // Set From Other Data Functions
100 
101  /// @brief Sets the values for every number in the matrix.
102  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);
103  /// @brief Sets the Matrix based on Euler angles.
104  /// @param Yaw The number of degree's on the Yaw in Degrees to rotate.
105  /// @param Pitch The number of degree's on the Pitch in Degrees to rotate.
106  /// @param Roll The number of degree's on the Roll in Degrees to rotate.
107  void SetFromEulerZYX(const Real& Yaw, const Real& Pitch, const Real& Roll);
108  /// @brief Sets the Matrix from a quaternion.
109  /// @param Rot The rotation to apply to this Matrix expressed as a Quaternion.
110  void SetFromQuaternion(const Quaternion& Rot);
111  /// @brief Sets the Matrix from an Axis Angle.
112  /// @param Axis The axis on which to apply the rotation.
113  /// @param Angle The amount of rotation to apply in Radians.
114  void SetFromAxisAngle(const Vector3& Axis, const Real& Angle);
115  /// @brief Sets all values in this Matrix to Identity values.
116  /// @details Identity values for a 4x4 matrix is all zeros except for the values at [0][0], [1][1], [2][2], [3][3], which are set to one.
117  void SetIdentity();
118  /// @brief Sets all values in this Matrix to zero.
119  void SetZero();
120 
121  ///////////////////////////////////////////////////////////////////////////////
122  // Utility and Conversion Functions
123 
124  /// @brief Gets the Determinant of this Matrix.
125  /// @return Returns a Real representing the Determinant of this Matrix.
126  Real GetDeterminant() const;
127  /// @brief Gets this Matrix as a Quaternion.
128  /// @return Returns a Quaternion that expresses the same rotation as this Matrix.
129  Quaternion GetAsQuaternion() const;
130  /// @brief Gets the data from a Bullet Matrix3x3 and applies it to this.
131  /// @param temp The Matrix3x3 to copy from.
132  void ExtractBulletMatrix3x3(const btMatrix3x3& temp);
133  /// @brief Gets a Bullet copy of this Matrix3x3.
134  /// @return Returns a Bullet Matrix3x3 with the same values as this Matrix3x3.
135  btMatrix3x3 GetBulletMatrix3x3() const;
136  /// @brief Gets the data from an Ogre Matrix3x3 and applies it to this.
137  /// @param temp The Matrix3x3 to copy from.
138  void ExtractOgreMatrix3x3(const Ogre::Matrix3& temp);
139  /// @brief Gets an Ogre copy of this Matrix3x3.
140  /// @return Returns an Ogre Matrix3x3 with the same values as this Matrix3x3.
141  Ogre::Matrix3 GetOgreMatrix3x3() const;
142 
143  ///////////////////////////////////////////////////////////////////////////////
144  // Comparison Operators
145 
146  /// @brief Equality comparison operator.
147  /// @param Other The other Matrix3x3 to compare against.
148  /// @return Returns true if the two Matrix3x3's are equal, false otherwise.
149  Boole operator==(const Matrix3x3& Other) const;
150  /// @brief Inequality comparison operator.
151  /// @param Other The other Matrix3x3 to compare against.
152  /// @return Returns true if the two Matrix3x3's are not equal, false otherwise.
153  Boole operator!=(const Matrix3x3& Other) const;
154 
155  ///////////////////////////////////////////////////////////////////////////////
156  // Arithmetic Operators With Matrix3x3
157 
158  /// @brief Addition operator.
159  /// @param Other The other Matrix3x3 to add to this.
160  /// @return Returns a fresh Matrix3x3.
161  Matrix3x3 operator+(const Matrix3x3& Other) const;
162  /// @brief Subtraction operator.
163  /// @param Other The other Matrix3x3 to subtract from this.
164  /// @return Returns a fresh Matrix3x3.
165  Matrix3x3 operator-(const Matrix3x3& Other) const;
166  /// @brief Multiplication operator.
167  /// @param Other The other Matrix3x3 to multiply this by.
168  /// @return Returns a fresh Matrix3x3.
169  Matrix3x3 operator*(const Matrix3x3& Other) const;
170 
171  /// @brief Addition Assignment operator.
172  /// @param Other The other Matrix3x3 to add to this.
173  /// @return Returns a reference to *this.
174  Matrix3x3& operator+=(const Matrix3x3& Other);
175  /// @brief Subtraction Assignment operator.
176  /// @param Other The other Matrix3x3 to subtract from this.
177  /// @return Returns a reference to *this.
178  Matrix3x3& operator-=(const Matrix3x3& Other);
179  /// @brief Multiplication Assignment operator.
180  /// @param Other The other Matrix3x3 to add to this.
181  /// @return Returns a reference to *this.
182  Matrix3x3& operator*=(const Matrix3x3& Other);
183 
184  ///////////////////////////////////////////////////////////////////////////////
185  // Arithmetic Operators With Other Datatypes
186 
187  /// @brief Multiply by Vector3 operator.
188  /// @param Vec The Vector to be rotated.
189  /// @return Returns a Vector3 with the rotation of this Matrix applied to it.
190  Vector3 operator*(const Vector3& Vec) const;
191  /// @brief Multiply by Real operator.
192  /// @param Scaler The Real to multiply each member of this Matrix by.
193  /// @return Returns a new Matrix3x3 that is a copy of this Matrix3x3 with each of it's members multiplied by the scaler.
194  Matrix3x3 operator*(const Real& Scaler) const;
195 
196  /// @brief Multiply Assignment by Real operator.
197  /// @param Scaler The Real to multiply each member of this Matrix by.
198  /// @return Returns a reference to *this, being the modified Matrix3x3.
199  Matrix3x3& operator*=(const Real& Scaler);
200 
201  ///////////////////////////////////////////////////////////////////////////////
202  // Other Operators
203 
204  /// @brief Assignment operator.
205  /// @param Other The other Matrix3x3 to copy from.
206  void operator=(const Matrix3x3& Other);
207  /// @brief Negative Unary operator.
208  /// @return Returns a copy of this Matrix3x3 with each of it's members flipped.
209  Matrix3x3 operator-() const;
210 
211  /// @brief Array access operator.
212  /// @param Row The row of the matrix to retrieve.
213  /// @return Returns a pointer to the first element of the specified row in the matrix.
214  Real* operator[](const Whole Row);
215  #ifndef SWIG
216  /// @brief Const Array access operator.
217  /// @param Row The row of the matrix to retrieve.
218  /// @return Returns a const pointer to the first element of the specified row in the matrix.
219  const Real* operator[](const Whole Row) const;
220  #endif
221 
222  ///////////////////////////////////////////////////////////////////////////////
223  // Fancy Math
224 
225  /// @brief Gets the Transpose of this Matrix.
226  /// @todo I'm not gonna lie, I have no idea what the hell the Transpose of a 3x3 Matrix is or what it is used for...this doc could use a touchup. In fact most of the doc's on this class could use a review.
227  /// @return Returns a new Matrix3x3 that is a Transposed copy of this.
228  Matrix3x3 Transpose() const;
229  /// @brief Gets the Adjoint of this Matrix.
230  /// @return Returns a new Matrix3x3 that is the Adjoint of this.
231  Matrix3x3 Adjoint() const;
232  /// @brief Gets the Inverse of this Matrix.
233  /// @return Returns a new Matrix3x3 that is this Matrix inversed.
234  Matrix3x3 Inverse() const;
235 
236  /// @brief Gets the cofactor between two sets of rows/columns.
237  /// @param Row1 Row for the first Real of the calculated cofactor.
238  /// @param Col1 Column for the first Real of the calculated cofactor.
239  /// @param Row2 Row for the second Real of the calculated cofactor.
240  /// @param Col2 Column for the second Real of the calculated cofactor.
241  /// @return Returns the CoFactor of the provided rows/columns.
242  Real CoFactor(const Whole& Row1, const Whole& Col1, const Whole& Row2, const Whole& Col2) const;
243  /// @brief Scales this Matrix.
244  /// @param Scaling A Vector3 containing the scaling to be applied to this Matrix.
245  void SetScale(const Vector3& Scaling);
246  /// @brief Checks to see if this Matrix has any scaling applied to it.
247  /// @return Returns true if this Matrix is scaled, false otherwise.
248  Boole HasScaling() const;
249  };//Matrix3x3
250 }//Mezzanine
251 
252 #endif
This is a 3x3 Matrix class used for representing rotations and scaling in an object.
Definition: matrix3x3.h:62
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
SmoothTrackIterator< InterpolatableType > & operator+(Integer Steps, SmoothTrackIterator< InterpolatableType > &Iter)
This allows for addition with and an Integer on the Left hand side, such as: 2 + Iter.
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
SmoothTrackIterator< InterpolatableType > & operator-(Integer Steps, SmoothTrackIterator< InterpolatableType > &Iter)
This allows for subtraction with and an Integer on the Left hand side, such as: 2 + Iter...
Mezzanine::Vector3 operator*(const btVector3 &Vec, const Mezzanine::Vector3 &lhs)
Right Hand Multiplication Operator for Bullet Vectors with a Mezzanine::Vector3.
Definition: vector3.cpp:651
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
This is used to store information about rotation in 3d space.
Definition: quaternion.h:68