Sign in to follow this  
ComradeBG

md2 animation

Recommended Posts

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


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


Link to post
Share on other sites
ComradeBG    122
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
ScottC    100
Quote:
Original post by Evil Steve
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.

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


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


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


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this