00001
00002 #ifndef MODEL_H
00003 #define MODEL_H
00004
00005 #include "newcoll.h"
00006
00007
00008
00009 #define MODEL_PLAIN 0
00010 #define MODEL_FOG 1
00011 #define MODEL_LIT 2
00012 #define MODEL_ENV 4
00013 #define MODEL_DONOTCLIP 8
00014 #define MODEL_MIRROR 16
00015 #define MODEL_GHOST 32
00016 #define MODEL_GLARE 64
00017 #define MODEL_USENEWVERTS 128
00018 #define MODEL_ADDLIT 256
00019 #define MODEL_SCALE 512
00020
00021 #define LOADMODEL_FORCE_TPAGE 1
00022 #define LOADMODEL_OFFSET_TPAGE 2
00023
00024 #define MAX_LEVEL_MODELS 64
00025
00026 enum {
00027 LEVEL_MODEL_BARREL,
00028 LEVEL_MODEL_BEACHBALL,
00029 LEVEL_MODEL_MERCURY,
00030 LEVEL_MODEL_VENUS,
00031 LEVEL_MODEL_EARTH,
00032 LEVEL_MODEL_MARS,
00033 LEVEL_MODEL_JUPITER,
00034 LEVEL_MODEL_SATURN,
00035 LEVEL_MODEL_URANUS,
00036 LEVEL_MODEL_NEPTUNE,
00037 LEVEL_MODEL_PLUTO,
00038 LEVEL_MODEL_MOON,
00039 LEVEL_MODEL_RINGS,
00040 LEVEL_MODEL_PLANE,
00041 LEVEL_MODEL_PLANE_PROPELLOR,
00042 LEVEL_MODEL_COPTER,
00043 LEVEL_MODEL_COPTER_BLADE1,
00044 LEVEL_MODEL_COPTER_BLADE2,
00045 LEVEL_MODEL_DRAGON1,
00046 LEVEL_MODEL_DRAGON2,
00047 LEVEL_MODEL_WATER,
00048 LEVEL_MODEL_BOAT1,
00049 LEVEL_MODEL_BOAT2,
00050 LEVEL_MODEL_SPEEDUP,
00051 LEVEL_MODEL_RADAR,
00052 LEVEL_MODEL_BALLOON,
00053 LEVEL_MODEL_HORSE,
00054 LEVEL_MODEL_TRAIN,
00055 LEVEL_MODEL_TRAIN2,
00056 LEVEL_MODEL_TRAIN3,
00057 LEVEL_MODEL_LIGHT1,
00058 LEVEL_MODEL_LIGHT2,
00059 LEVEL_MODEL_FOOTBALL,
00060 LEVEL_MODEL_SPACEMAN,
00061 LEVEL_MODEL_PICKUP,
00062 LEVEL_MODEL_FLAP,
00063 LEVEL_MODEL_LASER,
00064 LEVEL_MODEL_FIREWORK,
00065 LEVEL_MODEL_CHROMEBALL,
00066 LEVEL_MODEL_WATERBOMB,
00067 LEVEL_MODEL_BOMBBALL,
00068 };
00069
00070 #define ModelAddGouraud(_a, _b, _c) \
00071 { \
00072 long _i; \
00073 _i = (_b)[0] + (long)(_a)->r; \
00074 if (_i > 255) (_c)->r = 255; \
00075 else if (_i < 0) (_c)->r = 0; \
00076 else (_c)->r = (unsigned char)_i; \
00077 _i = (_b)[1] + (long)(_a)->g; \
00078 if (_i > 255) (_c)->g = 255; \
00079 else if (_i < 0) (_c)->g = 0; \
00080 else (_c)->g = (unsigned char)_i; \
00081 _i = (_b)[2] + (long)(_a)->b; \
00082 if (_i > 255) (_c)->b = 255; \
00083 else if (_i < 0) (_c)->b = 0; \
00084 else (_c)->b = (unsigned char)_i; \
00085 }
00086
00087 #define ModelAddGouraudAlpha(_a, _b, _c) \
00088 { \
00089 long _i; \
00090 _i = (_b)[0] + (long)(_a)->r; \
00091 if (_i > 255) (_c)->r = 255; \
00092 else if (_i < 0) (_c)->r = 0; \
00093 else (_c)->r = (unsigned char)_i; \
00094 _i = (_b)[1] + (long)(_a)->g; \
00095 if (_i > 255) (_c)->g = 255; \
00096 else if (_i < 0) (_c)->g = 0; \
00097 else (_c)->g = (unsigned char)_i; \
00098 _i = (_b)[2] + (long)(_a)->b; \
00099 if (_i > 255) (_c)->b = 255; \
00100 else if (_i < 0) (_c)->b = 0; \
00101 else (_c)->b = (unsigned char)_i; \
00102 (_c)->a = (_a)->a; \
00103 }
00104
00105 #define ModelChangeGouraud(c, p) \
00106 { \
00107 if (p != 100) \
00108 { \
00109 (c)->r = ((c)->r + 1) * p / 100; \
00110 (c)->g = ((c)->g + 1) * p / 100; \
00111 (c)->b = ((c)->b + 1) * p / 100; \
00112 } \
00113 }
00114
00115 #define REJECT_MODEL_ENV_POLY() \
00116 if (mp->Type & POLY_NOENV) continue
00117
00118 #define REJECT_MODEL_POLY() \
00119 { \
00120 if (!(mp->Type & POLY_DOUBLE)) if (Cull(mp->v0->sx, mp->v0->sy, mp->v1->sx, mp->v1->sy, mp->v2->sx, mp->v2->sy) > 0) continue; \
00121 }
00122
00123 #define REJECT_MODEL_POLY_MIRROR() \
00124 { \
00125 if (!(mp->Type & POLY_DOUBLE)) if (Cull(mp->v0->sx, mp->v0->sy, mp->v1->sx, mp->v1->sy, mp->v2->sx, mp->v2->sy) < 0) continue; \
00126 }
00127
00128 #define COPY_MODEL_TRI_COLOR(_v) \
00129 { \
00130 (_v)[0].color = *(long*)&mrgb->rgb[0]; \
00131 (_v)[1].color = *(long*)&mrgb->rgb[1]; \
00132 (_v)[2].color = *(long*)&mrgb->rgb[2]; \
00133 }
00134
00135 #define COPY_MODEL_QUAD_COLOR(_v) \
00136 { \
00137 (_v)[0].color = *(long*)&mrgb->rgb[0]; \
00138 (_v)[1].color = *(long*)&mrgb->rgb[1]; \
00139 (_v)[2].color = *(long*)&mrgb->rgb[2]; \
00140 (_v)[3].color = *(long*)&mrgb->rgb[3]; \
00141 }
00142
00143 #define COPY_MODEL_TRI_COLOR_LIT(_v) \
00144 { \
00145 ModelAddGouraudAlpha(&mrgb->rgb[0], &mp->v0->r, (MODEL_RGB*)&(_v)[0].color); \
00146 ModelAddGouraudAlpha(&mrgb->rgb[1], &mp->v1->r, (MODEL_RGB*)&(_v)[1].color); \
00147 ModelAddGouraudAlpha(&mrgb->rgb[2], &mp->v2->r, (MODEL_RGB*)&(_v)[2].color); \
00148 }
00149
00150 #define COPY_MODEL_QUAD_COLOR_LIT(_v) \
00151 { \
00152 ModelAddGouraudAlpha(&mrgb->rgb[0], &mp->v0->r, (MODEL_RGB*)&(_v)[0].color); \
00153 ModelAddGouraudAlpha(&mrgb->rgb[1], &mp->v1->r, (MODEL_RGB*)&(_v)[1].color); \
00154 ModelAddGouraudAlpha(&mrgb->rgb[2], &mp->v2->r, (MODEL_RGB*)&(_v)[2].color); \
00155 ModelAddGouraudAlpha(&mrgb->rgb[3], &mp->v3->r, (MODEL_RGB*)&(_v)[3].color); \
00156 }
00157
00158 #define COPY_MODEL_TRI_COLOR_GHOST(_v) \
00159 { \
00160 (_v)[0].color = *(long*)&mrgb->rgb[0] | mp->v0->a; \
00161 (_v)[1].color = *(long*)&mrgb->rgb[1] | mp->v1->a; \
00162 (_v)[2].color = *(long*)&mrgb->rgb[2] | mp->v2->a; \
00163 }
00164
00165 #define COPY_MODEL_QUAD_COLOR_GHOST(_v) \
00166 { \
00167 (_v)[0].color = *(long*)&mrgb->rgb[0] | mp->v0->a; \
00168 (_v)[1].color = *(long*)&mrgb->rgb[1] | mp->v1->a; \
00169 (_v)[2].color = *(long*)&mrgb->rgb[2] | mp->v2->a; \
00170 (_v)[3].color = *(long*)&mrgb->rgb[3] | mp->v3->a; \
00171 }
00172
00173
00174
00175 typedef struct {
00176 float x, y, z;
00177 float nx, ny, nz;
00178 } MODEL_VERTEX_LOAD;
00179
00180 typedef struct {
00181 short Type, Tpage;
00182 short vi0, vi1, vi2, vi3;
00183 long c0, c1, c2, c3;
00184 float u0, v0, u1, v1, u2, v2, u3, v3;
00185 } MODEL_POLY_LOAD;
00186
00187 typedef struct {
00188 unsigned char b, g, r, a;
00189 } MODEL_RGB;
00190
00191 typedef struct {
00192 MODEL_RGB rgb[4];
00193 } POLY_RGB;
00194
00195 typedef struct {
00196 float x, y, z;
00197 float x2, y2, z2;
00198 float nx, ny, nz;
00199 float sx, sy, sz, rhw;
00200 long color, specular;
00201 float tu, tv;
00202 long r, g, b, a;
00203 unsigned char Clip;
00204 unsigned char pad0, pad1, pad2;
00205 } MODEL_VERTEX;
00206
00207 typedef struct {
00208 float x, y, z;
00209 float nx, ny, nz;
00210 } MODEL_VERTEX_MORPH;
00211
00212 typedef struct {
00213 short Type, Tpage;
00214 float tu0, tv0;
00215 float tu1, tv1;
00216 float tu2, tv2;
00217 float tu3, tv3;
00218 MODEL_VERTEX *v0, *v1, *v2, *v3;
00219 } MODEL_POLY;
00220
00221 typedef struct {
00222 float Radius;
00223 float Xmin, Xmax;
00224 float Ymin, Ymax;
00225 float Zmin, Zmax;
00226 void *AllocPtr;
00227 short PolyNum, VertNum;
00228 short QuadNumTex, TriNumTex, QuadNumRGB, TriNumRGB;
00229 POLY_RGB *PolyRGB;
00230 MODEL_POLY *PolyPtr;
00231 MODEL_VERTEX *VertPtr;
00232 MODEL_VERTEX_MORPH *VertPtrMorph;
00233 } MODEL;
00234
00235 typedef struct {
00236 short PolyNum, VertNum;
00237 } MODEL_HEADER;
00238
00239 typedef struct {
00240 long ID, RefCount;
00241 MODEL Model;
00242
00243 COLLSKIN CollSkin;
00244 } LEVEL_MODEL;
00245
00246
00247
00248 extern long LoadModel(char *file, MODEL *m, char tpage, char prmlevel, char loadflag, long RgbPer);
00249 extern void FreeModel(MODEL *m, long prmlevel);
00250 extern void DrawModel(MODEL *m, MAT *worldmat, VEC *worldpos, short flag);
00251 extern void TransModelVertsFogClip(MODEL *m, MAT *mat, VEC *trans);
00252 extern void TransModelVertsPlainClip(MODEL *m, MAT *mat, VEC *trans);
00253 extern void TransModelVertsPlain(MODEL *m, MAT *mat, VEC *trans);
00254 extern void TransModelVertsFog(MODEL *m, MAT *mat, VEC *trans);
00255 extern void TransModelVertsFogClipNewVerts(MODEL *m, MAT *mat, VEC *trans);
00256 extern void TransModelVertsPlainClipNewVerts(MODEL *m, MAT *mat, VEC *trans);
00257 extern void TransModelVertsPlainNewVerts(MODEL *m, MAT *mat, VEC *trans);
00258 extern void TransModelVertsFogNewVerts(MODEL *m, MAT *mat, VEC *trans);
00259 extern void TransModelVertsMirror(MODEL *m, MAT *mat, VEC *trans, MAT *worldmat, VEC *worldpos);
00260 extern void TransModelVertsMirrorNewVerts(MODEL *m, MAT *mat, VEC *trans, MAT *worldmat, VEC *worldpos);
00261 extern void SetModelVertsEnvPlain(MODEL *m);
00262 extern void SetModelVertsEnvLit(MODEL *m);
00263 extern void SetModelVertsGhost(MODEL *m);
00264 extern void SetModelVertsGlare(MODEL *m, VEC *pos, MAT *mat, short flag);
00265 extern void DrawModelPolysClip(MODEL *m, long lit, long env);
00266 extern void DrawModelPolys(MODEL *m, long lit, long env);
00267 extern void DrawModelPolysMirror(MODEL *m, long lit);
00268 extern void SetEnvStatic(VEC *pos, MAT *mat, long rgb, float xoff, float yoff, float scale);
00269 extern void SetEnvActive(VEC *pos, MAT *mat, MAT *envmat, long rgb, float xoff, float yoff, float scale);
00270 extern void InitLevelModels(void);
00271 extern void FreeLevelModels(void);
00272 extern long LoadOneLevelModel(long id, long flag, struct renderflags renderflag, long tpage);
00273 extern void FreeOneLevelModel(long slot);
00274 extern void SetModelFrames(MODEL *model, char **files, long count);
00275 extern void SetModelMorph(MODEL *m, long frame1, long frame2, float time);
00276 extern void CheckModelMeshFx(MODEL *model, MAT *mat, VEC *pos, short *flag);
00277
00278
00279
00280 extern float ModelVertFog;
00281 extern short ModelPolyCount, ModelDrawnCount, EnvTpage;
00282 extern MAT EnvMatrix;
00283 extern MODEL_RGB EnvRgb;
00284 extern long ModelAddLit;
00285 extern REAL ModelScale;
00286 extern float GhostSineCount, GhostSinePos, GhostSineOffset;
00287 extern LEVEL_MODEL LevelModel[];
00288 extern MODEL *ModelMeshModel;
00289 extern MAT *ModelMeshMat;
00290 extern VEC *ModelMeshPos;
00291 extern short *ModelMeshFlag;
00292
00293 #endif