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.

Matrix.h 4.7KB

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