diff options
| author | Syndamia <kamen@syndamia.com> | 2026-03-28 22:36:57 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2026-03-28 22:36:57 +0200 |
| commit | 40f33359c7b47d99c3386948bbeead8409a1a902 (patch) | |
| tree | 6847f11c13b3eb87d0dadfab4fce68a2062fd09a | |
| parent | af9f6ae727a15b965789717047a52e6857a3bd8d (diff) | |
| download | ppm_graphics-40f33359c7b47d99c3386948bbeead8409a1a902.tar ppm_graphics-40f33359c7b47d99c3386948bbeead8409a1a902.tar.gz ppm_graphics-40f33359c7b47d99c3386948bbeead8409a1a902.zip | |
feat: Add rotation interpolation and add frame context reset on new frame
| -rw-r--r-- | AnimationRender/AnimationRender.c | 4 | ||||
| -rw-r--r-- | AnimationRender/F_Interpolate.c | 4 | ||||
| -rw-r--r-- | AnimationRender/F_Interpolate.h | 2 | ||||
| -rw-r--r-- | graphics.c | 11 |
4 files changed, 21 insertions, 0 deletions
diff --git a/AnimationRender/AnimationRender.c b/AnimationRender/AnimationRender.c index 68bb7b7..e717a95 100644 --- a/AnimationRender/AnimationRender.c +++ b/AnimationRender/AnimationRender.c @@ -10,7 +10,10 @@ void RenderAnimation(u32 width, u32 height, u32 totalFrames, const FrameCallback fc.frameBuffer = frameBuffer; for (u32 f = 0; f < totalFrames; ++f) { + fc.startFrame = 0; + fc.endFrame = totalFrames; fc.frame = f; + for (usize i = 0; i < sizeCallbacks; ++i) { // Soft context reset if (callbacks[i] == NULL) { @@ -21,6 +24,7 @@ void RenderAnimation(u32 width, u32 height, u32 totalFrames, const FrameCallback else if (fc.startFrame <= fc.frame && fc.frame <= fc.endFrame) callbacks[i]->callback(callbacks[i]->callback_self, &fc); } + ppm6_write(stdout, frameBuffer); } diff --git a/AnimationRender/F_Interpolate.c b/AnimationRender/F_Interpolate.c index cc72163..890279c 100644 --- a/AnimationRender/F_Interpolate.c +++ b/AnimationRender/F_Interpolate.c @@ -31,3 +31,7 @@ void Interpolate_TransformCenter(TransformCenter* value, const TransformCenter* value->centerX = NUM_INTERPOLATE(start->centerX, end->centerX, progress); value->centerY = NUM_INTERPOLATE(start->centerY, end->centerY, progress); } + +void Interpolate_TransformRotate(TransformRotate* value, const TransformRotate* start, const TransformRotate* end, double progress) { + value->angle = NUM_INTERPOLATE(start->angle, end->angle, progress); +} diff --git a/AnimationRender/F_Interpolate.h b/AnimationRender/F_Interpolate.h index 502fbb4..e2ee4c5 100644 --- a/AnimationRender/F_Interpolate.h +++ b/AnimationRender/F_Interpolate.h @@ -3,6 +3,7 @@ #include "FrameCallback.h" #include "../FrameRender/P_TransformCenter.h" +#include "../FrameRender/P_TransformRotate.h" typedef void (*f_interpolate)(void* value, const void* start, const void* end, double progress); @@ -16,5 +17,6 @@ typedef struct Interpolate { FrameCallback* Interpolate_setup(Interpolate obj); void Interpolate_TransformCenter(TransformCenter* value, const TransformCenter* start, const TransformCenter* end, double progress); +void Interpolate_TransformRotate(TransformRotate* value, const TransformRotate* start, const TransformRotate* end, double progress); #endif /* F_INTERPOLATE */ @@ -63,6 +63,8 @@ main() { TransformCenter img1 = { .centerX = width / 8, .centerY = height * 3/5 }, img2 = { .centerX = height * 3/5, .centerY = width / 8 }; + + TransformRotate r1 = { .angle = M_PI / 8 }, r2 = { .angle = M_PI * 2 }; const FrameCallback* frameCallbacks[] = { Draw_setup((Draw){ .callbacks = (const PixelCallback**)callbacks, .sizeCallbacks = sizeCallbacks, @@ -75,6 +77,15 @@ main() { .value = callbacks[10]->callback_self, .interpolate = (f_interpolate)Interpolate_TransformCenter, }), + NULL, + FrameRange_setup((FrameRange){ + .startFrame = 0, .endFrame = 50, + }), + Interpolate_setup((Interpolate){ + .startValue = &r1, .endValue = &r2, + .value = callbacks[4]->callback_self, + .interpolate = (f_interpolate)Interpolate_TransformRotate, + }), }; u32 sizeFrameCallbacks = sizeof(frameCallbacks) / sizeof(*frameCallbacks); |
