# md2 animation

## Recommended Posts

i tried posting in this topic http://www.gamedev.net/community/forums/topic.asp?topic_id=161374 but the access was denied so, i have the same problem can anybody post the solution to this problem? thanks in advance [Edited by - ComradeBG on November 7, 2006 8:17:34 AM]

bump =/

##### Share on other sites
ScottC    100
If your animation is "jumpy", then I would have to guess that you're not linearly interpolating between frames. Can you show some code?

##### Share on other sites
as far I understand from the topic in my first post the problem is in this function

float CLoadMD2::ReturnCurrentTime(t3DModel *pModel, int nextFrame){	static float elapsedTime   = 0.0f;	static float lastTime	  = 0.0f;	float time = (float)GetTickCount();        elapsedTime = time - lastTime;	float t = elapsedTime / (1000.0f / kAnimationSpeed);		if (elapsedTime >= (1000.0f / kAnimationSpeed) )	{		pModel->currentFrame = nextFrame;		lastTime = time;	}	return t;}

it works for a one md2 model, but when i import more than one the 1st model is ok with the animation but the others are animating in choppy way
the problem is that elapsedTime and lastTime are giving the times for one model and i have to have these 2 variables separate for every separate model
i tried to put them in the model structure info but it didn't work =/
hope you understood me

[Edited by - ComradeBG on November 7, 2006 7:58:53 AM]

##### Share on other sites
look at this video
now i think you will understand what's the problem ;)

[Edited by - ComradeBG on November 7, 2006 8:38:53 AM]

Odiee    100

##### Share on other sites
it will work up to 15 minutes i've just uploaded it
or try this http://rapidshare.com/files/2324061/md2anim.avi.html

[Edited by - ComradeBG on November 7, 2006 8:25:02 AM]

##### Share on other sites
GetTickCount - is this a windows call - from what I can recall it's not very accurate - +- 50ms I heard. You'll need a high res timer. This may explain choppiness

##### Share on other sites
Evil Steve    2017
Going by your code above, you're not interpolating between animation frames, you're just skipping from one frame to the next. What you should be doing is lerping the vertex positions between the two positions, so at the start of frame 0, the vertices are at the positions defined by frame 0, halfway through they're halfway between frame 0 and 1, etc.

##### Share on other sites
I am interpolating but in another function

void CLoadMD2::AnimateMD2Model(t3DModel *pModel){	if(pModel->pObject.size() <= 0) return;	tAnimationInfo *pAnim = &(pModel->pAnimations[pModel->currentAnim]);	int nextFrame = (pModel->currentFrame + 1) % pAnim->endFrame;	if(nextFrame == 0) 		nextFrame =  pAnim->startFrame;	t3DObject *pFrame =	&pModel->pObject[pModel->currentFrame];	t3DObject *pNextFrame =  &pModel->pObject[nextFrame];	t3DObject *pFirstFrame = &pModel->pObject[0];	float t = ReturnCurrentTime(pModel, nextFrame);	glBegin(GL_TRIANGLES);		for(int j = 0; j < pFrame->numOfFaces; j++)		{			for(int whichVertex = 0; whichVertex < 3; whichVertex++)			{				int vertIndex = pFirstFrame->pFaces[j].vertIndex[whichVertex];				int texIndex  = pFirstFrame->pFaces[j].coordIndex[whichVertex];										if(pFirstFrame->pTexVerts) 				{					glTexCoord2f(pFirstFrame->pTexVerts[ texIndex ].x, 								 pFirstFrame->pTexVerts[ texIndex ].y);				}				CVector3 vPoint1 = pFrame->pVerts[ vertIndex ];				CVector3 vPoint2 = pNextFrame->pVerts[ vertIndex ];				glVertex3f(vPoint1.x + t * (vPoint2.x - vPoint1.x), 						   vPoint1.y + t * (vPoint2.y - vPoint1.y), 						   vPoint1.z + t * (vPoint2.z - vPoint1.z));			}		}	glEnd();	}

the previous one just returns the time between frames

[Edited by - ComradeBG on November 7, 2006 7:29:50 AM]

##### Share on other sites
ScottC    100
Quote:
 Original post by Evil SteveGoing by your code above, you're not interpolating between animation frames, you're just skipping from one frame to the next. What you should be doing is lerping the vertex positions between the two positions, so at the start of frame 0, the vertices are at the positions defined by frame 0, halfway through they're halfway between frame 0 and 1, etc.

no he isn't.
	if (elapsedTime >= (1000.0f / kAnimationSpeed) )	{		pModel->currentFrame = nextFrame;		lastTime = time;	}

He only updates the frame every x amount of milliseconds

##### Share on other sites
Kalidor    1087
Quote:
 Original post by ComradeBG...the problem is that elapsedTime and lastTime are giving the times for one model and i have to have these 2 variables separate for every separate modeli tried to put them in the model structure info but it didn't work =/
What didn't work about it? How did you go about doing that? You're right that that is your problem (or at least one of them) since elapsedTime and lastTime are static variables of that function. In your current design they should be member variables of the class so that each instance has it's own elapsedTime and lastTime.

##### Share on other sites
Thanks for the replies guys, I solved this problem
but now it appeared another :
when I enable OpenGL lighting, the models' textures disappear
what could causes this?

##### Share on other sites
ff8    134
if the texture becomes same as the light's color then check if the normals are normalized.
take care.