diff options
| author | Syndamia <kamen@syndamia.com> | 2026-03-28 22:14:32 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2026-03-28 22:14:32 +0200 |
| commit | 1cc8f72fb1c44e203a324e274038c2883c351fbb (patch) | |
| tree | bb3f63143fc643fa9d35bcba6566a0d6ef445cab /AnimationRender/F_Interpolate.c | |
| parent | 6a63e2c0e1f37c502501e1b611e8dc289476c1f2 (diff) | |
| download | ppm_graphics-1cc8f72fb1c44e203a324e274038c2883c351fbb.tar ppm_graphics-1cc8f72fb1c44e203a324e274038c2883c351fbb.tar.gz ppm_graphics-1cc8f72fb1c44e203a324e274038c2883c351fbb.zip | |
feat: Add animation capabilities with linear interpolation
Diffstat (limited to 'AnimationRender/F_Interpolate.c')
| -rw-r--r-- | AnimationRender/F_Interpolate.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/AnimationRender/F_Interpolate.c b/AnimationRender/F_Interpolate.c new file mode 100644 index 0000000..cc72163 --- /dev/null +++ b/AnimationRender/F_Interpolate.c @@ -0,0 +1,33 @@ +#include "F_Interpolate.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +void Interpolate_callback(Interpolate* self, struct FrameContext* fc) { + if (self->interpolate == NULL) { + fprintf(stderr, "Interpolation function cannot be NULL!\n"); + return; + } + + double p = (double)(fc->frame - fc->startFrame) / (fc->endFrame - fc->startFrame); + + if (0.0 <= p && p <= 1.0) + self->interpolate(self->value, self->startValue, self->endValue, p); +} + +FrameCallback* Interpolate_setup(Interpolate obj) { + FrameCallback* fca = malloc(sizeof(struct FrameCallback)); + + fca->callback = (FrameCallback_callback)Interpolate_callback; + fca->callback_self = malloc(sizeof(obj)); + memcpy(fca->callback_self, &obj, sizeof(obj)); + + return fca; +} + +#define NUM_INTERPOLATE(a, b, perc) ((a) * (1.0 - (perc)) + (b) * (perc)) + +void Interpolate_TransformCenter(TransformCenter* value, const TransformCenter* start, const TransformCenter* end, double progress) { + value->centerX = NUM_INTERPOLATE(start->centerX, end->centerX, progress); + value->centerY = NUM_INTERPOLATE(start->centerY, end->centerY, progress); +} |
