Open Source Tomb Raider Engine
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Quaternion.h 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
  2. /*================================================================
  3. *
  4. * Project : Hel
  5. * Author : Terry 'Mongoose' Hendrix II
  6. * Website : http://www.westga.edu/~stu7440/
  7. * Email : stu7440@westga.edu
  8. * Object : Quaternion
  9. * License : No use w/o permission (C) 2002 Mongoose
  10. * Comments: Quaternion now in C++ class form fresh from the grove
  11. *
  12. *
  13. * This file was generated using Mongoose's C++
  14. * template generator script. <stu7440@westga.edu>
  15. *
  16. *-- Test Defines -----------------------------------------------
  17. *
  18. * UNIT_TEST_QUATERNION - Builds Quaternion class as a console unit test
  19. *
  20. *-- History ------------------------------------------------
  21. *
  22. * 2002.12.16:
  23. * Mongoose - Created, based on mtk3d ( freyja )
  24. ================================================================*/
  25. #ifndef GUARD__HEL_MONGOOSE_QUATERNION_H_
  26. #define GUARD__HEL_MONGOOSE_QUATERNION_H_
  27. #include <MatMath.h>
  28. class Quaternion
  29. {
  30. public:
  31. ////////////////////////////////////////////////////////////
  32. // Constructors
  33. ////////////////////////////////////////////////////////////
  34. Quaternion();
  35. /*------------------------------------------------------
  36. * Pre :
  37. * Post : Constructs an object of Quaternion
  38. *
  39. *-- History ------------------------------------------
  40. *
  41. * 2002.12.16:
  42. * Mongoose - Created
  43. ------------------------------------------------------*/
  44. Quaternion(vec_t w, vec_t x, vec_t y, vec_t z);
  45. /*------------------------------------------------------
  46. * Pre :
  47. * Post : Constructs an object of Quaternion
  48. *
  49. *-- History ------------------------------------------
  50. *
  51. * 2002.12.16:
  52. * Mongoose - Created
  53. ------------------------------------------------------*/
  54. Quaternion(vec4_t v);
  55. /*------------------------------------------------------
  56. * Pre : v { w, x, y, z }
  57. * Post : Constructs an object of Quaternion
  58. *
  59. *-- History ------------------------------------------
  60. *
  61. * 2002.12.16:
  62. * Mongoose - Created
  63. ------------------------------------------------------*/
  64. ~Quaternion();
  65. /*------------------------------------------------------
  66. * Pre : Quaternion object is allocated
  67. * Post : Deconstructs an object of Quaternion
  68. *
  69. *-- History ------------------------------------------
  70. *
  71. * 2002.12.16:
  72. * Mongoose - Created
  73. ------------------------------------------------------*/
  74. ////////////////////////////////////////////////////////////
  75. // Public Accessors
  76. ////////////////////////////////////////////////////////////
  77. void getMatrix(matrix_t m);
  78. /*------------------------------------------------------
  79. * Pre : Matrix is valid
  80. * Post : Returns col order matrix equiv of this quaternion
  81. *
  82. *-- History ------------------------------------------
  83. *
  84. * 2002.05.08:
  85. * Mongoose - Created
  86. ------------------------------------------------------*/
  87. Quaternion operator =(const Quaternion &q);
  88. /*------------------------------------------------------
  89. * Pre :
  90. * Post : Asigns Q to this quaternion
  91. * returns (this) resultant quaternion
  92. *
  93. *-- History ------------------------------------------
  94. *
  95. * 2002.05.08:
  96. * Mongoose - Created
  97. ------------------------------------------------------*/
  98. Quaternion operator *(const Quaternion &q);
  99. /*------------------------------------------------------
  100. * Pre :
  101. * Post : Multiplies Q and this quaternion
  102. * returns resultant quaternion
  103. * ( Use normalize() call for unit quaternion )
  104. *
  105. *-- History ------------------------------------------
  106. *
  107. * 2002.05.08:
  108. * Mongoose - Created
  109. ------------------------------------------------------*/
  110. Quaternion operator /(const Quaternion &q);
  111. /*------------------------------------------------------
  112. * Pre :
  113. * Post : Dividess Q from this quaternion
  114. * returns quotient quaternion
  115. *
  116. *-- History ------------------------------------------
  117. *
  118. * 2002.05.08:
  119. * Mongoose - Created
  120. ------------------------------------------------------*/
  121. Quaternion operator +(const Quaternion &q);
  122. /*------------------------------------------------------
  123. * Pre :
  124. * Post : Adds Q and this quaternion
  125. * returns resultant quaternion
  126. *
  127. *-- History ------------------------------------------
  128. *
  129. * 2002.05.08:
  130. * Mongoose - Created
  131. ------------------------------------------------------*/
  132. Quaternion operator -(const Quaternion &q);
  133. /*------------------------------------------------------
  134. * Pre :
  135. * Post : Subtracts Q from this quaternion
  136. * returns resultant quaternion
  137. *
  138. *-- History ------------------------------------------
  139. *
  140. * 2002.05.08:
  141. * Mongoose - Created
  142. ------------------------------------------------------*/
  143. bool operator ==(const Quaternion &q);
  144. /*------------------------------------------------------
  145. * Pre :
  146. * Post : Compares Q to this quaternion
  147. * returns boolean true if equal, otherwise false
  148. *
  149. *-- History ------------------------------------------
  150. *
  151. * 2002.05.08:
  152. * Mongoose - Created
  153. ------------------------------------------------------*/
  154. Quaternion conjugate();
  155. /*------------------------------------------------------
  156. * Pre :
  157. * Post : Returns conjugate of this quaternion
  158. *
  159. *-- History ------------------------------------------
  160. *
  161. * 2002.05.08:
  162. * Mongoose - Created
  163. ------------------------------------------------------*/
  164. Quaternion scale(vec_t s);
  165. /*------------------------------------------------------
  166. * Pre :
  167. * Post : Returns scaled result of this quaternion
  168. *
  169. *-- History ------------------------------------------
  170. *
  171. * 2002.05.08:
  172. * Mongoose - Created
  173. ------------------------------------------------------*/
  174. Quaternion inverse();
  175. /*------------------------------------------------------
  176. * Pre :
  177. * Post : Returns inverse of this quaternion
  178. *
  179. *-- History ------------------------------------------
  180. *
  181. * 2002.05.08:
  182. * Mongoose - Created
  183. ------------------------------------------------------*/
  184. static vec_t dot(Quaternion a, Quaternion b);
  185. /*------------------------------------------------------
  186. * Pre :
  187. * Post : Returns dot product of A and B quaternions
  188. *
  189. *-- History ------------------------------------------
  190. *
  191. * 2002.05.08:
  192. * Mongoose - Created
  193. ------------------------------------------------------*/
  194. vec_t magnitude();
  195. /*------------------------------------------------------
  196. * Pre :
  197. * Post : Returns magnitude this quaternion
  198. *
  199. *-- History ------------------------------------------
  200. *
  201. * 2002.05.08:
  202. * Mongoose - Created
  203. ------------------------------------------------------*/
  204. static Quaternion slerp(Quaternion a, Quaternion b, vec_t time);
  205. /*------------------------------------------------------
  206. * Pre :
  207. * Post : Interpolates between A and B rotations and
  208. * returns resultant quaternion using
  209. * spherical linear interpolation:
  210. *
  211. * I = (((B . A)^ -1)^ Time) A
  212. *
  213. *-- History ------------------------------------------
  214. *
  215. * 2002.05.08:
  216. * Mongoose - Created
  217. ------------------------------------------------------*/
  218. ////////////////////////////////////////////////////////////
  219. // Public Mutators
  220. ////////////////////////////////////////////////////////////
  221. void setIdentity();
  222. /*------------------------------------------------------
  223. * Pre :
  224. * Post : Sets this quaternion to identity
  225. *
  226. *-- History ------------------------------------------
  227. *
  228. * 2002.05.08:
  229. * Mongoose - Created
  230. ------------------------------------------------------*/
  231. void set(vec_t angle, vec_t x, vec_t y, vec_t z);
  232. /*------------------------------------------------------
  233. * Pre :
  234. * Post : Sets this quaternion
  235. *
  236. *-- History ------------------------------------------
  237. *
  238. * 2002.05.08:
  239. * Mongoose - Created
  240. ------------------------------------------------------*/
  241. void normalize();
  242. /*------------------------------------------------------
  243. * Pre :
  244. * Post : Normalize this quaternion
  245. *
  246. *-- History ------------------------------------------
  247. *
  248. * 2002.05.08:
  249. * Mongoose - Created
  250. ------------------------------------------------------*/
  251. void copy(Quaternion q);
  252. /*------------------------------------------------------
  253. * Pre :
  254. * Post : Set this quaternion using q
  255. *
  256. *-- History ------------------------------------------
  257. *
  258. * 2002.05.08:
  259. * Mongoose - Created
  260. ------------------------------------------------------*/
  261. void setByMatrix(matrix_t m);
  262. /*------------------------------------------------------
  263. * Pre : Matrix is valid column order
  264. * Post : Sets matrix equiv of this quaternion
  265. *
  266. *-- History ------------------------------------------
  267. *
  268. * 2002.05.08:
  269. * Mongoose - Created
  270. ------------------------------------------------------*/
  271. private:
  272. ////////////////////////////////////////////////////////////
  273. // Private Accessors
  274. ////////////////////////////////////////////////////////////
  275. Quaternion multiply(Quaternion a, Quaternion b);
  276. /*------------------------------------------------------
  277. * Pre :
  278. * Post : Multiplies A and B quaternions
  279. * returns resultant quaternion
  280. *
  281. *-- History ------------------------------------------
  282. *
  283. * 2002.05.08:
  284. * Mongoose - Created
  285. ------------------------------------------------------*/
  286. Quaternion divide(Quaternion a, Quaternion b);
  287. /*------------------------------------------------------
  288. * Pre :
  289. * Post : Divides B from A quaternion
  290. * returns quotient quaternion
  291. *
  292. *-- History ------------------------------------------
  293. *
  294. * 2002.05.08:
  295. * Mongoose - Created
  296. ------------------------------------------------------*/
  297. Quaternion add(Quaternion a, Quaternion b);
  298. /*------------------------------------------------------
  299. * Pre :
  300. * Post : Adds A and B quaternions
  301. * returns resultant quaternion
  302. *
  303. *-- History ------------------------------------------
  304. *
  305. * 2002.05.08:
  306. * Mongoose - Created
  307. ------------------------------------------------------*/
  308. Quaternion subtract(Quaternion a, Quaternion b);
  309. /*------------------------------------------------------
  310. * Pre :
  311. * Post : Subtracts B from A quaternion
  312. * returns resultant quaternion
  313. *
  314. *-- History ------------------------------------------
  315. *
  316. * 2002.05.08:
  317. * Mongoose - Created
  318. ------------------------------------------------------*/
  319. ////////////////////////////////////////////////////////////
  320. // Private Mutators
  321. ////////////////////////////////////////////////////////////
  322. vec_t mW, mX, mY, mZ; /* Quaternion */
  323. };
  324. #endif