MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
matrix3x3.h
1 // © Copyright 2010 - 2014 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 
71  /// @brief Class destructor.
72  ~Matrix3x3();
73 
74  ///////////////////////////////////////////////////////////////////////////////
75  // Additional Constructors
76 
77  /// @brief Explict Initialization constructor.
78  /// @details Provides initialization for every number in the matrix.
79  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);
80 
81  /// @brief Euler Initialization constructor.
82  /// @param Yaw The number of degree's on the Yaw in Degrees to rotate.
83  /// @param Pitch The number of degree's on the Pitch in Degrees to rotate.
84  /// @param Roll The number of degree's on the Roll in Degrees to rotate.
85  Matrix3x3(const Real& Yaw, const Real& Pitch, const Real& Roll);
86 
87  /// @brief Quaternion Initialization constructor.
88  /// @param Rot The rotation to apply to this Matrix expressed as a Quaternion.
89  Matrix3x3(const Quaternion& Rot);
90 
91  /// @brief Axis Angle Initialization constructor.
92  /// @param Axis The axis on which to apply the rotation.
93  /// @param Angle The amount of rotation to apply in Radians.
94  Matrix3x3(const Vector3& Axis, const Real& Angle);
95 
96  /// @brief Bullet Matrix3x3 constructor.
97  /// @param Mat The Bullet 3x3 Matrix.
98  Matrix3x3(const btMatrix3x3& Mat);
99 
100  /// @brief Ogre Matrix3x3 constructor.
101  /// @param Mat The Ogre 3x3 Matrix.
102  Matrix3x3(const Ogre::Matrix3& Mat);
103 
104  ///////////////////////////////////////////////////////////////////////////////
105  // Set From Other Data Functions
106 
107  /// @brief Sets the values for every number in the matrix.
108  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);
109 
110  /// @brief Sets the Matrix based on Euler angles.
111  /// @param Yaw The number of degree's on the Yaw in Degrees to rotate.
112  /// @param Pitch The number of degree's on the Pitch in Degrees to rotate.
113  /// @param Roll The number of degree's on the Roll in Degrees to rotate.
114  void SetFromEulerZYX(const Real& Yaw, const Real& Pitch, const Real& Roll);
115 
116  /// @brief Sets the Matrix from a quaternion.
117  /// @param Rot The rotation to apply to this Matrix expressed as a Quaternion.
118  void SetFromQuaternion(const Quaternion& Rot);
119 
120  /// @brief Sets the Matrix from an Axis Angle.
121  /// @param Axis The axis on which to apply the rotation.
122  /// @param Angle The amount of rotation to apply in Radians.
123  void SetFromAxisAngle(const Vector3& Axis, const Real& Angle);
124 
125  /// @brief Sets all values in this Matrix to Identity values.
126  /// @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.
127  void SetIdentity();
128 
129  /// @brief Sets all values in this Matrix to zero.
130  void SetZero();
131 
132  ///////////////////////////////////////////////////////////////////////////////
133  // Utility and Conversion Functions
134 
135  /// @brief Gets the Determinant of this Matrix.
136  /// @return Returns a Real representing the Determinant of this Matrix.
137  Real GetDeterminant() const;
138 
139  /// @brief Gets this Matrix as a Quaternion.
140  /// @return Returns a Quaternion that expresses the same rotation as this Matrix.
141  Quaternion GetAsQuaternion() const;
142 
143  /// @brief Gets the data from a Bullet Matrix3x3 and applies it to this.
144  /// @param temp The Matrix3x3 to copy from.
145  void ExtractBulletMatrix3x3(const btMatrix3x3& temp);
146 
147  /// @brief Gets a Bullet copy of this Matrix3x3.
148  /// @return Returns a Bullet Matrix3x3 with the same values as this Matrix3x3.
149  btMatrix3x3 GetBulletMatrix3x3() const;
150 
151  /// @brief Gets the data from an Ogre Matrix3x3 and applies it to this.
152  /// @param temp The Matrix3x3 to copy from.
153  void ExtractOgreMatrix3x3(const Ogre::Matrix3& temp);
154 
155  /// @brief Gets an Ogre copy of this Matrix3x3.
156  /// @return Returns an Ogre Matrix3x3 with the same values as this Matrix3x3.
157  Ogre::Matrix3 GetOgreMatrix3x3() const;
158 
159  ///////////////////////////////////////////////////////////////////////////////
160  // Comparison Operators
161 
162  /// @brief Equality comparison operator.
163  /// @param Other The other Matrix3x3 to compare against.
164  /// @return Returns true if the two Matrix3x3's are equal, false otherwise.
165  bool operator==(const Matrix3x3& Other) const;
166 
167  /// @brief Inequality comparison operator.
168  /// @param Other The other Matrix3x3 to compare against.
169  /// @return Returns true if the two Matrix3x3's are not equal, false otherwise.
170  bool operator!=(const Matrix3x3& Other) const;
171 
172  ///////////////////////////////////////////////////////////////////////////////
173  // Arithmetic Operators With Matrix3x3
174 
175  /// @brief Addition operator.
176  /// @param Other The other Matrix3x3 to add to this.
177  /// @return Returns a fresh Matrix3x3.
178  Matrix3x3 operator+(const Matrix3x3& Other) const;
179 
180  /// @brief Subtraction operator.
181  /// @param Other The other Matrix3x3 to subtract from this.
182  /// @return Returns a fresh Matrix3x3.
183  Matrix3x3 operator-(const Matrix3x3& Other) const;
184 
185  /// @brief Multiplication operator.
186  /// @param Other The other Matrix3x3 to multiply this by.
187  /// @return Returns a fresh Matrix3x3.
188  Matrix3x3 operator*(const Matrix3x3& Other) const;
189 
190  /// @brief Addition Assignment operator.
191  /// @param Other The other Matrix3x3 to add to this.
192  /// @return Returns a reference to *this.
193  Matrix3x3& operator+=(const Matrix3x3& Other);
194 
195  /// @brief Subtraction Assignment operator.
196  /// @param Other The other Matrix3x3 to subtract from this.
197  /// @return Returns a reference to *this.
198  Matrix3x3& operator-=(const Matrix3x3& Other);
199 
200  /// @brief Multiplication Assignment operator.
201  /// @param Other The other Matrix3x3 to add to this.
202  /// @return Returns a reference to *this.
203  Matrix3x3& operator*=(const Matrix3x3& Other);
204 
205  ///////////////////////////////////////////////////////////////////////////////
206  // Arithmetic Operators With Other Datatypes
207 
208  /// @brief Multiply by Vector3 operator.
209  /// @param Vec The Vector to be rotated.
210  /// @return Returns a Vector3 with the rotation of this Matrix applied to it.
211  Vector3 operator*(const Vector3& Vec) const;
212 
213  /// @brief Multiply by Real operator.
214  /// @param Scaler The Real to multiply each member of this Matrix by.
215  /// @return Returns a new Matrix3x3 that is a copy of this Matrix3x3 with each of it's members multiplied by the scaler.
216  Matrix3x3 operator*(const Real& Scaler) const;
217 
218  /// @brief Multiply Assignment by Real operator.
219  /// @param Scaler The Real to multiply each member of this Matrix by.
220  /// @return Returns a reference to *this, being the modified Matrix3x3.
221  Matrix3x3& operator*=(const Real& Scaler);
222 
223  ///////////////////////////////////////////////////////////////////////////////
224  // Other Operators
225 
226  /// @brief Assignment operator.
227  /// @param Other The other Matrix3x3 to copy from.
228  void operator=(const Matrix3x3& Other);
229 
230  /// @brief Negative Unary operator.
231  /// @return Returns a copy of this Matrix3x3 with each of it's members flipped.
232  Matrix3x3 operator-() const;
233 
234  ///////////////////////////////////////////////////////////////////////////////
235  // Fancy Math
236 
237  /// @brief Gets the Transpose of this Matrix.
238  /// @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.
239  /// @return Returns a new Matrix3x3 that is a Transposed copy of this.
240  Matrix3x3 Transpose() const;
241 
242  /// @brief Gets the Adjoint of this Matrix.
243  /// @return Returns a new Matrix3x3 that is the Adjoint of this.
244  Matrix3x3 Adjoint() const;
245 
246  /// @brief Gets the Inverse of this Matrix.
247  /// @return Returns a new Matrix3x3 that is this Matrix inversed.
248  Matrix3x3 Inverse() const;
249 
250  /// @brief Gets the cofactor between two sets of rows/columns.
251  /// @param Row1 Row for the first Real of the calculated cofactor.
252  /// @param Col1 Column for the first Real of the calculated cofactor.
253  /// @param Row2 Row for the second Real of the calculated cofactor.
254  /// @param Col2 Column for the second Real of the calculated cofactor.
255  /// @return Returns the CoFactor of the provided rows/columns.
256  Real CoFactor(const Whole& Row1, const Whole& Col1, const Whole& Row2, const Whole& Col2) const;
257 
258  /// @brief Scales this Matrix.
259  /// @param Scaling A Vector3 containing the scaling to be applied to this Matrix.
260  void SetScale(const Vector3& Scaling);
261 
262  /// @brief Checks to see if this Matrix has any scaling applied to it.
263  /// @return Returns true if this Matrix is scaled, false otherwise.
264  bool HasScaling() const;
265  };//Matrix3x3
266 }//Mezzanine
267 
268 #endif