Ocular Engine
Matrix4x4.hpp
1 
17 #pragma once
18 #ifndef __H__OCULAR_MATH_MATRIX_4X4_TEMP__H__
19 #define __H__OCULAR_MATH_MATRIX_4X4_TEMP__H__
20 
21 #include "MathCommon.hpp"
22 #include "Utilities/Types.hpp"
23 
24 //------------------------------------------------------------------------------------------
25 
30 namespace Ocular
31 {
36  namespace Math
37  {
38  template<typename T> class Vector3;
39  template<typename T> class Vector4;
40  class Matrix3x3;
41  class Quaternion;
42 
43  struct Matrix4x4_Internal;
44 
64  class Matrix4x4
65  {
66  public:
67 
68  //------------------------------------------------------------------------------
69  // CONSTRUCTORS
70  //------------------------------------------------------------------------------
71 
92  Matrix4x4(float x0, float y0, float z0, float w0,
93  float x1, float y1, float z1, float w1,
94  float x2, float y2, float z2, float w2,
95  float x3, float y3, float z3, float w3);
96 
101  Matrix4x4(Matrix3x3 const& matrix);
102 
107  Matrix4x4(float const* values);
108 
112  Matrix4x4(Vector4<float> const& col0, Vector4<float> const& col1, Vector4<float> const& col2, Vector4<float> const& col3);
113 
120  Matrix4x4(Vector3<float> const& position, Quaternion const& rotation);
121 
128  Matrix4x4(Vector3<float> const& position, Vector3<float> const& eulerRotation);
129 
133  Matrix4x4(Vector3<float> const& position, Quaternion const& rotation, Vector3<float> const& scale);
134 
138  Matrix4x4(Matrix4x4_Internal const& data);
139 
143  Matrix4x4(Matrix4x4 const& other);
144 
148  Matrix4x4();
149 
153  ~Matrix4x4();
154 
155  //------------------------------------------------------------------------------
156  // OPERATORS
157  //------------------------------------------------------------------------------
158 
159  float operator[](uint32_t index);
160 
161  Matrix4x4& operator=(Matrix4x4 const& rhs);
162  Matrix4x4& operator+=(Matrix4x4 const& rhs);
163  Matrix4x4& operator-=(Matrix4x4 const& rhs);
164  Matrix4x4& operator*=(Matrix4x4 const& rhs);
165  Matrix4x4& operator*=(Vector4<float> const& rhs);
166  Matrix4x4& operator*=(float rhs);
167 
168  //------------------------------------------------------------------------------
169  // GETTERS / SETTERS
170  //------------------------------------------------------------------------------
171 
188  void setElement(uint32_t index, float value);
189 
206  float getElement(uint32_t index) const;
207 
214  void setRow(uint32_t index, Vector4<float> const& row);
215 
219  void setRow(uint32_t index, Vector3<float> const& row);
220 
227  void getRow(uint32_t index, Vector4<float>& row) const;
228 
232  Vector4<float> getRow(uint32_t index) const;
233 
240  void setCol(uint32_t index, Vector4<float> const& col);
241 
245  void setCol(uint32_t index, Vector3<float> const& col);
246 
253  void getCol(uint32_t index, Vector4<float>& col) const;
254 
258  Vector4<float> getCol(uint32_t index) const;
259 
264  void setData(float const* data);
265 
270  void getData(float* data) const;
271 
272  //------------------------------------------------------------------------------
273  // MISC OPERATIONS
274  //------------------------------------------------------------------------------
275 
279  void invert();
280 
284  Matrix4x4 getInverse() const;
285 
289  float getDeterminant() const;
290 
294  Matrix4x4 getTranspose() const;
295 
299  bool isIdentity() const;
300 
301  //------------------------------------------------------------------------------
302  // STATIC OPERATIONS
303  //------------------------------------------------------------------------------
304 
311  static Matrix4x4 CreateTranslationMatrix(Vector3<float> const& translate, Matrix4x4 const& matrix = Matrix4x4());
312 
319  static Matrix4x4 CreateScaleMatrix(Vector3<float> const& scale, Matrix4x4 const& matrix = Matrix4x4());
320 
326  static Matrix4x4 CreateLookAtMatrix(Vector3<float> const& from, Vector3<float> const& to, Vector3<float> const& up);
327 
336  static Matrix4x4 CreateOrthographicMatrix(float xMin, float xMax, float yMin, float yMax, float nearClip, float farClip);
337 
344  static Matrix4x4 CreatePerspectiveMatrix(float fov, float aspectRatio, float nearClip, float farClip);
345 
346  //------------------------------------------------------------------------------
347  // MISC
348  //------------------------------------------------------------------------------
349 
355 
356  protected:
357 
358  private:
359 
360  Matrix4x4_Internal* m_Internal;
361  };
362 
363  bool operator==(Matrix4x4 const& lhs, Matrix4x4 const& rhs);
364  bool operator!=(Matrix4x4 const& lhs, Matrix4x4 const& rhs);
365 
366  Matrix4x4 operator+(Matrix4x4 const& lhs, Matrix4x4 const& rhs);
367  Matrix4x4 operator-(Matrix4x4 const& lhs, Matrix4x4 const& rhs);
368  Matrix4x4 operator*(Matrix4x4 const& lhs, Matrix4x4 const& rhs);
369  Matrix4x4 operator*(Matrix4x4 const& lhs, float rhs);
370 
371  Vector4<float> operator*(Matrix4x4 const& lhs, Vector4<float> const& rhs);
372  Vector3<float> operator*(Matrix4x4 const& lhs, Vector3<float> const& rhs);
373  }
377 }
382 OCULAR_REGISTER_TYPE_CUSTOM(Ocular::Math::Matrix4x4, "Matrix4x4");
383 
384 //------------------------------------------------------------------------------------------
385 
386 #endif
Definition: Matrix3x3.hpp:39
Matrix4x4()
Definition: Matrix4x4.cpp:187
void setElement(uint32_t index, float value)
Definition: Matrix4x4.cpp:302
static Matrix4x4 CreateLookAtMatrix(Vector3< float > const &from, Vector3< float > const &to, Vector3< float > const &up)
Definition: Matrix4x4.cpp:487
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
Definition: Quaternion.hpp:50
static Matrix4x4 CreateTranslationMatrix(Vector3< float > const &translate, Matrix4x4 const &matrix=Matrix4x4())
Definition: Matrix4x4.cpp:477
static Matrix4x4 CreateScaleMatrix(Vector3< float > const &scale, Matrix4x4 const &matrix=Matrix4x4())
Definition: Matrix4x4.cpp:482
A 3x3 column-major float matrix.
Definition: Matrix3x3.hpp:63
void getRow(uint32_t index, Vector4< float > &row) const
Definition: Matrix4x4.cpp:345
void setCol(uint32_t index, Vector4< float > const &col)
Definition: Matrix4x4.cpp:371
Matrix4x4_Internal * getInternal() const
Definition: Matrix4x4.cpp:514
bool isIdentity() const
Definition: Matrix4x4.cpp:458
void getCol(uint32_t index, Vector4< float > &col) const
Definition: Matrix4x4.cpp:392
static Matrix4x4 CreatePerspectiveMatrix(float fov, float aspectRatio, float nearClip, float farClip)
Definition: Matrix4x4.cpp:497
void getData(float *data) const
Definition: Matrix4x4.cpp:426
A 4x4 column-major float matrix.
Definition: Matrix4x4.hpp:64
float getElement(uint32_t index) const
Definition: Matrix4x4.cpp:310
static Matrix4x4 CreateOrthographicMatrix(float xMin, float xMax, float yMin, float yMax, float nearClip, float farClip)
Definition: Matrix4x4.cpp:492
Definition: MathInternal.hpp:52
void setRow(uint32_t index, Vector4< float > const &row)
Definition: Matrix4x4.cpp:324
void setData(float const *data)
Definition: Matrix4x4.cpp:418