MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
matrix4x4.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 _matrix4x4_h
41 #define _matrix4x4_h
42 
43 #include "matrix3x3.h"
44 #include "plane.h"
45 
46 namespace Ogre
47 {
48  class Matrix4;
49 }
50 
51 namespace Mezzanine
52 {
53  ///////////////////////////////////////////////////////////////////////////////
54  /// @class Matrix4x4
55  /// @headerfile matrix4x4.h
56  /// @brief A 4x4 matrix math class for the representation of full transforms.
57  /// @details 4x4 matricies are commonly used by graphics subsystems.
58  ///////////////////////////////////////
60  {
61  public:
62  ///////////////////////////////////////////////////////////////////////////////
63  // Public Data Members
64 
65  /// @brief The bigger Matrix. Fo' Reals.
66  Real Matrix[4][4];
67 
68  ///////////////////////////////////////////////////////////////////////////////
69  // Construction and Destruction
70 
71  /// @brief Non-Initialization constructor.
72  Matrix4x4();
73  /// @brief Explict Initialization constructor.
74  /// @details Provides initialization for every number in the matrix.
75  Matrix4x4(const Real& XX, const Real& XY, const Real& XZ, const Real& XW, const Real& YX, const Real& YY, const Real& YZ, const Real& YW,
76  const Real& ZX, const Real& ZY, const Real& ZZ, const Real& ZW, const Real& WX, const Real& WY, const Real& WZ, const Real& WW);
77  /// @brief Ogre Matrix Initialization constructor.
78  /// @param Mat The Ogre Matrix to build this Matrix from.
79  Matrix4x4(const Ogre::Matrix4& Mat);
80  /// @brief Transform Information Initialization constructor.
81  /// @param Position The position of the transform.
82  /// @param Scale The scale of the transform.
83  /// @param Rotation The rotation of the transform.
84  Matrix4x4(const Vector3& Position, const Vector3& Scale, const Quaternion& Rotation);
85  /// @brief Class destructor.
86  ~Matrix4x4();
87 
88  ///////////////////////////////////////////////////////////////////////////////
89  // Set From Other Data Functions
90 
91  /// @brief Sets the values for every number in the matrix.
92  void SetValues(const Real& XX, const Real& XY, const Real& XZ, const Real& XW, const Real& YX, const Real& YY, const Real& YZ, const Real& YW,
93  const Real& ZX, const Real& ZY, const Real& ZZ, const Real& ZW, const Real& WX, const Real& WY, const Real& WZ, const Real& WW);
94  /// @brief Sets the Matrix based on a provided position, scale, and rotation.
95  /// @param Position The position of the transform.
96  /// @param Scale The scale of the transform.
97  /// @param Rotation The rotation of the transform.
98  void SetTransform(const Vector3& Position, const Vector3& Scale, const Quaternion& Rotation);
99  /// @brief Sets all values in this Matrix to Identity values.
100  /// @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.
101  void SetIdentity();
102  /// @brief Sets all values in this Matrix to zero.
103  void SetZero();
104 
105  ///////////////////////////////////////////////////////////////////////////////
106  // Utility and Conversion Functions
107 
108  /// @brief Gets the Determinant of this Matrix.
109  /// @return Returns a Real representing the Determinant of this Matrix.
110  Real GetDeterminant() const;
111 
112  /*/// @brief Gets the individual data in this Matrix and populates other data classes with their values.
113  /// @param Position The vector to be populated with position data.
114  /// @param Scale The vector to be populated with scaling data.
115  /// @param Rotation The quaternion to be populated with rotation data.
116  void Decompose(Vector3& Position, Vector3& Scale, Quaternion& Rotation) const;// */
117 
118  /// @brief Gets the rotation portion of this Matrix as a Quaternion.
119  /// @return Returns a Quaternion that expresses the rotation of this Matrix.
120  Quaternion GetRotationAsQuaternion() const;
121  /// @brief Gets the rotation portion of this Matrix as a Matrix3x3.
122  /// @return Returns a Matrix3x3 that expresses the rotation of this Matrix.
123  Matrix3x3 GetRotationAsMatrix3x3() const;
124 
125  /// @brief Gets the data from an Ogre Matrix4x4 and applies it to this.
126  /// @param temp The Matrix4x4 to copy from.
127  void ExtractOgreMatrix4x4(const Ogre::Matrix4& temp);
128  /// @brief Gets an Ogre copy of this Matrix4x4.
129  /// @return Returns an Ogre Matrix4x4 with the same values as this Matrix4x4.
130  Ogre::Matrix4 GetOgreMatrix4x4() const;
131 
132  ///////////////////////////////////////////////////////////////////////////////
133  // Comparison Operators
134 
135  /// @brief Equality comparison operator.
136  /// @param Other The other Matrix4x4 to compare against.
137  /// @return Returns true if the two Matrix4x4's are equal, false otherwise.
138  bool operator==(const Matrix4x4& Other) const;
139  /// @brief Inequality comparison operator.
140  /// @param Other The other Matrix4x4 to compare against.
141  /// @return Returns true if the two Matrix4x4's are not equal, false otherwise.
142  bool operator!=(const Matrix4x4& Other) const;
143 
144  ///////////////////////////////////////////////////////////////////////////////
145  // Arithmetic Operators With Matrix4x4
146 
147  /// @brief Addition operator.
148  /// @param Other The other Matrix4x4 to add to this.
149  /// @return Returns a fresh Matrix4x4.
150  Matrix4x4 operator+(const Matrix4x4& Other) const;
151  /// @brief Subtraction operator.
152  /// @param Other The other Matrix4x4 to subtract from this.
153  /// @return Returns a fresh Matrix4x4.
154  Matrix4x4 operator-(const Matrix4x4& Other) const;
155  /// @brief Multiplication operator.
156  /// @param Other The other Matrix4x4 to multiply this by.
157  /// @return Returns a fresh Matrix4x4.
158  Matrix4x4 operator*(const Matrix4x4& Other) const;
159  /// @brief Addition Assignment operator.
160  /// @param Other The other Matrix4x4 to add to this.
161  /// @return Returns a reference to *this.
162  Matrix4x4& operator+=(const Matrix4x4& Other);
163  /// @brief Subtraction Assignment operator.
164  /// @param Other The other Matrix4x4 to subtract from this.
165  /// @return Returns a reference to *this.
166  Matrix4x4& operator-=(const Matrix4x4& Other);
167  /// @brief Multiplication Assignment operator.
168  /// @param Other The other Matrix4x4 to add to this.
169  /// @return Returns a reference to *this.
170  Matrix4x4& operator*=(const Matrix4x4& Other);
171 
172  ///////////////////////////////////////////////////////////////////////////////
173  // Arithmetic Operators With Other Datatypes
174 
175  /// @brief Multiply by Vector3 operator.
176  /// @param Vec The Vector to be rotated.
177  /// @return Returns a Vector3 with the rotation and translation of this Matrix applied to it.
178  Vector3 operator*(const Vector3& Vec) const;
179  /// @brief Multiply by Real operator.
180  /// @param Scalar The Real to multiply each member of this Matrix by.
181  /// @return Returns a new Matrix4x4 that is a copy of this Matrix4x4 with each of it's members multiplied by the scaler.
182  Matrix4x4 operator*(const Real& Scalar) const;
183  /// @brief Multiply Assignment by Real operator.
184  /// @param Scalar The Real to multiply each member of this Matrix by.
185  /// @return Returns a reference to *this, being the modified Matrix4x4.
186  Matrix4x4& operator*=(const Real& Scalar);
187 
188  ///////////////////////////////////////////////////////////////////////////////
189  // Other Operators
190 
191  /// @brief Assignment operator.
192  /// @param Other The other Matrix4x4 to copy from.
193  void operator=(const Matrix4x4& Other);
194  /// @brief Assignment operator.
195  /// @details This will copy the rotation portions of the other Matrix into this Matrix.
196  /// @param Other The other Matrix3x3 to copy from.
197  void operator=(const Matrix3x3& Other);
198 
199  ///////////////////////////////////////////////////////////////////////////////
200  // Fancy Math
201 
202  /// @brief Gets the Transpose of this Matrix.
203  /// @todo I'm not gonna lie, I have no idea what the hell the Transpose of a 4x4 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.
204  /// @return Returns a new Matrix4x4 that is a Transposed copy of this.
205  Matrix4x4 Transpose() const;
206  /// @brief Gets the Adjoint of this Matrix.
207  /// @return Returns a new Matrix4x4 that is the Adjoint of this.
208  Matrix4x4 Adjoint() const;
209  /// @brief Gets the Inverse of this Matrix.
210  /// @return Returns a new Matrix4x4 that is this Matrix inversed.
211  Matrix4x4 Inverse() const;
212  /// @brief Combines the translation/rotation of two Matricies.
213  /// @param Mat The other Matrix to combine with this.
214  /// @return Returns the product of the two Matricies.
215  Matrix4x4 Concatenate(const Matrix4x4& Mat) const;
216  /// @brief Gets the Minor of the specified rows/columns of this Matrix.
217  /// @param Row1 Row for the first Real of the calculated minor.
218  /// @param Row2 Row for the second Real of the calculated minor.
219  /// @param Row3 Row for the third Real of the calculated minor.
220  /// @param Col1 Column for the first Real of the calculated minor.
221  /// @param Col2 Column for the second Real of the calculated minor.
222  /// @param Col3 Column for the third Real of the calculated minor.
223  /// @return Returns a Real containing the minor of the Matrix.
224  Real Minor(const Whole& Row1, const Whole& Row2, const Whole& Row3, const Whole& Col1, const Whole& Col2, const Whole& Col3) const;
225 
226  ///////////////////////////////////////////////////////////////////////////////
227  // Serialization
228 
229  /// @brief Convert this class to an XML::Node ready for serialization
230  /// @param CurrentRoot The point in the XML hierarchy that all this Matrix4x4 should be appended to.
231  void ProtoSerialize(XML::Node& CurrentRoot) const;
232  /// @brief Take the data stored in an XML and overwrite this instance of this object with it
233  /// @param OneNode and XML::Node containing the data.
234  void ProtoDeSerialize(const XML::Node& OneNode);
235 
236  /// @brief Get the name of the the XML tag this class will leave behind as its instances are serialized.
237  /// @return A string containing "Matrix4x4".
238  static String GetSerializableName();
239  };//Matrix4x4
240 }//Mezzanine
241 
242 #endif