Clone of Akilla's ac2d @ https://github.com/deregtd/AC2D

cModel.h 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #pragma once
  2. #include "cPoint3D.h"
  3. #include "cByteStream.h"
  4. class cACTriFan {
  5. public:
  6. cACTriFan()
  7. {
  8. bUVs = NULL;
  9. wVerts = NULL;
  10. }
  11. ~cACTriFan()
  12. {
  13. delete []wVerts;
  14. delete []bUVs;
  15. }
  16. void Unpack(cByteStream *pBS)
  17. {
  18. bNumVerts = pBS->ReadByte();
  19. bType = pBS->ReadByte();
  20. DWORD unknown = pBS->ReadDWORD();
  21. wTexNum = pBS->ReadWORD();
  22. WORD unknown2 = pBS->ReadWORD();
  23. wVerts = new WORD[bNumVerts];
  24. for (int i=0; i<bNumVerts; i++)
  25. wVerts[i] = pBS->ReadWORD();
  26. if (bType == 4)
  27. {
  28. // Some sort of lighting/partitioning poly
  29. }
  30. else
  31. {
  32. bUVs = new BYTE[bNumVerts];
  33. for (int i=0; i<bNumVerts; i++)
  34. bUVs[i] = pBS->ReadByte();
  35. if (unknown == 2)
  36. {
  37. //???
  38. //Added for model 0x0100326E... No idea what this is, but it seems to work...
  39. for (unsigned int j = 0; j < bNumVerts; j++)
  40. pBS->ReadByte();
  41. }
  42. }
  43. }
  44. BYTE bType;
  45. WORD wTexNum;
  46. BYTE bNumVerts;
  47. WORD *wVerts;
  48. BYTE *bUVs;
  49. };
  50. struct stACUV {
  51. stACUV()
  52. {
  53. }
  54. stACUV(float nu, float nv)
  55. {
  56. u = nu;
  57. v = nv;
  58. }
  59. void Unpack(cByteStream *pBS)
  60. {
  61. u = pBS->ReadFloat();
  62. v = pBS->ReadFloat();
  63. }
  64. float u, v;
  65. };
  66. class cACVertex {
  67. public:
  68. cACVertex()
  69. {
  70. UVs = NULL;
  71. }
  72. ~cACVertex()
  73. {
  74. delete []UVs;
  75. }
  76. void Unpack(cByteStream *pBS)
  77. {
  78. wNumUVs = pBS->ReadWORD();
  79. x = pBS->ReadFloat();
  80. y = pBS->ReadFloat();
  81. z = pBS->ReadFloat();
  82. nx = pBS->ReadFloat();
  83. ny = pBS->ReadFloat();
  84. nz = pBS->ReadFloat();
  85. UVs = new stACUV[wNumUVs];
  86. for (int i=0; i<wNumUVs; i++)
  87. UVs[i].Unpack(pBS);
  88. }
  89. cPoint3D GetP3D()
  90. {
  91. return cPoint3D(x,y,z);
  92. }
  93. WORD wNumUVs;
  94. float x, y, z;
  95. float nx, ny, nz;
  96. stACUV *UVs;
  97. };
  98. class cACPreModel {
  99. public:
  100. cACPreModel()
  101. {
  102. m_Vertices = NULL;
  103. m_TriFans = NULL;
  104. m_bSwaps = false;
  105. vPaletteSwaps = NULL;
  106. }
  107. ~cACPreModel()
  108. {
  109. delete []m_Vertices;
  110. delete []m_TriFans;
  111. }
  112. std::vector<DWORD> m_Textures;
  113. int iNumVerts;
  114. cACVertex * m_Vertices;
  115. int iNumTriFans;
  116. cACTriFan * m_TriFans;
  117. //Swaps
  118. bool m_bSwaps;
  119. int iSwapModelNum;
  120. std::vector<stPaletteSwap> *vPaletteSwaps;
  121. std::vector<stTextureSwap> *vTextureSwaps;
  122. };
  123. struct renderTriangle
  124. {
  125. int pt[3];
  126. };
  127. struct stTexInfo {
  128. DWORD dwTexID;
  129. DWORD dwColor;
  130. };
  131. struct stTriSet {
  132. public:
  133. stTriSet()
  134. {
  135. pColorarray = NULL;
  136. pTriarray = NULL;
  137. pVertarray = NULL;
  138. pTexarray = NULL;
  139. }
  140. ~stTriSet()
  141. {
  142. delete []pColorarray;
  143. delete []pTriarray;
  144. delete []pVertarray;
  145. delete []pTexarray;
  146. }
  147. DWORD dwGLTex;
  148. int iTriCount;
  149. GLuint *pColorarray;
  150. GLuint *pTriarray;
  151. GLfloat *pVertarray;
  152. GLfloat *pTexarray;
  153. };
  154. class cModel {
  155. public:
  156. cModel();
  157. ~cModel();
  158. bool ReadModel(DWORD dwModel, int iModelNum = -1, std::vector<stPaletteSwap> *vPaletteSwaps = 0, std::vector<stTextureSwap> *vTextureSwaps = 0);
  159. bool ReadDungeonPart(DWORD dwDungeon, WORD wDungeonPart, std::vector<WORD> * v_Textures);
  160. bool ParsePreModel(cACPreModel * pModel);
  161. int Draw();
  162. void SetTranslation(cPoint3D Translation);
  163. void SetRotation(float Rot1, float Rot2, float Rot3, float Rot4);
  164. private:
  165. DWORD m_dwID;
  166. cPoint3D m_pTranslation;
  167. float m_fRotation[4];
  168. std::vector <stTriSet *> m_vTriSets;
  169. };