Skip to main content
gamedev.net
🔒 Locked

Help interpolating MD2 models

Started by RDG Nov 18, 2008 at 4:14 PM 0 replies 500+ views
Original Post
RDG
RDG
How can I interpolate a model if I have the two frames which I will be interpolating and am using glcommands to render the model? Here's the current render code:
void MD2Model::render()
{
	int i;
	vec3f v;
	int *pglCommands;
	MD2Frame *pframe;
	MD2Vertex *pvert;
	MD2GLCommand *packet;
	
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, this->textureID);
	
        //-------------------
        //Calculate frames
        //-------------------

	int frameIndexOne = (int)(this->time * (this->endFrame - this->startFrame + 1)) + this->startFrame; 
	if (frameIndexOne > this->endFrame)
	{
		frameIndexOne = this->startFrame;
	}
	
	int frameIndexTwo;
	if (frameIndexOne < this->endFrame)
	{
		frameIndexTwo = frameIndexOne + 1;
	} else {
		frameIndexTwo = this->startFrame;
	}
	
	MD2Frame *frameOne = this->frames + frameIndexOne;
	MD2Frame *frameTwo = this->frames + frameIndexTwo;
	
        //------------------
        //------------------
        //------------------

	float frac = (time - (float)(frameIndexOne - this->startFrame) / (float)(this->endFrame - this->startFrame + 1)) * (this->endFrame - this->startFrame + 1);
	
	pglCommands = this->glCommands;
	while ((i = *(pglCommands++)) != 0)
	{
		if (i < 0)
		{
			glBegin(GL_TRIANGLE_FAN);
			i = -i;
		} else {
			glBegin(GL_TRIANGLE_STRIP);
		}
		
		for (/*Nothing*/; i > 0; --i, pglCommands += 3)
		{
			packet = (MD2GLCommand *)pglCommands;
			
			pframe = &this->frames[this->startFrame];
			pvert = &pframe->verts[packet->index];
			
			glTexCoord2f(packet->s, packet->t);
			glNormal3fv(anormsTable[pvert->normalIndex]);
			
			v[0] = (pframe->scale[0] * pvert->coords[0]) + pframe->translate[0];
			v[1] = (pframe->scale[1] * pvert->coords[1]) + pframe->translate[1];
			v[2] = (pframe->scale[2] * pvert->coords[2]) + pframe->translate[2];
			
			glVertex3fv(v);
		}
		
		glEnd();
	}
	
	glDisable(GL_TEXTURE_2D);
}


As you can see, I don't use frameOne and frameTwo in the rendering portion of the code, I just calculated them. How can I calculate interpolation using these frames? All the tutorials on interpolation I've seen don't use glcommands. Any help will be appreciated

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.