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
|
void MD2_Model::Draw( int Attributes[], bool Which_Way )
{
///Get Frame indicies
int FrameIndex1 = StartFrame, FrameIndex2 = StartFrame;
int AnimationLength = EndFrame - StartFrame + 1;
vector<float> FramePos;
for ( int i = 0; i < AnimationLength; i++ )
FramePos.push_back( i * 1.f/AnimationLength );
for ( int i = 1; i < FramePos.size(); i++ )
if ( Time >= FramePos[i-1] and Time <= FramePos[i] )
{
FrameIndex1 = i - 1 + StartFrame;
FrameIndex2 = i + StartFrame;
}
if ( FrameIndex1 == FrameIndex2 )
FrameIndex1 = EndFrame;
MD2_Frame Frame1 = Frames[FrameIndex1], Frame2 = Frames[FrameIndex2];
///Get Fraction between the two frames
float Fraction = 0;
if ( AnimationLength > 0 )
Fraction = float(Time - FramePos[FrameIndex1 - StartFrame] )*AnimationLength;
///Draw
Skin.Bind();
/// Usual Way
if ( Which_Way )
{
glBegin(GL_TRIANGLES);
for ( int i = 0; i < Header.num_tris; i++ )
{
MD2_Triangle Triangle = Triangles[i];
for ( int j = 0; j < 3; j++ )
{
MD2_Vertex V1 = Frame1.Vertices[ Triangle.VertexIndex[j] ];
MD2_Vertex V2 = Frame2.Vertices[ Triangle.VertexIndex[j] ];
vec3 Pos = V1.Pos * (1.f-Fraction) + V2.Pos * Fraction;
vec3 Norm = V1.Norm * (1.f-Fraction) + V2.Norm * Fraction;
MD2_TextureCoord Coord = TexCoords[ Triangle.TextureIndex[j] ];
glVertexAttrib3f( Attributes[0], Pos[0], Pos[1], Pos[2] ); ///Position
glVertexAttrib4f( Attributes[1], 1, 1, 1, 1 ); ///Color
glVertexAttrib2f( Attributes[2], Coord.gl_X, Coord.gl_Y ); ///TexCoord
glVertexAttrib3f( Attributes[3], Norm[0], Norm[1], Norm[2] ); ///Normal
}
}
glEnd();
}
///Using file's commands
else
{
for ( int i = 0; i < Groups.size(); i++ )
{
MD2_CommandGroup Group = Groups[i];
if ( Group.Size > 0 )
glBegin( GL_TRIANGLE_STRIP );
else
glBegin( GL_TRIANGLE_FAN );
for ( int j = 0; j < fabs(Group.Size); j++ )
{
MD2_glCommand Command = Group.Commands[j];
MD2_Vertex V1 = Frame1.Vertices[ Command.VertexIndex ];
MD2_Vertex V2 = Frame2.Vertices[ Command.VertexIndex ];
vec3 Pos = V1.Pos * (1.f-Fraction) + V2.Pos * Fraction;
vec3 Norm = V1.Norm * (1.f-Fraction) + V2.Norm * Fraction;
glVertexAttrib3f( Attributes[0], Pos[0], Pos[1], Pos[2] ); ///Position
glVertexAttrib4f( Attributes[1], 1, 1, 1, 1 ); ///Color
glVertexAttrib2f( Attributes[2], Command.s, Command.t ); ///TexCoord
glVertexAttrib3f( Attributes[3], Norm[0], Norm[1], Norm[2] ); ///Normal
}
glEnd();
}
}
Skin.UnBind();
}
|