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.

Md3AnimModel.h 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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 : Md3AnimModel
  9. * License : No use w/o permission (C) 2002 Mongoose
  10. * Comments: Md3 animation model class
  11. *
  12. *
  13. * This file was generated using Mongoose's C++
  14. * template generator script. <stu7440@westga.edu>
  15. *
  16. *
  17. *-- Test Defines -----------------------------------------------
  18. *
  19. * UNIT_TEST_MD3 - Builds Md3 class as a console unit test
  20. *
  21. *-- History ----------------------------------------------------
  22. *
  23. * 2002.06.19:
  24. * Mongoose - Created
  25. ================================================================*/
  26. #ifndef __FREYJA_MONGOOSE_MD3ANIMMODEL_H_
  27. #define __FREYJA_MONGOOSE_MD3ANIMMODEL_H_
  28. #include "Md3.h"
  29. typedef enum
  30. {
  31. MD3_LOD_HIGH = 0,
  32. MD3_LOD_MED = 1,
  33. MD3_LOD_LOW = 2,
  34. } md3_lod_t;
  35. typedef enum
  36. {
  37. MD3_SEX_MALE = 0,
  38. MD3_SEX_FEMALE = 1,
  39. MD3_SEX_NEUTER = 2,
  40. } md3_sex_t;
  41. typedef enum
  42. {
  43. UNSUPPORTED = -1,
  44. BOTH_DEATH1 = 0, // The first twirling death animation
  45. BOTH_DEAD1, // The end of the first twirling death animation
  46. BOTH_DEATH2, // The second twirling death animation
  47. BOTH_DEAD2, // The end of the second twirling death animation
  48. BOTH_DEATH3, // The back flip death animation
  49. BOTH_DEAD3, // The end of the back flip death animation
  50. TORSO_GESTURE, // The torso's gesturing animation
  51. TORSO_ATTACK, // The torso's attack1 animation
  52. TORSO_ATTACK2, // The torso's attack2 animation
  53. TORSO_DROP, // The torso's weapon drop animation
  54. TORSO_RAISE, // The torso's weapon pickup animation
  55. TORSO_STAND, // The torso's idle stand animation
  56. TORSO_STAND2, // The torso's idle stand2 animation
  57. LEGS_WALKCR, // The legs's crouching walk animation
  58. LEGS_WALK, // The legs's walk animation
  59. LEGS_RUN, // The legs's run animation
  60. LEGS_BACK, // The legs's running backwards animation
  61. LEGS_SWIM, // The legs's swimming animation
  62. LEGS_JUMP, // The legs's jumping animation
  63. LEGS_LAND, // The legs's landing animation
  64. LEGS_JUMPB, // The legs's jumping back animation
  65. LEGS_LANDB, // The legs's landing back animation
  66. LEGS_IDLE, // The legs's idle stand animation
  67. LEGS_IDLECR, // The legs's idle crouching animation
  68. LEGS_TURN // The legs's turn animation
  69. // MD3_ANIM_SIZE
  70. } md3_animation_id_t;
  71. typedef struct md3_texture_s
  72. {
  73. char *name;
  74. unsigned int name_len;
  75. int gl_texture_id;
  76. } md3_texture_t;
  77. typedef struct md3_animation_s
  78. {
  79. md3_animation_id_t id;
  80. unsigned int first_frame;
  81. unsigned int end_frame;
  82. unsigned int num_frames;
  83. unsigned int looping_frames;
  84. unsigned int frames_per_second;
  85. } md3_animation_t;
  86. class Md3AnimModel
  87. {
  88. public:
  89. enum Md3AnimModelFlags
  90. {
  91. fDisableTagInterpolate = 1,
  92. fAnimate = 2,
  93. fRenderBones = 4,
  94. fDrawWeapon = 8,
  95. fDisableMeshInterpolate = 16,
  96. fRenderingWarnings = 32,
  97. fUseNormals = 64
  98. };
  99. ////////////////////////////////////////////////////////////
  100. // Constructors
  101. ////////////////////////////////////////////////////////////
  102. Md3AnimModel();
  103. /*------------------------------------------------------
  104. * Pre :
  105. * Post : Md3AnimModel object is deconstructed
  106. *
  107. *-- History ------------------------------------------
  108. *
  109. * 2002.06.19:
  110. * Mongoose - Created
  111. ------------------------------------------------------*/
  112. ~Md3AnimModel();
  113. /*------------------------------------------------------
  114. * Pre : Md3AnimModel object is allocated
  115. * Post : Md3AnimModel object is deconstructed
  116. *
  117. *-- History ------------------------------------------
  118. *
  119. * 2002.06.19:
  120. * Mongoose - Created
  121. ------------------------------------------------------*/
  122. ////////////////////////////////////////////////////////////
  123. // Public Accessors
  124. ////////////////////////////////////////////////////////////
  125. unsigned int getFlags();
  126. /*------------------------------------------------------
  127. * Pre :
  128. * Post : Gets option flags
  129. *
  130. *-- History ------------------------------------------
  131. *
  132. * 2002.12.29:
  133. * Mongoose - Created
  134. ------------------------------------------------------*/
  135. md3_animation_id_t getAnimUpper();
  136. /*------------------------------------------------------
  137. * Pre :
  138. * Post : Get animation for upper model
  139. *
  140. *-- History ------------------------------------------
  141. *
  142. * 2002.06.22:
  143. * Mongoose - Created
  144. ------------------------------------------------------*/
  145. md3_animation_id_t getAnimLower();
  146. /*------------------------------------------------------
  147. * Pre :
  148. * Post : Get animation for lower model
  149. *
  150. *-- History ------------------------------------------
  151. *
  152. * 2002.06.22:
  153. * Mongoose - Created
  154. ------------------------------------------------------*/
  155. ////////////////////////////////////////////////////////////
  156. // Public Mutators
  157. ////////////////////////////////////////////////////////////
  158. void setFlag(Md3AnimModelFlags flag);
  159. /*------------------------------------------------------
  160. * Pre :
  161. * Post : Sets option flag
  162. *
  163. *-- History ------------------------------------------
  164. *
  165. * 2002.12.29:
  166. * Mongoose - Created
  167. ------------------------------------------------------*/
  168. void toggleFlag(Md3AnimModelFlags flag);
  169. /*------------------------------------------------------
  170. * Pre :
  171. * Post : Clear/Set option flag
  172. *
  173. *-- History ------------------------------------------
  174. *
  175. * 2002.12.29:
  176. * Mongoose - Created
  177. ------------------------------------------------------*/
  178. void setAnimUpper(md3_animation_id_t anim);
  179. /*------------------------------------------------------
  180. * Pre :
  181. * Post : Animation is set for upper model
  182. *
  183. *-- History ------------------------------------------
  184. *
  185. * 2002.06.22:
  186. * Mongoose - Created
  187. ------------------------------------------------------*/
  188. void setAnimLower(md3_animation_id_t anim);
  189. /*------------------------------------------------------
  190. * Pre :
  191. * Post : Animation is set for lower model
  192. *
  193. *-- History ------------------------------------------
  194. *
  195. * 2002.06.22:
  196. * Mongoose - Created
  197. ------------------------------------------------------*/
  198. void setDebug(unsigned char level);
  199. /*------------------------------------------------------
  200. * Pre :
  201. * Post : level 0 = errors, 1 = warnings, 2 = debug1
  202. *
  203. *-- History ------------------------------------------
  204. *
  205. * 2002.06.19:
  206. * Mongoose - Created
  207. ------------------------------------------------------*/
  208. int load(char *modelPath, char *skin, md3_lod_t modelLoD);
  209. /*------------------------------------------------------
  210. * Pre : modelPath - Path to directory containg data files
  211. *
  212. * eg '/usr/local/games/quake3/qbase3/players/slash'
  213. *
  214. * skin - name of skin base to use
  215. *
  216. * eg 'default' or 'red' or 'blue' etc
  217. *
  218. * modelLoD - Level of detail to use,
  219. *
  220. * Post : Error code is returned, 0 no error
  221. * Md3s are read into memory
  222. *
  223. *-- History ------------------------------------------
  224. *
  225. *
  226. * 2002.12.29:
  227. * Mongoose - Progressively loads lower LoDs if it can't
  228. * find passed LoD
  229. *
  230. * 2002.06.19:
  231. * Mongoose - Created
  232. ------------------------------------------------------*/
  233. int loadAnimations(char *modelPath);
  234. /*------------------------------------------------------
  235. * Pre :
  236. * Post : Loads animations for composite model
  237. *
  238. *-- History ------------------------------------------
  239. *
  240. * 2002.06.19:
  241. * Mongoose - Created
  242. ------------------------------------------------------*/
  243. int loadWeapon(char *modelPath, char *name);
  244. /*------------------------------------------------------
  245. * Pre :
  246. * Post : Loads a weapon model
  247. *
  248. *-- History ------------------------------------------
  249. *
  250. * 2002.06.19:
  251. * Mongoose - Created
  252. ------------------------------------------------------*/
  253. void render();
  254. /*------------------------------------------------------
  255. * Pre : Build with USING_OPENGL
  256. * Post : Renders entire composite model
  257. *
  258. *-- History ------------------------------------------
  259. *
  260. * 2002.06.19:
  261. * Mongoose - Created
  262. ------------------------------------------------------*/
  263. void renderTag(unsigned int id);
  264. /*------------------------------------------------------
  265. * Pre : Build with USING_OPENGL
  266. * Post : Renders tag and it's slaves
  267. *
  268. *-- History ------------------------------------------
  269. *
  270. * 2002.06.19:
  271. * Mongoose - Created
  272. ------------------------------------------------------*/
  273. void renderModel(Md3 &model);
  274. /*------------------------------------------------------
  275. * Pre : Build with USING_OPENGL
  276. * Post : Renders single Md3 model
  277. *
  278. *-- History ------------------------------------------
  279. *
  280. * 2002.06.19:
  281. * Mongoose - Created
  282. ------------------------------------------------------*/
  283. unsigned int texNumTest; /* Number of texTests */
  284. md3_texture_t texTest[32]; /* Texture loader/id trans test */
  285. private:
  286. ////////////////////////////////////////////////////////////
  287. // Private Accessors
  288. ////////////////////////////////////////////////////////////
  289. ////////////////////////////////////////////////////////////
  290. // Private Mutators
  291. ////////////////////////////////////////////////////////////
  292. void setCurrentTime(Md3 &model);
  293. /*------------------------------------------------------
  294. * Pre :
  295. * Post : time is set for model animation
  296. *
  297. *-- History ------------------------------------------
  298. *
  299. * 2002.06.23:
  300. * Mongoose - Created
  301. ------------------------------------------------------*/
  302. void updateModel(Md3 &model);
  303. /*------------------------------------------------------
  304. * Pre :
  305. * Post : Sets up md3 for next render pass
  306. *
  307. *-- History ------------------------------------------
  308. *
  309. * 2002.06.23:
  310. * Mongoose - Created, obsoletes old anim arrays
  311. ------------------------------------------------------*/
  312. void initMd3(Md3 &model, unsigned int id);
  313. /*------------------------------------------------------
  314. * Pre :
  315. * Post : Sets up md3 init animation values
  316. *
  317. *-- History ------------------------------------------
  318. *
  319. * 2002.06.23:
  320. * Mongoose - Created, obsoletes old anim arrays
  321. ------------------------------------------------------*/
  322. int addAnim(char *modelPath, md3_animation_id_t id,
  323. unsigned int firstFrame, unsigned int numFrames,
  324. unsigned int loopingFrames, unsigned int framesPerSecond);
  325. /*------------------------------------------------------
  326. * Pre :
  327. * Post : Sets up animation array
  328. *
  329. *-- History ------------------------------------------
  330. *
  331. * 2002.06.22:
  332. * Mongoose - Created, forked off load()
  333. ------------------------------------------------------*/
  334. int loadMd3(Md3 &model, char *base, char *modelPath, char *skin,
  335. md3_lod_t modelLoD);
  336. /*------------------------------------------------------
  337. * Pre :
  338. * Post : Loads model and if given skin
  339. *
  340. *-- History ------------------------------------------
  341. *
  342. * 2002.06.22:
  343. * Mongoose - Created, forked off load()
  344. ------------------------------------------------------*/
  345. int loadSkin(Md3 &model, char *filename);
  346. /*------------------------------------------------------
  347. * Pre :
  348. * Post : Loads skin for model
  349. *
  350. *-- History ------------------------------------------
  351. *
  352. * 2002.06.19:
  353. * Mongoose - Created
  354. ------------------------------------------------------*/
  355. int loadShader(Md3 &model, char *filename);
  356. /*------------------------------------------------------
  357. * Pre :
  358. * Post : Loads shader for model
  359. *
  360. *-- History ------------------------------------------
  361. *
  362. * 2002.06.19:
  363. * Mongoose - Created
  364. ------------------------------------------------------*/
  365. void connectModels(char *tagName, Md3 &modelA, Md3 &modelB);
  366. /*------------------------------------------------------
  367. * Pre :
  368. * Post : Connects models as A slave to B master
  369. *
  370. *-- History ------------------------------------------
  371. *
  372. * 2002.06.19:
  373. * Mongoose - Created
  374. ------------------------------------------------------*/
  375. int cacheTexture(char *texture);
  376. /*------------------------------------------------------
  377. * Pre :
  378. * Post : Sets up texture filename caching
  379. *
  380. *-- History ------------------------------------------
  381. *
  382. * 2002.06.19:
  383. * Mongoose - Created
  384. ------------------------------------------------------*/
  385. unsigned int mFlags; /* Model options */
  386. Md3 m_head; /* Head model */
  387. Md3 m_upper; /* Upper body model */
  388. Md3 m_lower; /* Lower body model */
  389. Md3 m_weapon; /* Weapon model */
  390. unsigned int m_animCount; /* Number of animations loaded */
  391. unsigned char m_debug; /* Set level of debug info to stdout */
  392. md3_sex_t m_sex; /* Sex of model */
  393. md3_animation_t m_anim[32]; /* This models animation list */
  394. md3_animation_id_t m_upperAnim; /* Current upper model animation */
  395. md3_animation_id_t m_lowerAnim; /* Current lower model animation */
  396. };
  397. #endif