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.

Quaternion.h 11KB

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