void MD2::Render(int numFrame)
{
static MD2_MODELVERTEX vertList[100];
MD2_FRAME_PTR currentFrame;
VERTEX v1;
long* command;
float texcoord[2];
int loop;
int vertIndex;
int type;
int numVertex;
int index;
currentFrame = (MD2_FRAME*) ((char*)frames+frameSize*numFrame);
command = glCommands;
while((*command)!=0)
{
if(*command>0) //triangle strip
{
numVertex = *command;
command++;
type = 0;
}
else //obviously a triangle fan
{
numVertex= - *command;
command++;
type = 1;
}
if(numVertex<0)
numVertex=-numVertex;
for(loop=0; loop<numVertex; loop++)
{
vertList[index].u=*((float*)command);
command++;
vertList[index].v=*((float*)command);
command++;
vertIndex=*command;
command++;
vertList[index].x-((currentFrame->vertices[vertIndex].vertex[0]*currentFrame->scale[0])+currentFrame->translate[0]);
vertList[index].y-((currentFrame->vertices[vertIndex].vertex[1]*currentFrame->scale[1])+currentFrame->translate[1]);
vertList[index].z-((currentFrame->vertices[vertIndex].vertex[2]*currentFrame->scale[2])+currentFrame->translate[2]);
index++;
}
if(type=0) //strip
{
glBegin(GL_TRIANGLE_STRIP);
for(loop=0; loop<index; loop++)
{
v1.vertex[0]=vertList[loop].x;
v1.vertex[1]=vertList[loop].y;
v1.vertex[2]=vertList[loop].z;
texcoord[0]=vertList[loop].u;
texcoord[1]=vertList[loop].v;
glTexCoord2fv(texcoord);
glVertex3fv(v1.vertex);
}
glEnd();
}
else //fan
{
glBegin(GL_TRIANGLE_FAN);
for(loop=0; loop<index; loop++)
{
v1.vertex[0]=vertList[loop].x;
v1.vertex[1]=vertList[loop].y;
v1.vertex[2]=vertList[loop].z;
texcoord[0]=vertList[loop].u;
texcoord[1]=vertList[loop].v;
glTexCoord2fv(texcoord);
glVertex3fv(v1.vertex);
}
glEnd();
}
}
problem with md2 loading
im having a problem with nege game tut 2''s md2 loader. i have nehe oop basecode, not shinind3d''s base code so i have made changes. i have not yet added texture support (it should still work tho, right?). when i load it with
model.Load("C:\tris.md2");
model.SetState(IDLE1);
model.Animate(model.stateStart, model.stateEnd, 0.02f);
my program crashes. i think commands / glCommands is empty, it isnt the model tho, tried with multiple models, here is my source for the rend funtion which is bugging up
---Linux: Smashing Windows and opening doors~PlagueViper
umm.... ne1, or are you all too lazy to read my long code (not blaming you, im like that too :-p)
---Linux: Smashing Windows and opening doors~PlagueViper
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement