Jump to content
  • Advertisement
Sign in to follow this  
ComradeBG

md2 animation

This topic is 4268 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

Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
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 this post


Link to post
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 this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!