1 #if (USE_POLYMOST == 0)
2 #error Polymost not enabled.
3 #endif
4 #if (USE_OPENGL == 0)
5 #error OpenGL not enabled.
6 #endif
7 
8 #ifndef MDSPRITE_PRIV_H
9 #define MDSPRITE_PRIV_H
10 
11 typedef struct _mdskinmap_t
12 {
13 	unsigned char palette, filler[3]; // Build palette number
14 	int skinnum, surfnum;   // Skin identifier, surface number
15 	char *fn;   // Skin filename
16 	PTMHead *tex[HICEFFECTMASK+1];
17 	struct _mdskinmap_t *next;
18 } mdskinmap_t;
19 
20 typedef struct
21 {
22 	int mdnum; //VOX=1, MD2=2, MD3=3. NOTE: must be first in structure!
23 	int shadeoff;
24 	float scale, bscale, zadd;
25 } mdmodel;
26 
27 typedef struct _mdanim_t
28 {
29 	int startframe, endframe;
30 	int fpssc, flags;
31 	struct _mdanim_t *next;
32 } mdanim_t;
33 #define MDANIM_LOOP 0
34 #define MDANIM_ONESHOT 1
35 
36 
37 	//This MD2 code is based on the source code from David Henry (tfc_duke(at)hotmail.com)
38 	//   Was at http://tfc.duke.free.fr/us/tutorials/models/md2.htm
39 	//   Available from http://web.archive.org/web/20030816010242/http://tfc.duke.free.fr/us/tutorials/models/md2.htm
40 	//   Now at http://tfc.duke.free.fr/coding/md2.html (in French)
41 	//He probably wouldn't recognize it if he looked at it though :)
42 typedef struct { float x, y, z; } point3d;
43 
44 typedef struct
45 {
46 	int id, vers, skinxsiz, skinysiz, framebytes; //id:"IPD2", vers:8
47 	int numskins, numverts, numuv, numtris, numglcmds, numframes;
48 	int ofsskins, ofsuv, ofstris, ofsframes, ofsglcmds, ofseof; //ofsskins: skin names (64 bytes each)
49 } md2head_t;
50 
51 typedef struct { unsigned char v[3], ni; } md2vert_t; //compressed vertex coords (x,y,z), light normal index
52 typedef struct { short u, v; } md2uv_t;	//compressed texture coords
53 typedef struct { short ivert[3], iuv[3]; } md2tri_t;	//indices of vertices and tex coords for each point of a triangle
54 typedef struct
55 {
56 	point3d mul, add; //scale&translation vector
57 	char name[16];    //frame name
58 	md2vert_t verts[1]; //first vertex of this frame
59 } md2frame_t;
60 
61 typedef struct
62 {
63 		//common between mdmodel/voxmodel/md2model/md3model
64 	int mdnum; //VOX=1, MD2=2, MD3=3. NOTE: must be first in structure!
65 	int shadeoff;
66 	float scale, bscale, zadd;
67 
68 		//MD2 and MD3 share these
69 	PTMHead **tex;   // textures for base skin if no mappings defined
70 	int numframes, cframe, nframe, fpssc, usesalpha;
71 	float oldtime, curtime, interpol;
72 	mdanim_t *animations;
73 	mdskinmap_t *skinmap;
74 	int numskins, skinloaded;   // set to 1+numofskin when a skin is loaded and the tex coords are modified,
75 
76 		//MD2 specific stuff:
77 	int numverts, numuv, numtris, framebytes;
78 	int skinxsiz, skinysiz;
79 	char *frames;
80 	md2uv_t *uvs;
81 	md2tri_t *tris;
82 	char *basepath;   // pointer to string of base path
83 	char *skinfn;   // pointer to first of numskins 64-char strings
84 } md2model;
85 
86 
87 typedef struct { char nam[64]; int i; } md3shader_t; //ascz path of shader, shader index
88 typedef struct { int i[3]; } md3tri_t; //indices of tri
89 typedef struct { float u, v; } md3uv_t;
90 typedef struct { signed short x, y, z; unsigned char nlat, nlng; } md3xyzn_t; //xyz are [10:6] ints
91 
92 typedef struct
93 {
94 	point3d min, max, cen; //bounding box&origin
95 	float r; //radius of bounding sphere
96 	char nam[16]; //ascz frame name
97 } md3frame_t;
98 
99 typedef struct
100 {
101 	char nam[64]; //ascz tag name
102 	point3d p, x, y, z; //tag object pos&orient
103 } md3tag_t;
104 
105 typedef struct
106 {
107 	int id; //IDP3(0x33806873)
108 	char nam[64]; //ascz surface name
109 	int flags; //?
110 	int numframes, numshaders, numverts, numtris; //numframes same as md3head,max shade=~256,vert=~4096,tri=~8192
111 	md3tri_t *tris;       //file format: rel offs from md3surf
112 	md3shader_t *shaders; //file format: rel offs from md3surf
113 	md3uv_t *uv;          //file format: rel offs from md3surf
114 	md3xyzn_t *xyzn;      //file format: rel offs from md3surf
115 	int ofsend;
116 } md3surf_t;
117 
118 typedef struct
119 {
120 	int id; //IDP3(0x33806873)
121 	char nam[64]; //ascz surface name
122 	int flags; //?
123 	int numframes, numshaders, numverts, numtris; //numframes same as md3head,max shade=~256,vert=~4096,tri=~8192
124 	int tris;       //file format: rel offs from md3surf
125 	int shaders;    //file format: rel offs from md3surf
126 	int uv;         //file format: rel offs from md3surf
127 	int xyzn;       //file format: rel offs from md3surf
128 	int ofsend;
129 } md3filesurf_t;
130 
131 typedef struct
132 {
133 	int id, vers; //id=IDP3(0x33806873), vers=15
134 	char nam[64]; //ascz path in PK3
135 	int flags; //?
136 	int numframes, numtags, numsurfs, numskins; //max=~1024,~16,~32,numskins=artifact of MD2; use shader field instead
137 	md3frame_t *frames; //file format: abs offs
138 	md3tag_t *tags;     //file format: abs offs
139 	md3surf_t *surfs;   //file format: abs offs
140 	int eof;           //file format: abs offs
141 } md3head_t;
142 
143 typedef struct
144 {
145 	int id, vers; //id=IDP3(0x33806873), vers=15
146 	char nam[64]; //ascz path in PK3
147 	int flags; //?
148 	int numframes, numtags, numsurfs, numskins; //max=~1024,~16,~32,numskins=artifact of MD2; use shader field instead
149 	int frames; //file format: abs offs
150 	int tags;     //file format: abs offs
151 	int surfs;   //file format: abs offs
152 	int eof;           //file format: abs offs
153 } md3filehead_t;
154 
155 typedef struct
156 {
157 		//common between mdmodel/voxmodel/md2model/md3model
158 	int mdnum; //VOX=1, MD2=2, MD3=3. NOTE: must be first in structure!
159 	int shadeoff;
160 	float scale, bscale, zadd;
161 
162 		//MD2 and MD3 share these
163 	PTMHead **tex;   // textures for base skin if no mappings defined
164 	int numframes, cframe, nframe, fpssc, usesalpha;
165 	float oldtime, curtime, interpol;
166 	mdanim_t *animations;
167 	mdskinmap_t *skinmap;
168 	int numskins, skinloaded;   // set to 1+numofskin when a skin is loaded and the tex coords are modified,
169 
170 		//MD3 specific
171 	md3head_t head;
172 } md3model;
173 
174 typedef struct
175 { // maps build tiles to particular animation frames of a model
176 	int modelid;
177 	int skinnum;
178 	int framenum;   // calculate the number from the name when declaring
179 } tile2model_t;
180 extern tile2model_t tile2model[MAXTILES];
181 
182 typedef struct { float xadd, yadd, zadd; short angadd, flags; } hudtyp;
183 extern hudtyp hudmem[2][MAXTILES];
184 
185 #define VOXUSECHAR 0
186 #if (VOXUSECHAR != 0)
187 typedef struct { unsigned char x, y, z, u, v; } vert_t;
188 #else
189 typedef struct { unsigned short x, y, z, u, v; } vert_t;
190 #endif
191 typedef struct { vert_t v[4]; } voxrect_t;
192 typedef struct
193 {
194 		//common between mdmodel/voxmodel/md2model/md3model
195 	int mdnum; //VOX=1, MD2=2, MD3=3. NOTE: must be first in structure!
196 	int shadeoff;
197 	float scale, bscale, zadd;
198 
199 		//VOX specific stuff:
200 	GLuint *texid;	// skins for palettes
201 	voxrect_t *quad; int qcnt, qfacind[7];
202 	int *mytex, mytexx, mytexy;
203 	int xsiz, ysiz, zsiz;
204 	float xpiv, ypiv, zpiv;
205 	int is8bit;
206 
207 	GLuint vertexbuf;		// 4 per quad.
208 	GLuint indexbuf;		// 6 per quad (0, 1, 2, 0, 2, 3)
209 	unsigned int indexcount;
210 } voxmodel;
211 
212 extern voxmodel *voxmodels[MAXVOXELS];
213 extern mdmodel **models;
214 
215 extern char mdinited;
216 extern int mdtims, omdtims;
217 extern int nextmodelid;
218 
219 void freeallmodels (void);
220 void clearskins (void);
221 void voxfree (voxmodel *m);
222 voxmodel *voxload (const char *filnam);
223 int voxdraw (voxmodel *m, spritetype *tspr, int method);
224 
225 void mdinit (void);
226 PTMHead * mdloadskin (md2model *m, int number, int pal, int surf);
227 int mddraw (spritetype *, int method);
228 
229 #endif
230