Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Matrix.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
  2. /*================================================================
  3. *
  4. * Project : Freyja
  5. * Author : Terry 'Mongoose' Hendrix II
  6. * Website : http://www.westga.edu/~stu7440/
  7. * Email : stu7440@westga.edu
  8. * Object : Matrix
  9. * License : No use w/o permission (C) 2002 Mongoose
  10. * Comments: 3d Matrix in class form
  11. *
  12. *
  13. * This file was generated using Mongoose's C++
  14. * template generator script. <stu7440@westga.edu>
  15. *
  16. *-- History ------------------------------------------------
  17. *
  18. * 2003.06.17:
  19. * Mongoose - Now in column order to match OpenGL user needs,
  20. * use transpose() to get row order back =)
  21. *
  22. * 2002.05.11:
  23. * Mongoose - Created, based on my mtk3d matrix
  24. ================================================================*/
  25. #ifndef _MATRIX_H_
  26. #define _MATRIX_H_
  27. #include <MatMath.h>
  28. #include <Quaternion.h>
  29. #include <Vector3d.h>
  30. ///////////////////////////////////////////////
  31. // Multidim map for row order encoding //
  32. ///////////////////////////////////////////////
  33. // 0,0 - 0; 0,1 - 1; 0,2 - 2; 0,3 - 3 //
  34. // 1,0 - 4; 1,1 - 5; 1,2 - 6; 1,3 - 7 //
  35. // 2,0 - 8; 2,1 - 9; 2,2 - 10; 2,3 - 11 //
  36. // 3,0 - 12; 3,1 - 13; 3,2 - 14; 3,3 - 15 //
  37. ///////////////////////////////////////////////
  38. ///////////////////////////////////////////////
  39. // Multidim map for column order encoding //
  40. ///////////////////////////////////////////////
  41. // 0,0 - 0; 0,1 - 4; 0,2 - 8; 0,3 - 12 //
  42. // 1,0 - 1; 1,1 - 5; 1,2 - 9; 1,3 - 13 //
  43. // 2,0 - 2; 2,1 - 6; 2,2 - 10; 2,3 - 14 //
  44. // 3,0 - 3; 3,1 - 7; 3,2 - 11; 3,3 - 15 //
  45. ///////////////////////////////////////////////
  46. class Matrix
  47. {
  48. public:
  49. ////////////////////////////////////////////////////////////
  50. // Constructors
  51. ////////////////////////////////////////////////////////////
  52. Matrix();
  53. /*------------------------------------------------------
  54. * Pre :
  55. * Post : Constructs an object of Matrix
  56. *
  57. *-- History ------------------------------------------
  58. *
  59. * 2002.05.11:
  60. * Mongoose - Created
  61. ------------------------------------------------------*/
  62. Matrix(matrix_t mat);
  63. /*------------------------------------------------------
  64. * Pre :
  65. * Post : Constructs an object of Matrix
  66. *
  67. *-- History ------------------------------------------
  68. *
  69. * 2002.05.11:
  70. * Mongoose - Created
  71. ------------------------------------------------------*/
  72. Matrix(Quaternion &q);
  73. /*------------------------------------------------------
  74. * Pre :
  75. * Post : Converts and asigns Q to a Matrix
  76. * returns quaternion as Matrix
  77. *
  78. *-- History ------------------------------------------
  79. *
  80. * 2002.05.08:
  81. * Mongoose - Created
  82. ------------------------------------------------------*/
  83. ~Matrix();
  84. /*------------------------------------------------------
  85. * Pre : Matrix object is allocated
  86. * Post : Deconstructs an object of Matrix
  87. *
  88. *-- History ------------------------------------------
  89. *
  90. * 2002.05.11:
  91. * Mongoose - Created
  92. ------------------------------------------------------*/
  93. ////////////////////////////////////////////////////////////
  94. // Public Accessors
  95. ////////////////////////////////////////////////////////////
  96. void getMatrix(matrix_t mat);
  97. /*------------------------------------------------------
  98. * Pre :
  99. * Post : Returns this matrix copy
  100. *
  101. *-- History ------------------------------------------
  102. *
  103. * 2002.05.08:
  104. * Mongoose - Created
  105. ------------------------------------------------------*/
  106. void getTransposeMatrix(matrix_t mat);
  107. /*------------------------------------------------------
  108. * Pre :
  109. * Post : Returns this matrix transposed
  110. *
  111. *-- History ------------------------------------------
  112. *
  113. * 2002.05.08:
  114. * Mongoose - Created
  115. ------------------------------------------------------*/
  116. bool getInvert(matrix_t mat);
  117. /*------------------------------------------------------
  118. * Pre :
  119. * Post : Returns this matrix inverted
  120. *
  121. *-- History ------------------------------------------
  122. *
  123. * 2002.05.08:
  124. * Mongoose - Created
  125. ------------------------------------------------------*/
  126. Matrix multiply(const Matrix &a, const Matrix &b);
  127. /*------------------------------------------------------
  128. * Pre : Multiplies 2 matrices
  129. * Post : Returns resultant matrix
  130. *
  131. *-- History ------------------------------------------
  132. *
  133. * 2002.05.08:
  134. * Mongoose - Created
  135. ------------------------------------------------------*/
  136. void multiply4d(double *v, double *result);
  137. /*------------------------------------------------------
  138. * Pre : Multiplies <V> vector (double[4]) and <This> matrix
  139. *
  140. * Post : Returns <Result> vector,
  141. * <V> and <Result> maybe be the same vector
  142. *
  143. *-- History ------------------------------------------
  144. *
  145. * 2002.05.08:
  146. * Mongoose - Created
  147. ------------------------------------------------------*/
  148. void multiply4v(vec4_t v, vec4_t result);
  149. /*------------------------------------------------------
  150. * Pre : Multiplies <V> vector and <This> matrix
  151. *
  152. * Post : Returns <Result> vector,
  153. * <V> and <Result> maybe be the same vector
  154. *
  155. *-- History ------------------------------------------
  156. *
  157. * 2002.05.08:
  158. * Mongoose - Created
  159. ------------------------------------------------------*/
  160. void multiply3v(vec3_t v, vec3_t result);
  161. /*------------------------------------------------------
  162. * Pre : Multiplies <V> vector and <This> matrix
  163. *
  164. * Post : Returns <Result> vector,
  165. * <V> and <Result> maybe be the same vector
  166. *
  167. *-- History ------------------------------------------
  168. *
  169. * 2002.05.08:
  170. * Mongoose - Created
  171. ------------------------------------------------------*/
  172. void print();
  173. /*------------------------------------------------------
  174. * Pre :
  175. * Post : Prints matrix values to stdout
  176. *
  177. *-- History ------------------------------------------
  178. *
  179. * 2002.05.08:
  180. * Mongoose - Created
  181. ------------------------------------------------------*/
  182. bool isIdentity();
  183. /*------------------------------------------------------
  184. * Pre :
  185. * Post : Is this matrix the identity matrix?
  186. *
  187. *-- History ------------------------------------------
  188. *
  189. * 2002.05.08:
  190. * Mongoose - Created
  191. ------------------------------------------------------*/
  192. Matrix operator *(const Matrix &a);
  193. /*------------------------------------------------------
  194. * Pre : Multiplies A and this matrices
  195. * Post : Returns resultant matrix
  196. *
  197. *-- History ------------------------------------------
  198. *
  199. * 2002.05.08:
  200. * Mongoose - Created
  201. ------------------------------------------------------*/
  202. Vector3d operator *(Vector3d v);
  203. /*------------------------------------------------------
  204. * Pre : <V> is vector to multiply by this matrix
  205. * Post : Returns resultant vector ( mult )
  206. *
  207. *-- History ------------------------------------------
  208. *
  209. * 2002.05.08:
  210. * Mongoose - Created
  211. ------------------------------------------------------*/
  212. ////////////////////////////////////////////////////////////
  213. // Public Mutators
  214. ////////////////////////////////////////////////////////////
  215. void setIdentity();
  216. /*------------------------------------------------------
  217. * Pre :
  218. * Post : Sets to identity matrix
  219. *
  220. *-- History ------------------------------------------
  221. *
  222. * 2002.05.08:
  223. * Mongoose - Created
  224. ------------------------------------------------------*/
  225. void setMatrix(matrix_t mat);
  226. /*------------------------------------------------------
  227. * Pre :
  228. * Post : Set the matrix ( dangerous, scary boo )
  229. *
  230. *-- History ------------------------------------------
  231. *
  232. * 2002.05.08:
  233. * Mongoose - Created
  234. ------------------------------------------------------*/
  235. void rotate(vec_t x, vec_t y, vec_t z);
  236. /*------------------------------------------------------
  237. * Pre : Radian input
  238. * Post : Rotates object in 3 space
  239. *
  240. *-- History ------------------------------------------
  241. *
  242. * 2002.05.08:
  243. * Mongoose - Created
  244. ------------------------------------------------------*/
  245. void rotate(const vec_t *xyz);
  246. /*------------------------------------------------------
  247. * Pre : Rotates object in 3 space, Radian input
  248. * Post : Returns true on sucess
  249. *
  250. *-- History ------------------------------------------
  251. *
  252. * 2002.05.08:
  253. * Mongoose - Created
  254. ------------------------------------------------------*/
  255. void scale(vec_t x, vec_t y, vec_t z);
  256. /*------------------------------------------------------
  257. * Pre :
  258. * Post : Scales object in 3 space
  259. *
  260. *-- History ------------------------------------------
  261. *
  262. * 2002.05.08:
  263. * Mongoose - Created
  264. ------------------------------------------------------*/
  265. void scale(const vec_t *xyz);
  266. /*------------------------------------------------------
  267. * Pre :
  268. * Post : Scales object in 3 space
  269. *
  270. *-- History ------------------------------------------
  271. *
  272. * 2002.05.08:
  273. * Mongoose - Created
  274. ------------------------------------------------------*/
  275. void translate(vec_t x, vec_t y, vec_t z);
  276. /*------------------------------------------------------
  277. * Pre :
  278. * Post : Translates ( moves ) object in 3 space
  279. *
  280. *-- History ------------------------------------------
  281. *
  282. * 2002.05.08:
  283. * Mongoose - Created
  284. ------------------------------------------------------*/
  285. void translate(const vec_t *xyz);
  286. /*------------------------------------------------------
  287. * Pre :
  288. * Post : Translates ( moves ) object in 3 space
  289. *
  290. *-- History ------------------------------------------
  291. *
  292. * 2002.05.08:
  293. * Mongoose - Created
  294. ------------------------------------------------------*/
  295. void transpose();
  296. /*------------------------------------------------------
  297. * Pre :
  298. * Post : Transpose this matrix
  299. *
  300. *-- History ------------------------------------------
  301. *
  302. * 2002.05.08:
  303. * Mongoose - Created
  304. ------------------------------------------------------*/
  305. matrix_t mMatrix; /* Data model, moved public for faster
  306. external renderer feedback use */
  307. private:
  308. ////////////////////////////////////////////////////////////
  309. // Private Accessors
  310. ////////////////////////////////////////////////////////////
  311. ////////////////////////////////////////////////////////////
  312. // Private Mutators
  313. ////////////////////////////////////////////////////////////
  314. void copy(matrix_t source, matrix_t dest);
  315. /*------------------------------------------------------
  316. * Pre :
  317. * Post : Copys value of source to dest
  318. *
  319. *-- History ------------------------------------------
  320. *
  321. * 2002.05.08:
  322. * Mongoose - Created
  323. ------------------------------------------------------*/
  324. void multiply(const matrix_t a, const matrix_t b, matrix_t result);
  325. /*------------------------------------------------------
  326. * Pre : Multiplies matrices a and b
  327. * Neither a or b is also the result
  328. *
  329. * Post : Sets resultant matrix value ( result )
  330. *
  331. *-- History ------------------------------------------
  332. *
  333. * 2002.05.08:
  334. * Mongoose - Created
  335. ------------------------------------------------------*/
  336. };
  337. #endif