I have an MD2 loader that loads keyframes into memory. My draw function takes two parameters, a mode (not important right now), and a floating point value named frame. Here’s the idea:
If it gets passed 3.5 for the frame variable, then it means draw the coordinates halfway inbetween keyframe 3 and keyframe 4.
So, what should be my algorithm for doing this? I was thinking something that looks like this:
Originally posted by 31337:
(frames[(int)frame].x - frames[(int)frame-1)].x)*b[/b] + frames[(int)frame].x
So basically you are trying to do linear interpolation between the two keyframes. However, in your code snippet, the “scaling factor” (bolded) will be an integer. You want to use:
(frame-(int)frame)
You are also “offsetting” with the wrong frame (last part should be +frames[(int)frame-1].x)
Also, I suggest that you calculate indeces and “interplation fraction” before doing the interpolation (e.g. to handle the start/end of the animation without access violations etc).