Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*!
  2. * \file include/math/Matrix.h
  3. * \brief 3D Matrix
  4. *
  5. * \author Mongoose
  6. */
  7. #ifndef _MATH_MATRIX_H_
  8. #define _MATH_MATRIX_H_
  9. #include "math/math.h"
  10. #include "math/Quaternion.h"
  11. #include "math/Vector3d.h"
  12. /*!
  13. * \brief 3D Matrix
  14. *
  15. * Multidim map for row order encoding
  16. *
  17. * ///////////////////////////////////////////////
  18. * // 0,0 - 0; 0,1 - 1; 0,2 - 2; 0,3 - 3 //
  19. * // 1,0 - 4; 1,1 - 5; 1,2 - 6; 1,3 - 7 //
  20. * // 2,0 - 8; 2,1 - 9; 2,2 - 10; 2,3 - 11 //
  21. * // 3,0 - 12; 3,1 - 13; 3,2 - 14; 3,3 - 15 //
  22. * ///////////////////////////////////////////////
  23. *
  24. * Multidim map for column order encoding
  25. *
  26. * ///////////////////////////////////////////////
  27. * // 0,0 - 0; 0,1 - 4; 0,2 - 8; 0,3 - 12 //
  28. * // 1,0 - 1; 1,1 - 5; 1,2 - 9; 1,3 - 13 //
  29. * // 2,0 - 2; 2,1 - 6; 2,2 - 10; 2,3 - 14 //
  30. * // 3,0 - 3; 3,1 - 7; 3,2 - 11; 3,3 - 15 //
  31. * ///////////////////////////////////////////////
  32. */
  33. class Matrix {
  34. public:
  35. /*!
  36. * \brief Constructs an object of Matrix
  37. */
  38. Matrix();
  39. /*!
  40. * \brief Constructs an object of Matrix
  41. * \param mat Matrix as data source
  42. */
  43. Matrix(matrix_t mat);
  44. /*!
  45. * \brief Constructs an object of Matrix
  46. * \param q Converts and assigns the Quaternion to the Matrix
  47. */
  48. Matrix(Quaternion &q);
  49. /*!
  50. * \brief Returns this matrix copy
  51. * \param mat target
  52. */
  53. void getMatrix(matrix_t mat);
  54. /*!
  55. * \brief Returns this matrix transposed
  56. * \param mat target
  57. */
  58. void getTransposeMatrix(matrix_t mat);
  59. /*!
  60. * \brief Returns this matrix inverted
  61. * \param mat target
  62. */
  63. bool getInvert(matrix_t mat);
  64. /*!
  65. * \brief Multiplies two matrices
  66. * \param a first matrix
  67. * \param b second matrix
  68. * \returns resultant matrix
  69. */
  70. static Matrix multiply(const Matrix &a, const Matrix &b);
  71. /*!
  72. * \brief Multiplies v vector and this matrix
  73. * \param v vector
  74. * \param result where the result will be stored, may be same as v
  75. */
  76. void multiply4v(vec4_t v, vec4_t result);
  77. /*!
  78. * \brief Multiplies v vector and this matrix
  79. * \param v vector
  80. * \param result where the result will be stored, may be same as v
  81. */
  82. void multiply3v(vec3_t v, vec3_t result);
  83. /*!
  84. * \brief Prints matrix values to stdout
  85. */
  86. void print();
  87. /*!
  88. * \brief Is this matrix the identity matrix?
  89. * \returns true if it is identity, false otherwise
  90. */
  91. bool isIdentity();
  92. /*!
  93. * \brief Multiplies a and this matrix
  94. * \param a matrix to multiply with
  95. * \returns resultant matrix
  96. */
  97. Matrix operator *(const Matrix &a);
  98. /*!
  99. * \brief Multiply vector by this matrix
  100. * \param v Vector to multiply with
  101. * \returns resultant vector (mult)
  102. */
  103. Vector3d operator *(Vector3d v);
  104. /*!
  105. * \brief Sets to identity matrix
  106. */
  107. void setIdentity();
  108. /*!
  109. * \brief S et the matrix
  110. * \fixme dangerous, scary, boo!
  111. * \param mat new matrix
  112. */
  113. void setMatrix(matrix_t mat);
  114. /*!
  115. * \brief Rotate object in 3D space
  116. * \param x x rotation in radians
  117. * \param y y rotation in radians
  118. * \param z z rotation in radians
  119. */
  120. void rotate(vec_t x, vec_t y, vec_t z);
  121. /*!
  122. * \brief Rotate object in 3D space
  123. * \param xyz rotation in radians
  124. */
  125. void rotate(const vec_t *xyz);
  126. /*!
  127. * \brief Scale object in 3D space
  128. * \param x x scaling
  129. * \param y y scaling
  130. * \param z z scaling
  131. */
  132. void scale(vec_t x, vec_t y, vec_t z);
  133. /*!
  134. * \brief Scale object in 3D space
  135. * \param xyz scaling factors
  136. */
  137. void scale(const vec_t *xyz);
  138. /*!
  139. * \brief Translate (move) object in 3D space
  140. * \param x x translation
  141. * \param y y translation
  142. * \param z z translation
  143. */
  144. void translate(vec_t x, vec_t y, vec_t z);
  145. /*!
  146. * \brief Translate (move) object in 3D space
  147. * \param xyz translations
  148. */
  149. void translate(const vec_t *xyz);
  150. /*!
  151. * \brief Transpose this matrix
  152. */
  153. void transpose();
  154. matrix_t mMatrix; //!< Data model, moved public for faster external renderer feedback use
  155. private:
  156. /*!
  157. * \brief Copys value from source to dest
  158. * \param source source
  159. * \param dest destination
  160. */
  161. static void copy(matrix_t source, matrix_t dest);
  162. /*!
  163. * \brief Multiplies matrices a and b. Neither a or b is also the result.
  164. * \param a first matrix
  165. * \param b second matrix
  166. * \param result wil be set to resultant matrix value
  167. */
  168. static void multiply(const matrix_t a, const matrix_t b, matrix_t result);
  169. };
  170. #endif