View Full Version : MD2 Time Based Animating

zedus

12-10-2000, 09:00 AM

Well, I thought this subject is wide anough to be a new topic:

Could ppl here tell me of common methods of animating md2 models with respect to time. I've got the animation implemented but it doesn't have any respect to time so when the refresh rate is high it's fast and vica versa.

The method I'm using is the only one I know - Linear Interpolation.

DFrey

12-10-2000, 09:50 AM

If you are using linear interpolation, what exactly is your interpolation parameter if not time?

zedus

12-11-2000, 07:16 AM

Well, I hope I understand the term Linear Interpolation but here is what I do:

Here it is:

StartAni - Is the frame the loop starts;

EndAni - you guessed - the frame the loop ends...

The rest should be obvious.

anyway, remember that when I wrote this I wasn't thinking about the FPS issue , and now that all the physics is time based , this is the obly obsticle I'm facing towards a time based engine. This was done based only on intuition - it worked well in the rest of the engine but obviously not here. well, now here's my code:

Glvoid UpdateAnimation(GLvoid)

{

if (AniCounter<EndAni)

{

if (SubAniCounter==0) // we should move to next frame...

{

AniCounter++;

CreateAnimationArray(CurrentFrame,FramesArray[AniCounter].VertexArray); // Creates The Direction Array I was talking about.

SubAniCounter++;

}

else

{

SubAniCounter++;

if (SubAniCounter>(int)SubFramesNum)

SubAniCounter=0;

}

ActivateAnimationArray(); // Uses the Direction Array I was talking about

}

else

{

AniCounter=StartAni;

}

}

zedus

12-11-2000, 07:24 AM

An easier sollution would be simply telling me what formula linear interpolation uses or simply directing me to a tutorial about it.

10x in advance!

DFrey

12-11-2000, 09:55 AM

Simply put, linear interpolation of the keyframes involves calculating the relative positions of the vertices of the triangles with respect to two adjacent keyframes given an interpolation parameter, which is generally derived from time. For example: V'=V1 * t + V0*(1-t), where t is the interpolation parameter such that when t=0 keyframe 0 is used and when t=1 keyframe 1 is used. t itself is derived from time and the keyframes per second that the model is desgined to use, e.g. t=period since previous keyframe / keyframe period.

zedus

12-11-2000, 10:10 AM

I just thought of this method:

I decide how much time should a segment last.

I find out the TimePassedFromAnimationStart.

let's say it's found between frames 3 and 4.

find out where is it found between them (My calculations return a value between zero and 1, let's call it FramePart)

I use that to find the destination :

DestinationPoint = (PointInFrame4 - PointInFrame3) * FramePart.

Now I find the middle between my current point position to the destination.

I didn't try it and thought about it 3 minutes ago, but I think that it's surves my desire of a time based animation system. Is this method already used? or maybe totaly wrong?

DFrey

12-11-2000, 10:53 AM

That's essentially correct, although your equation is wrong. You need an equation similar to one I have shown above. Since what you have, if framepart=0, then neither keyframe contributes to the final outcome, and for framepart!=0, both keyframes have an impact on the result. With what I've shown, when t=0, only V0 contributes to the outcome. And when t=1, only V1 contributes to the outcome. For 0<t<1, both keyframes contribute.

zedus

12-11-2000, 09:43 PM

well, I guess my problem is that I don't understand this equation:

V'=V1 * t + V0*(1-t)

what each of the values stands for?

Hi there !

Although DFrey's equation is perfectly correct, it does not make it easy to understand the interpolation (don't kill me DFrey ! :-) ).

Say you want to go from point P1(x1,y1,z1) to point P2(x2,y2,z2). The vector V that defines the move from P1 to P2 is given by:

V(xv,yv,zv) where :

xv=x2-x1

yv=y2-y1

zv=z2-z1

Now, any point P in the segment [P1P2] can be defined as:

P=P1 + t*V where t is between 0 and 1.

The equation can also be written:

P=P1 + t * (P2-P1)

or:

P= t * P2 + (1 - t) * P1

And here you have DFrey's equation.

Now, if you want N frames between two keyframes, you just make t vary from 0 to 1 with a step of 1/N.

Let's say you have your 2 arrays of vertices that show two different states of your mesh. Let's call them A1 and A2. They could be allocated as follow:

float (*A1)[3], (*A2)[3]; // [3] for x,y,z

A1=new float[N_Vertices][3];

A2=new float[N_Vertices][3];

LoadMesh(A1); // Don't know about MD2 format but I guess you know how to load that !

LoadMesh(A2);

Now, we want a function that will give us an intermediate mesh based on the two base meshes, one frame number, and the total number of frames we want:

void InterpolateMesh(int iNVertices,float (*A1)[3],float (*A2)[3],float (*AC)[3],int iStep,int iNSteps)

{

int i;

double t=(double) iStep/iNSteps;

for (i=0;i<iNVertices;i++)

{

AC[i][0]=A1[i][0]+(A2[i][0]-A1[i][0])*t;

AC[i][1]=A1[i][1]+(A2[i][1]-A1[i][1])*t;

AC[i][2]=A1[i][2]+(A2[i][2]-A1[i][2])*t;

}

}

iNVertices is the number of vertices.

A1,A2 are our basic meshes.

AC is the output mesh (the interpolated one).

iStep is the frame number we want to calculate.

iNSteps is the total number of frames.

As you see:

When iStep=0, we obtain A1.

When iStep=iNSteps, we obtain A2.

When iStep is in between, we obtain a frame between A1 and A2 !

I hope this will be useful !

Although I think the code above is correct, please forgive me if there is an error: I typed it directly....

Regards.

Eric

[This message has been edited by Eric (edited 12-12-2000).]

zedus

12-11-2000, 10:23 PM

Well, that totaly made everything clear i'm implementing it at the very moment...

10x alot by understanding where that eqaution came from I understand the subject.

10x alot to both of you!

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.