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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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://gooseegg.sourceforge.net
  7. * Email : stu7440@westga.edu
  8. * Object : Md3
  9. * Comments: This is the MD3 model class.
  10. *
  11. * See file COPYING for license details.
  12. *
  13. * Quake (c) id Software 1995 - 2000
  14. *
  15. * MD3 file format specs provided by Mental Vortex,
  16. * and that site says the specs may not be 100% correct
  17. * so - since this class is desgined using their specs...
  18. *
  19. *-- Test Defines -----------------------------------------------------
  20. *
  21. * UNIT_TEST_MD3 - Builds Md3 class as a console unit test program
  22. * UNIT_TEST_MD3_LV2 - Does more debugging when used with unit test
  23. *
  24. *-- History ----------------------------------------------------------
  25. *
  26. * 2002.10.19:
  27. * Mongoose - Interface update, Animation support starts
  28. *
  29. * 2000.10.07:
  30. * Mongoose - Interface update
  31. *
  32. * 2000.06.03:
  33. * Mongoose - Created, MD3 specs provided by Mental Vortex
  34. ==========================================================================*/
  35. #ifndef __FREYJA_MONGOOSE_MD3_H
  36. #define __FREYJA_MONGOOSE_MD3_H
  37. #define MD3_IDALIASHEADER 0x33504449 // "IDP3"
  38. #define MD3_ALIAS_VERSION 15
  39. #define MD3_MAX_FRAMES 1024
  40. #ifndef vec3_t
  41. typedef float vec3_t[3];
  42. #endif
  43. #ifndef mat3_t
  44. typedef float mat3_t[3][3];
  45. #endif
  46. typedef struct md3_tag_s
  47. {
  48. char name[64]; /* Name of 'tag' as it's usually
  49. called in the md3 files try to
  50. see it as a sub-mesh/seperate
  51. mesh-part.
  52. Sometimes this 64 string may
  53. contain some garbage, but
  54. i've been told this is because
  55. some tools leave garbage in
  56. those strings, but they ARE
  57. strings... */
  58. vec3_t center; /* Relative position of tag */
  59. mat3_t rotation; /* The direction the tag is facing
  60. relative to the rest of the model */
  61. } md3_tag_t;
  62. typedef struct md3_boneframe_s
  63. {
  64. float mins[3];
  65. float maxs[3];
  66. float center[3];
  67. float scale;
  68. char creator[16];
  69. } md3_bone_t;
  70. typedef struct md3_skin_s
  71. {
  72. char name[68]; /* Name of skin used by mesh
  73. 65 chars,
  74. 32 bit aligned == 68 chars */
  75. int index; /* For shader use (skin is a shader) */
  76. } md3_skin_t;
  77. typedef struct md3_tri_index_s
  78. {
  79. int triangle[3]; /* Vertex 1, 2, 3 of triangle */
  80. } md3_tri_index_t;
  81. typedef struct md3_texel_s
  82. {
  83. float st[2]; /* Texel (s, t) */
  84. } md3_texel_t;
  85. typedef struct md3_vertex_s
  86. {
  87. signed short pos[3]; /* Vertex X/Y/Z coordinate */
  88. unsigned char st[2]; /* Enviromental mapping
  89. texture coordinates
  90. (Acutally encoded normal?) */
  91. float norm[3]; /* Decoded normal from above decoded */
  92. } md3_vertex_t;
  93. typedef struct md3_mesh_s
  94. {
  95. // Start Mesh Header /////////////
  96. char id[4]; /* Mesh alias id, must be IDP3 */
  97. char name[68]; /* Name of mesh
  98. 65 chars,
  99. 32 bit aligned == 68 chars */
  100. int flags;
  101. int num_frames; /* Number of VertexMorph frames
  102. in mesh */
  103. int num_shaders; /* Number of shaders in mesh*/
  104. int num_skins; /* Number of skins in mesh,
  105. for backwards compatibility with
  106. incorrect/obsolete spec */
  107. int num_vertices; /* Number of vertices */
  108. int num_triangles; /* Number of triangles */
  109. int tris_offset; /* Starting position of
  110. Triangle data, relative
  111. to start of Mesh_Header */
  112. int header_size; /* Size of header */
  113. int texel_offset; /* Starting position of
  114. texvector data, relative
  115. to start of Mesh_Header */
  116. int vertex_offset; /* Starting position of
  117. vertex data,relative
  118. to start of Mesh_Header */
  119. int mesh_size; /* Size of mesh */
  120. // End Mesh Header ///////////////
  121. md3_skin_t *skin; /* Skins */
  122. md3_tri_index_t *tris; /* Triangles */
  123. md3_texel_t *texel; /* Texels */
  124. md3_vertex_t *vertex; /* Vertices */
  125. } md3_mesh_t;
  126. class Md3
  127. {
  128. public:
  129. enum Md3Flag
  130. {
  131. fDecodeNormals = 1
  132. };
  133. ////////////////////////////////////////////////////////////
  134. // Constructors
  135. ////////////////////////////////////////////////////////////
  136. Md3();
  137. /*------------------------------------------------------
  138. * Pre :
  139. * Post : Md3 object is constructed
  140. *
  141. *-- History ------------------------------------------
  142. *
  143. * 2000.06.03:
  144. * Mongoose - Created
  145. ------------------------------------------------------*/
  146. Md3(unsigned int num_meshes, unsigned int num_bones, unsigned int num_tags);
  147. /*------------------------------------------------------
  148. * Pre : Md3 is being used for exporting, since
  149. * this is the only way to allocate arrays
  150. * from public access
  151. *
  152. * Post : Md3 object is constructed and ready to edit
  153. *
  154. *-- History ------------------------------------------
  155. *
  156. * 2002.06.19:
  157. * Mongoose - Created
  158. ------------------------------------------------------*/
  159. ~Md3();
  160. /*------------------------------------------------------
  161. * Pre : Md3 object is allocated
  162. * Post : Md3 object is deconstructed
  163. *
  164. *-- History ------------------------------------------
  165. *
  166. * 2000.06.03:
  167. * Mongoose - Created
  168. ------------------------------------------------------*/
  169. ////////////////////////////////////////////////////////////
  170. // Public Accessors
  171. ////////////////////////////////////////////////////////////
  172. unsigned int getNumMeshes();
  173. /*------------------------------------------------------
  174. * Pre :
  175. * Post : Mesh count is returned
  176. *
  177. *-- History ------------------------------------------
  178. *
  179. * 2002.06.19:
  180. * Mongoose - Created, Obsoletes:
  181. * 2000.06.03, int NumTags();
  182. ------------------------------------------------------*/
  183. unsigned int getNumTags();
  184. /*------------------------------------------------------
  185. * Pre :
  186. * Post : Tag count is returned
  187. *
  188. *-- History ------------------------------------------
  189. *
  190. * 2002.06.19:
  191. * Mongoose - Created, Obsoletes:
  192. * 2000.06.03, int NumTags();
  193. ------------------------------------------------------*/
  194. unsigned int getNumBones();
  195. /*------------------------------------------------------
  196. * Pre :
  197. * Post : Bone count is returned
  198. *
  199. *-- History ------------------------------------------
  200. *
  201. * 2002.06.19:
  202. * Mongoose - Created, Obsoletes:
  203. * 2000.06.03, int NumTags();
  204. ------------------------------------------------------*/
  205. md3_mesh_t *getMeshes();
  206. /*------------------------------------------------------
  207. * Pre :
  208. * Post : Mesh list is returned
  209. *
  210. *-- History ------------------------------------------
  211. *
  212. * 2002.06.19:
  213. * Mongoose - Created, Obsoletes:
  214. * 2000.06.03, md3_mesh_t *Mesh();
  215. ------------------------------------------------------*/
  216. md3_tag_t *getTags();
  217. /*------------------------------------------------------
  218. * Pre :
  219. * Post : Tag list is returned
  220. *
  221. *-- History ------------------------------------------
  222. *
  223. * 2002.06.19:
  224. * Mongoose - Created, Obsoletes:
  225. * 2000.06.03, md3_tag_t *Tag();
  226. ------------------------------------------------------*/
  227. md3_bone_t *getBones();
  228. /*------------------------------------------------------
  229. * Pre :
  230. * Post : Bone list is returned
  231. *
  232. *-- History ------------------------------------------
  233. *
  234. * 2002.06.19:
  235. * Mongoose - Created, Obsoletes:
  236. * 2000.06.03, md3_boneframe_t *Bone();
  237. ------------------------------------------------------*/
  238. ////////////////////////////////////////////////////////////
  239. // Public Mutators
  240. ////////////////////////////////////////////////////////////
  241. void toggleFlag(Md3Flag flag);
  242. /*------------------------------------------------------
  243. * Pre :
  244. * Post : Toggles a flag
  245. *
  246. *-- History ------------------------------------------
  247. *
  248. * 2003.01.01:
  249. * Mongoose - Created
  250. ------------------------------------------------------*/
  251. void reset();
  252. /*------------------------------------------------------
  253. * Pre :
  254. * Post : Resets all model data
  255. *
  256. *-- History ------------------------------------------
  257. *
  258. * 2002.06.22:
  259. * Mongoose - Created
  260. ------------------------------------------------------*/
  261. void setDebug(unsigned char level);
  262. /*------------------------------------------------------
  263. * Pre :
  264. * Post : level 0 = errors, 1 = warnings, 2 = debug1
  265. *
  266. *-- History ------------------------------------------
  267. *
  268. * 2002.06.19:
  269. * Mongoose - Created
  270. ------------------------------------------------------*/
  271. int load(char *filename);
  272. /*------------------------------------------------------
  273. * Pre :
  274. * Post : Error code is returned, 0 no error
  275. * Md3 filename is read into memory
  276. *
  277. *-- History ------------------------------------------
  278. *
  279. * 2000.06.03:
  280. * Mongoose - Created
  281. ------------------------------------------------------*/
  282. int save(char *filename);
  283. /*------------------------------------------------------
  284. * Pre :
  285. * Post : Error code is returned, 0 no error
  286. * Md3 saved as filename
  287. *
  288. *-- History ------------------------------------------
  289. *
  290. * 2000.10.06:
  291. * Mongoose - Created
  292. ------------------------------------------------------*/
  293. // Testing members
  294. unsigned int *slaveTest;
  295. unsigned int idTest;
  296. int *texTest;
  297. // For animation rendering
  298. unsigned int numAnimations;
  299. unsigned int currentAnimation;
  300. unsigned int currentFrame;
  301. unsigned int nextFrame;
  302. float time;
  303. float lastTime;
  304. private:
  305. ////////////////////////////////////////////////////////////
  306. // Private Accessors
  307. ////////////////////////////////////////////////////////////
  308. ////////////////////////////////////////////////////////////
  309. // Private Mutators
  310. ////////////////////////////////////////////////////////////
  311. void printError(char *method, char *s, ...);
  312. /*------------------------------------------------------
  313. * Pre :
  314. * Post : Dumps error to stderr
  315. *
  316. *-- History ------------------------------------------
  317. *
  318. * 2002.06.19:
  319. * Mongoose - Created
  320. ------------------------------------------------------*/
  321. void printWarning(char *method, char *s, ...);
  322. /*------------------------------------------------------
  323. * Pre :
  324. * Post : Dumps warning to stderr
  325. *
  326. *-- History ------------------------------------------
  327. *
  328. * 2002.06.19:
  329. * Mongoose - Created
  330. ------------------------------------------------------*/
  331. void printDebug(char *method, char *s, ...);
  332. /*------------------------------------------------------
  333. * Pre : Debugging is on
  334. * Post : Dumps debug info
  335. *
  336. *-- History ------------------------------------------
  337. *
  338. * 2002.06.19:
  339. * Mongoose - Created
  340. ------------------------------------------------------*/
  341. void createMeshes(unsigned int num);
  342. /*------------------------------------------------------
  343. * Pre : Model hasn't been init yet
  344. * Post : Allocates num of meshes for model
  345. *
  346. *-- History ------------------------------------------
  347. *
  348. * 2002.06.19:
  349. * Mongoose - Created, Obsoletes:
  350. * 2000.10.24, void NumMeshes(int);
  351. * 2000.10.24, void Mesh(md3_mesh_t *);
  352. ------------------------------------------------------*/
  353. void createTags(unsigned int num);
  354. /*------------------------------------------------------
  355. * Pre : Model hasn't been init yet
  356. * Post : Allocates num of tags for model
  357. *
  358. *-- History ------------------------------------------
  359. *
  360. * 2002.06.19:
  361. * Mongoose - Created, Obsoletes:
  362. * 2000.10.24, void NumTags(int);
  363. * 2000.10.24, void Tag(md3_tag_t *);
  364. ------------------------------------------------------*/
  365. void createBones(unsigned int num);
  366. /*------------------------------------------------------
  367. * Pre : Model hasn't been init yet
  368. * Post : Allocates num of bones for model
  369. *
  370. *-- History ------------------------------------------
  371. *
  372. * 2002.06.19:
  373. * Mongoose - Created, Obsoletes:
  374. * 2000.10.24, void NumBones(int);
  375. * 2000.10.24, void Bone(md3_bone_t *);
  376. ------------------------------------------------------*/
  377. unsigned int mFlags;
  378. // Start Header //////////////////////////////////////////////
  379. int m_id; /* Alias id always "IDP3" */
  380. int m_version; /* Version number, always 15 */
  381. char m_filename[68]; /* Sometimes left blank...
  382. 65 chars, 32bit aligned ==
  383. 68 chars */
  384. int m_num_bones; /* Number of Bone */
  385. int m_num_tags; /* Number of 'tags' per Bone */
  386. int m_num_meshes; /* Number of meshes/skins */
  387. int m_max_skins; /* Maximum number of unique skins
  388. used in md3 file */
  389. int m_header_length; /* Always equal to the length of
  390. this header */
  391. int m_tag_start; /* Starting position of
  392. tag-structures */
  393. int m_surfaces_start; /* Starting position of
  394. geometeric data (mesh structures) */
  395. int m_file_size; /* Size of file */
  396. // End Header ////////////////////////////////////////////////
  397. unsigned char m_debug; /* Set level of debug info to stdout */
  398. md3_tag_t *m_tags; /* Tags */
  399. md3_bone_t *m_bones; /* Bones */
  400. md3_mesh_t *m_meshes; /* Meshes */
  401. };
  402. #endif