19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
struct md2_frame {
float scale[3];
float translate[3];
char name[16];
md2_vertex vertices[1];
};
@implementation MD2 {
int _numGlCommands;
int *_glCommands;
int _numTriangles;
int _frameSize;
int _numFrames;
|
>
>
>
>
>
>
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
struct md2_frame {
float scale[3];
float translate[3];
char name[16];
md2_vertex vertices[1];
};
static float
snap(int sn, float f)
{
return sn ? (float)(((int)(f + sn * 0.5f)) & (~(sn - 1))) : f;
}
@implementation MD2 {
int _numGlCommands;
int *_glCommands;
int _numTriangles;
int _frameSize;
int _numFrames;
|
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
|
_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)scaleWithFrame:(int)frame scale:(float)scale snap:(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)renderWithLight:(OFVector3D &)light
frame:(int)frame
range:(int)range
x:(float)x
y:(float)y
z:(float)z
yaw:(float)yaw
pitch:(float)pitch
|
<
<
<
<
<
<
|
|
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
|
_mverts = new OFVector3D *[_numFrames];
loopj(_numFrames) _mverts[j] = NULL;
return true;
}
}
- (void)scaleWithFrame:(int)frame scale:(float)scale snap:(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)renderWithLight:(OFVector3D)light
frame:(int)frame
range:(int)range
x:(float)x
y:(float)y
z:(float)z
yaw:(float)yaw
pitch:(float)pitch
|