View Full Version : MD2 Time Based Animating
12-10-2000, 10: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.
12-10-2000, 10:50 AM
If you are using linear interpolation, what exactly is your interpolation parameter if not time?
12-11-2000, 08: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:
if (SubAniCounter==0) // we should move to next frame...
CreateAnimationArray(CurrentFrame,FramesArray[AniCounter].VertexArray); // Creates The Direction Array I was talking about.
ActivateAnimationArray(); // Uses the Direction Array I was talking about
12-11-2000, 08: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!
12-11-2000, 10: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.
12-11-2000, 11: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?
12-11-2000, 11: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.
12-11-2000, 10: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 :
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)
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), (*A2); //  for x,y,z
LoadMesh(A1); // Don't know about MD2 format but I guess you know how to load that !
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),float (*A2),float (*AC),int iStep,int iNSteps)
double t=(double) iStep/iNSteps;
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....
[This message has been edited by Eric (edited 12-12-2000).]
12-11-2000, 11: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.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.