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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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 : PSKModel
  9. * License : No use w/o permission (C) 2003 Mongoose
  10. * Comments: Unreal Tournament skeletal model
  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_PSKMODEL - Builds PSKModel class as a console unit test
  19. *
  20. *-- History ------------------------------------------------
  21. *
  22. * 2003.07.12:
  23. * Mongoose - UT Package prototype code moved into 'UTPackage'
  24. * API changes to structs to clearify meaning
  25. *
  26. * 2003.06.12:
  27. * Mongoose - PSA keyframes fixed, special thanks to:
  28. * Steven Fuller and Forest Hale for help picking
  29. * apart those tough little 8 bytes =)
  30. *
  31. * 2003.06.11:
  32. * Mongoose - Broke up rendering and model loading into seperate
  33. * classes ( Closely coupled )
  34. *
  35. * PSA experimental loader
  36. *
  37. * 2003.06.10:
  38. * Mongoose - Skeletal format fixed, should load perfectly
  39. *
  40. * 2003.01.20:
  41. * Mongoose - Fixed triangle rendering thanks to debugging by
  42. * Steven Fuller, who found the tris -> UV -> vert
  43. * connection
  44. *
  45. * Finished up basic rendering, lots of
  46. * small fixes/features
  47. *
  48. * 2003.01.06:
  49. * Mongoose - Created
  50. ================================================================*/
  51. #ifndef GUARD__FREYJA_MONGOOSE_PSKMODEL_H_
  52. #define GUARD__FREYJA_MONGOOSE_PSKMODEL_H_
  53. typedef struct /* 13 bytes */
  54. {
  55. unsigned short x, y, z;
  56. unsigned char material;
  57. unsigned int flags;
  58. unsigned short unknown;
  59. } psk_face_t;
  60. typedef struct /* 16 bytes */
  61. {
  62. unsigned short vertex;
  63. unsigned short unknown1;
  64. float uv[2];
  65. unsigned int unknown2;
  66. } psk_vtxw_t;
  67. typedef struct /* 88 bytes */
  68. {
  69. char name[64];
  70. unsigned int unknown1;
  71. unsigned int unknown2;
  72. unsigned int unknown3;
  73. unsigned int unknown4;
  74. unsigned int unknown5;
  75. unsigned int unknown6;
  76. } psk_material_t;
  77. typedef struct /* 120 bytes */
  78. {
  79. char name[64];
  80. unsigned int flags; /* Option flags? */
  81. unsigned int numChildren;
  82. unsigned int parentIndex;
  83. float restDir[4]; /* Quaternion x,y,z,w */
  84. float restLoc[3];
  85. int unknown[4]; /* Scale? */
  86. } psk_bone_t;
  87. typedef struct /* 12 bytes */
  88. {
  89. float weight;
  90. unsigned int vertexIndex;
  91. unsigned int boneIndex;
  92. } psk_weight_t;
  93. typedef struct /* 168 bytes */
  94. {
  95. char name[64];
  96. char name2[64];
  97. unsigned int numBones;
  98. unsigned int rootId; // ?
  99. unsigned int key[2];
  100. float keyf;
  101. float time[2];
  102. float unknown[3];
  103. } psa_anim_info_t;
  104. typedef struct /* 32 bytes */
  105. {
  106. float trans[3]; // xyz
  107. float dir[4]; // xyzw
  108. float scale; // ?
  109. } psa_key_frame_t;
  110. class PSKModel
  111. {
  112. public:
  113. enum PSKModelFlag
  114. {
  115. fDebugWeightLoad = 1,
  116. fDebugPointLoad = 2,
  117. fDebugFaceLoad = 4,
  118. fDebugUVLoad = 8,
  119. fDebugMattLoad = 16,
  120. fDebugBoneLoad = 32
  121. };
  122. ////////////////////////////////////////////////////////////
  123. // Constructors
  124. ////////////////////////////////////////////////////////////
  125. PSKModel();
  126. /*------------------------------------------------------
  127. * Pre :
  128. * Post : Constructs an object of PSKModel
  129. *
  130. *-- History ------------------------------------------
  131. *
  132. * 2003.01.06:
  133. * Mongoose - Created
  134. ------------------------------------------------------*/
  135. ~PSKModel();
  136. /*------------------------------------------------------
  137. * Pre : PSKModel object is allocated
  138. * Post : Deconstructs an object of PSKModel
  139. *
  140. *-- History ------------------------------------------
  141. *
  142. * 2003.01.06:
  143. * Mongoose - Created
  144. ------------------------------------------------------*/
  145. ////////////////////////////////////////////////////////////
  146. // Public Accessors
  147. ////////////////////////////////////////////////////////////
  148. void printSkeletion(bool printNames);
  149. /*------------------------------------------------------
  150. * Pre : <PrintNames> if true use names instead of Ids
  151. *
  152. * Post : Prints skeletion bone trace one bone per line
  153. *
  154. *-- History ------------------------------------------
  155. *
  156. * 2003.06.10:
  157. * Mongoose - Created
  158. ------------------------------------------------------*/
  159. ////////////////////////////////////////////////////////////
  160. // Public Mutators
  161. ////////////////////////////////////////////////////////////
  162. int load(char *filename);
  163. /*------------------------------------------------------
  164. * Pre :
  165. * Post : Loads PSK model from disk
  166. *
  167. *-- History ------------------------------------------
  168. *
  169. * 2003.01.06:
  170. * Mongoose - Created
  171. ------------------------------------------------------*/
  172. unsigned int mFlags;
  173. unsigned int mNumFrames;
  174. unsigned int mNumVertices;
  175. unsigned int mNumFaces;
  176. unsigned int mNumVTXWs;
  177. unsigned int mNumMaterials;
  178. unsigned int mNumBones;
  179. unsigned int mNumWeights;
  180. float *mVertices; /* Vertices of the model */
  181. psk_vtxw_t *mVTXWs; /* UV Wedges */
  182. psk_face_t *mFaces; /* The triangle mesh */
  183. psk_material_t *mMaterials; /* Materials/textures */
  184. psk_bone_t *mBones; /* The bones of the model */
  185. psk_weight_t *mWeights; /* The weights of the bones */
  186. private:
  187. ////////////////////////////////////////////////////////////
  188. // Private Accessors
  189. ////////////////////////////////////////////////////////////
  190. ////////////////////////////////////////////////////////////
  191. // Private Mutators
  192. ////////////////////////////////////////////////////////////
  193. };
  194. //////////////////////////////////////////////////////////////////////
  195. // PSAAnimation Class
  196. //////////////////////////////////////////////////////////////////////
  197. class PSAAnimation
  198. {
  199. public:
  200. enum PSKModelRendererFlag
  201. {
  202. fReserved1 = 1,
  203. fReserved2 = 2,
  204. fDebugBones = 4,
  205. fDebugAnimInfos = 8,
  206. fDebugKeyFrames = 16
  207. };
  208. ////////////////////////////////////////////////////////////
  209. // Constructors
  210. ////////////////////////////////////////////////////////////
  211. PSAAnimation();
  212. /*------------------------------------------------------
  213. * Pre :
  214. * Post : Constructs an object of PSAAnimation
  215. *
  216. *-- History ------------------------------------------
  217. *
  218. * 2003.06.11:
  219. * Mongoose - Created
  220. ------------------------------------------------------*/
  221. ~PSAAnimation();
  222. /*------------------------------------------------------
  223. * Pre : PSAAnimation object is allocated
  224. * Post : Deconstructs an object of PSAAnimation
  225. *
  226. *-- History ------------------------------------------
  227. *
  228. * 2003.06.11:
  229. * Mongoose - Created
  230. ------------------------------------------------------*/
  231. ////////////////////////////////////////////////////////////
  232. // Public Accessors
  233. ////////////////////////////////////////////////////////////
  234. int load(char *filename);
  235. /*------------------------------------------------------
  236. * Pre :
  237. * Post : Loads PSA animation from disk
  238. *
  239. * Returns < 0 on error
  240. *
  241. *-- History ------------------------------------------
  242. *
  243. * 2003.01.06:
  244. * Mongoose - Created
  245. ------------------------------------------------------*/
  246. ////////////////////////////////////////////////////////////
  247. // Public Mutators
  248. ////////////////////////////////////////////////////////////
  249. unsigned int mFlags;
  250. unsigned int mNumFrames;
  251. unsigned int mNumBones;
  252. unsigned int mNumAnimInfos;
  253. unsigned int mNumKeyFrames;
  254. psk_bone_t *mBones;
  255. psa_anim_info_t *mAnimInfos;
  256. psa_key_frame_t *mKeyFrames;
  257. private:
  258. ////////////////////////////////////////////////////////////
  259. // Private Accessors
  260. ////////////////////////////////////////////////////////////
  261. ////////////////////////////////////////////////////////////
  262. // Private Mutators
  263. ////////////////////////////////////////////////////////////
  264. };
  265. //////////////////////////////////////////////////////////////////////
  266. // PSKModelRenderer Class
  267. //////////////////////////////////////////////////////////////////////
  268. class PSKModelRenderer
  269. {
  270. public:
  271. enum PSKModelRendererFlag
  272. {
  273. fRenderFaces = 1,
  274. fRenderTexture = 2,
  275. fRenderPoints = 4,
  276. fRenderBones = 8,
  277. fConvertEuler = 16,
  278. fDebugFaceRender = 32
  279. };
  280. ////////////////////////////////////////////////////////////
  281. // Constructors
  282. ////////////////////////////////////////////////////////////
  283. PSKModelRenderer();
  284. /*------------------------------------------------------
  285. * Pre :
  286. * Post : Constructs an object of PSKModelRenderer
  287. *
  288. *-- History ------------------------------------------
  289. *
  290. * 2003.01.06:
  291. * Mongoose - Created
  292. ------------------------------------------------------*/
  293. ~PSKModelRenderer();
  294. /*------------------------------------------------------
  295. * Pre : PSKModelRenderer object is allocated
  296. * Post : Deconstructs an object of PSKModelRenderer
  297. *
  298. *-- History ------------------------------------------
  299. *
  300. * 2003.01.06:
  301. * Mongoose - Created
  302. ------------------------------------------------------*/
  303. ////////////////////////////////////////////////////////////
  304. // Public Accessors
  305. ////////////////////////////////////////////////////////////
  306. void render();
  307. /*------------------------------------------------------
  308. * Pre :
  309. * Post : Renders PSK model in OpenGL
  310. *
  311. *-- History ------------------------------------------
  312. *
  313. * 2003.01.06:
  314. * Mongoose - Created
  315. ------------------------------------------------------*/
  316. void renderBone(unsigned int id);
  317. /*------------------------------------------------------
  318. * Pre :
  319. * Post : Renders PSK model's bone in OpenGL,
  320. * ( Recursive calling )
  321. *
  322. *-- History ------------------------------------------
  323. *
  324. * 2003.01.06:
  325. * Mongoose - Created, from nonpublic render()
  326. ------------------------------------------------------*/
  327. ////////////////////////////////////////////////////////////
  328. // Public Mutators
  329. ////////////////////////////////////////////////////////////
  330. void convertBoneAngles();
  331. /*------------------------------------------------------
  332. * Pre :
  333. * Post : Converts bone angles for rendering use
  334. *
  335. *-- History ------------------------------------------
  336. *
  337. * 2003.06.10:
  338. * Mongoose - Created
  339. ------------------------------------------------------*/
  340. void convertBoneAnglesPSA(unsigned int frame);
  341. /*------------------------------------------------------
  342. * Pre :
  343. * Post : Converts PSA bone angles for rendering use
  344. *
  345. *-- History ------------------------------------------
  346. *
  347. * 2003.06.10:
  348. * Mongoose - Created
  349. ------------------------------------------------------*/
  350. void copyVertices();
  351. /*------------------------------------------------------
  352. * Pre :
  353. * Post : Resets vertices to match PSKModel's default
  354. *
  355. *-- History ------------------------------------------
  356. *
  357. * 2003.06.10:
  358. * Mongoose - Created
  359. ------------------------------------------------------*/
  360. void setAnimation(PSAAnimation *anim);
  361. /*------------------------------------------------------
  362. * Pre :
  363. * Post : Sets PSA animation to render, and sets up cache
  364. *
  365. *-- History ------------------------------------------
  366. *
  367. * 2003.06.11:
  368. * Mongoose - Created
  369. ------------------------------------------------------*/
  370. void setModel(PSKModel *model);
  371. /*------------------------------------------------------
  372. * Pre :
  373. * Post : Sets PSK model to render, and sets up cache
  374. *
  375. *-- History ------------------------------------------
  376. *
  377. * 2003.06.10:
  378. * Mongoose - Created
  379. ------------------------------------------------------*/
  380. void setupRestMatrices(unsigned int id);
  381. /*------------------------------------------------------
  382. * Pre : <Id> the bone to setup matching invert matrix
  383. *
  384. * Post : Generates inverted matrices to render deformed
  385. * mesh by recursive call from root bone
  386. *
  387. * OpenGL accelerated where avalibable
  388. *
  389. *-- History ------------------------------------------
  390. *
  391. * 2003.07.07:
  392. * Mongoose - Created, was boneTransforms
  393. ------------------------------------------------------*/
  394. void setupWorldMatrices(unsigned int id);
  395. /*------------------------------------------------------
  396. * Pre : <Id> the bone to setup matching transform matrix
  397. *
  398. * Post : Generates transform matrices to render deformed
  399. * mesh by recursive call from root bone
  400. *
  401. *-- History ------------------------------------------
  402. *
  403. * 2003.06.10:
  404. * Mongoose - Created, was boneTransforms
  405. ------------------------------------------------------*/
  406. void transformVertices();
  407. /*------------------------------------------------------
  408. * Pre :
  409. * Post : Transforms vertices to deformed mesh for
  410. * current bone frame
  411. *
  412. *-- History ------------------------------------------
  413. *
  414. * 2003.06.10:
  415. * Mongoose - Created
  416. ------------------------------------------------------*/
  417. unsigned int mFlags;
  418. int mTextures[8]; /* Texture Ids of loaded materials */
  419. unsigned int mAnimationFrame; /* Used to keep up with animation
  420. frame externally,
  421. And updated internally
  422. Should be moved to
  423. private+acessor method
  424. */
  425. private:
  426. ////////////////////////////////////////////////////////////
  427. // Private Accessors
  428. ////////////////////////////////////////////////////////////
  429. ////////////////////////////////////////////////////////////
  430. // Private Mutators
  431. ////////////////////////////////////////////////////////////
  432. float *mBoneRotationCache; /* Cache of the computed axis angles */
  433. float *mVertexTransformCache; /* Cache of vertex transforms */
  434. float **mInvertedMatrices; /* Cache of computed inverted
  435. bone transform matrices for the
  436. vertices at rest position */
  437. float **mWorldMatrices;
  438. unsigned int mNumMatrices;
  439. /* Simulate inheritence here, cheesy waste */
  440. unsigned int mNumFrames;
  441. unsigned int mNumVertices;
  442. unsigned int mNumFaces;
  443. unsigned int mNumVTXWs;
  444. unsigned int mNumMaterials;
  445. unsigned int mNumBones;
  446. unsigned int mNumWeights;
  447. PSKModel *mModel; /* Current PSK model to render */
  448. PSAAnimation *mAnimation; /* Current PSA anim to render */
  449. psk_vtxw_t *mVTXWs; /* UV Wedges */
  450. psk_face_t *mFaces; /* The triangle mesh */
  451. psk_material_t *mMaterials; /* Materials/textures */
  452. psk_bone_t *mBones; /* The bones of the model */
  453. psk_weight_t *mWeights; /* The weights of the bones */
  454. };
  455. #endif