I've been following the development of the panim development (which unfortunately doesn't have a repo yet or I would've created a pull request there) and I believe that there is another viable and perhaps simpler way to describe animations in code.
This is based on Sebastian Lague's animation system. It uses a more immediate mode style api where every update you go over the entire animation code and decide what actually happens based on when in the animation you are.
The state required for this is:
typedef struct {
float currentTime; // time since start of the animation preserved between frames
float clipStartTime; // where the code is in the animation, updated by each "wait" operation, reset every update.
float globEnd; // when the animation ends, reset every update.
} ImAnim;
Then you can get a float t from 0 to 1 based on where in the animation you are:
If it returns 0 then you are before the clip and should leave the animated object untouched,
if it returns 1 then the clip is finished and the animated object should be as if the clip just finished.
A lerp would do the natural thing with the result.
Your shuffle squares example would look something like: (bugs might be present)
I've been following the development of the panim development (which unfortunately doesn't have a repo yet or I would've created a pull request there) and I believe that there is another viable and perhaps simpler way to describe animations in code.
This is based on Sebastian Lague's animation system. It uses a more immediate mode style api where every update you go over the entire animation code and decide what actually happens based on when in the animation you are.
The state required for this is:
Then you can get a
float t
from 0 to 1 based on where in the animation you are:If it returns 0 then you are before the clip and should leave the animated object untouched, if it returns 1 then the clip is finished and the animated object should be as if the clip just finished.
A lerp would do the natural thing with the result.
Your shuffle squares example would look something like: (bugs might be present)
no allocation or function pointers required.
In addition you can seek to any point in the animation by setting the
currentTime
field to which frame you want to display.