-
Notifications
You must be signed in to change notification settings - Fork 1
/
model.h
221 lines (162 loc) · 3.75 KB
/
model.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#ifndef MODEL_H
#define MODEL_H
#include "vec3d.h"
class Model;
class Bone;
Vec3D fixCoordSystem(Vec3D v);
#include "manager.h"
#include "mpq.h"
#include "video.h"
#include "modelheaders.h"
#include "quaternion.h"
#include "matrix.h"
#include <vector>
#include "animated.h"
#include "particle.h"
class Bone {
Vec3D pivot;
int parent;
Animated<Vec3D> trans;
Animated<Quaternion> rot;
Animated<Vec3D> scale;
public:
bool billboard;
Matrix mat;
Matrix mrot;
bool calc;
void calcMatrix(Bone* allbones, int anim, int time);
void init(MPQFile &f, ModelBoneDef &b, int *global);
};
class TextureAnim {
Animated<Vec3D> trans, rot, scale;
public:
Vec3D tval, rval, sval;
void calc(int anim, int time);
void init(MPQFile &f, ModelTexAnimDef &mta, int *global);
void setup();
};
struct ModelColor {
Animated<Vec3D> color;
AnimatedShort opacity;
void init(MPQFile &f, ModelColorDef &mcd, int *global);
};
struct ModelTransparency {
AnimatedShort trans;
void init(MPQFile &f, ModelTransDef &mtd, int *global);
};
// copied from the .mdl docs? this might be completely wrong
enum BlendModes {
BM_OPAQUE,
BM_TRANSPARENT,
BM_ALPHA_BLEND,
BM_ADDITIVE,
BM_ADDITIVE_ALPHA,
BM_MODULATE
};
struct ModelRenderPass {
uint16 indexStart, indexCount, vertexStart, vertexEnd;
TextureID texture, texture2;
bool usetex2, useenvmap, cull, trans, unlit, nozwrite;
float p;
int16 texanim, color, opacity, blendmode;
int16 order;
bool init(Model *m);
void deinit();
bool operator< (const ModelRenderPass &m) const
{
//return !trans;
if (order<m.order) return true;
else if (order>m.order) return false;
else return blendmode == m.blendmode ? (p<m.p) : blendmode < m.blendmode;
}
};
struct ModelCamera {
bool ok;
Vec3D pos, target;
float nearclip, farclip, fov;
Animated<Vec3D> tPos, tTarget;
Animated<float> rot;
void init(MPQFile &f, ModelCameraDef &mcd, int *global);
void setup(int time=0);
ModelCamera():ok(false) {}
};
struct ModelLight {
int type, parent;
Vec3D pos, tpos, dir, tdir;
Animated<Vec3D> diffColor, ambColor;
Animated<float> diffIntensity, ambIntensity;
void init(MPQFile &f, ModelLightDef &mld, int *global);
void setup(int time, GLuint l);
};
class Model: public ManagedItem {
GLuint dlist;
GLuint vbuf, nbuf, tbuf;
size_t vbufsize;
bool animated;
bool animGeometry,animTextures,animBones;
bool forceAnim;
void init(MPQFile &f);
ModelHeader header;
TextureAnim *texanims;
ModelAnimation *anims;
int *globalSequences;
ModelColor *colors;
ModelTransparency *transparency;
ModelLight *lights;
ParticleSystem *particleSystems;
RibbonEmitter *ribbons;
void drawModel();
void initCommon(MPQFile &f);
bool isAnimated(MPQFile &f);
void initAnimated(MPQFile &f);
void initStatic(MPQFile &f);
ModelVertex *origVertices;
Vec3D *vertices, *normals;
uint16 *indices;
size_t nIndices;
std::vector<ModelRenderPass> passes;
void animate(int anim);
void calcBones(int anim, int time);
void lightsOn(GLuint lbase);
void lightsOff(GLuint lbase);
public:
ModelCamera cam;
Bone *bones;
TextureID *textures;
bool ok;
bool ind;
float rad;
float trans;
bool animcalc;
int anim, animtime;
Model(std::string name, bool forceAnim=false);
~Model();
void draw();
void updateEmitters(float dt);
friend struct ModelRenderPass;
};
class ModelManager: public SimpleManager {
public:
int add(std::string name);
ModelManager() : v(0) {}
int v;
void resetAnim();
void updateEmitters(float dt);
};
class ModelInstance {
public:
Model *model;
int id;
Vec3D pos, dir;
unsigned int d1, scale;
float frot,w,sc;
int light;
Vec3D ldir;
Vec3D lcol;
ModelInstance() {}
ModelInstance(Model *m, MPQFile &f);
void init2(Model *m, MPQFile &f);
void draw();
void draw2(const Vec3D& ofs, const float rot);
};
#endif