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
|
int numGlCommands;
int *glCommands;
int numTriangles;
int frameSize;
int numFrames;
int numVerts;
char *frames;
vec **mverts;
int displaylist;
int displaylistverts;
mapmodelinfo mmi;
char *loadname;
int mdlnum;
bool loaded;
bool load(char *filename);
void render(vec &light, int numFrame, int range, float x, float y,
float z, float yaw, float pitch, float scale, float speed, int snap,
int basetime);
void scale(int frame, float scale, int sn);
md2()
: numGlCommands(0), frameSize(0), numFrames(0), displaylist(0),
loaded(false) {};
~md2()
|
|
|
|
|
|
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
|
int numGlCommands;
int *glCommands;
int numTriangles;
int frameSize;
int numFrames;
int numVerts;
char *frames;
OFVector3D **mverts;
int displaylist;
int displaylistverts;
mapmodelinfo mmi;
char *loadname;
int mdlnum;
bool loaded;
bool load(char *filename);
void render(OFVector3D &light, int numFrame, int range, float x,
float y, float z, float yaw, float pitch, float scale, float speed,
int snap, int basetime);
void scale(int frame, float scale, int sn);
md2()
: numGlCommands(0), frameSize(0), numFrames(0), displaylist(0),
loaded(false) {};
~md2()
|
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
|
numGlCommands = header.numGlCommands;
frameSize = header.frameSize;
numTriangles = header.numTriangles;
numVerts = header.numVertices;
fclose(file);
mverts = new vec *[numFrames];
loopj(numFrames) mverts[j] = NULL;
return true;
};
float
snap(int sn, float f)
{
return sn ? (float)(((int)(f + sn * 0.5f)) & (~(sn - 1))) : f;
};
void
md2::scale(int frame, float scale, int sn)
{
mverts[frame] = new vec[numVerts];
md2_frame *cf = (md2_frame *)((char *)frames + frameSize * frame);
float sc = 16.0f / scale;
loop(vi, numVerts)
{
uchar *cv = (uchar *)&cf->vertices[vi].vertex;
vec *v = &(mverts[frame])[vi];
v->x = (snap(sn, cv[0] * cf->scale[0]) + cf->translate[0]) / sc;
v->y =
-(snap(sn, cv[1] * cf->scale[1]) + cf->translate[1]) / sc;
v->z = (snap(sn, cv[2] * cf->scale[2]) + cf->translate[2]) / sc;
};
};
void
md2::render(vec &light, int frame, int range, float x, float y, float z,
float yaw, float pitch, float sc, float speed, int snap, int basetime)
{
loopi(range) if (!mverts[frame + i]) scale(frame + i, sc, snap);
glPushMatrix();
glTranslatef(x, y, z);
glRotatef(yaw + 180, 0, -1, 0);
|
|
|
|
|
|
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
|
numGlCommands = header.numGlCommands;
frameSize = header.frameSize;
numTriangles = header.numTriangles;
numVerts = header.numVertices;
fclose(file);
mverts = new OFVector3D *[numFrames];
loopj(numFrames) mverts[j] = NULL;
return true;
};
float
snap(int sn, float f)
{
return sn ? (float)(((int)(f + sn * 0.5f)) & (~(sn - 1))) : f;
};
void
md2::scale(int frame, float scale, int sn)
{
mverts[frame] = new OFVector3D[numVerts];
md2_frame *cf = (md2_frame *)((char *)frames + frameSize * frame);
float sc = 16.0f / scale;
loop(vi, numVerts)
{
uchar *cv = (uchar *)&cf->vertices[vi].vertex;
OFVector3D *v = &(mverts[frame])[vi];
v->x = (snap(sn, cv[0] * cf->scale[0]) + cf->translate[0]) / sc;
v->y =
-(snap(sn, cv[1] * cf->scale[1]) + cf->translate[1]) / sc;
v->z = (snap(sn, cv[2] * cf->scale[2]) + cf->translate[2]) / sc;
};
};
void
md2::render(OFVector3D &light, int frame, int range, float x, float y, float z,
float yaw, float pitch, float sc, float speed, int snap, int basetime)
{
loopi(range) if (!mverts[frame + i]) scale(frame + i, sc, snap);
glPushMatrix();
glTranslatef(x, y, z);
glRotatef(yaw + 180, 0, -1, 0);
|
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
|
int fr1 = (int)(time / speed);
float frac1 = (time - fr1 * speed) / speed;
float frac2 = 1 - frac1;
fr1 = fr1 % range + frame;
int fr2 = fr1 + 1;
if (fr2 >= frame + range)
fr2 = frame;
vec *verts1 = mverts[fr1];
vec *verts2 = mverts[fr2];
for (int *command = glCommands; (*command) != 0;) {
int numVertex = *command++;
if (numVertex > 0) {
glBegin(GL_TRIANGLE_STRIP);
} else {
glBegin(GL_TRIANGLE_FAN);
numVertex = -numVertex;
};
loopi(numVertex)
{
float tu = *((float *)command++);
float tv = *((float *)command++);
glTexCoord2f(tu, tv);
int vn = *command++;
vec &v1 = verts1[vn];
vec &v2 = verts2[vn];
#define ip(c) v1.c *frac2 + v2.c *frac1
glVertex3f(ip(x), ip(z), ip(y));
};
xtraverts += numVertex;
glEnd();
|
|
|
|
|
|
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
|
int fr1 = (int)(time / speed);
float frac1 = (time - fr1 * speed) / speed;
float frac2 = 1 - frac1;
fr1 = fr1 % range + frame;
int fr2 = fr1 + 1;
if (fr2 >= frame + range)
fr2 = frame;
OFVector3D *verts1 = mverts[fr1];
OFVector3D *verts2 = mverts[fr2];
for (int *command = glCommands; (*command) != 0;) {
int numVertex = *command++;
if (numVertex > 0) {
glBegin(GL_TRIANGLE_STRIP);
} else {
glBegin(GL_TRIANGLE_FAN);
numVertex = -numVertex;
};
loopi(numVertex)
{
float tu = *((float *)command++);
float tv = *((float *)command++);
glTexCoord2f(tu, tv);
int vn = *command++;
OFVector3D &v1 = verts1[vn];
OFVector3D &v2 = verts2[vn];
#define ip(c) v1.c *frac2 + v2.c *frac1
glVertex3f(ip(x), ip(z), ip(y));
};
xtraverts += numVertex;
glEnd();
|
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
int xs, ys;
glBindTexture(GL_TEXTURE_2D,
tex ? lookuptexture(tex, xs, ys) : FIRSTMDL + m->mdlnum);
int ix = (int)x;
int iy = (int)z;
vec light = {1.0f, 1.0f, 1.0f};
if (!OUTBORD(ix, iy)) {
sqr *s = S(ix, iy);
float ll = 256.0f; // 0.96f;
float of = 0.0f; // 0.1f;
light.x = s->r / ll + of;
light.y = s->g / ll + of;
|
|
|
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
int xs, ys;
glBindTexture(GL_TEXTURE_2D,
tex ? lookuptexture(tex, xs, ys) : FIRSTMDL + m->mdlnum);
int ix = (int)x;
int iy = (int)z;
OFVector3D light = OFMakeVector3D(1, 1, 1);
if (!OUTBORD(ix, iy)) {
sqr *s = S(ix, iy);
float ll = 256.0f; // 0.96f;
float of = 0.0f; // 0.1f;
light.x = s->r / ll + of;
light.y = s->g / ll + of;
|