Advertisement Jump to content
Sign in to follow this  
RDG

Help interpolating MD2 models

This topic is 3711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!