Movement is now much smoother for the easing functions and I can pan around better, but it's hard coded to only do pan at the moment.

This commit is contained in:
Zed A. Shaw 2025-11-09 01:40:15 -05:00
parent 2ebefcce05
commit 0d326089f7
8 changed files with 37 additions and 47 deletions

View file

@ -1,7 +1,9 @@
#include "animation.hpp"
#include "rand.hpp"
#include <cmath>
namespace components {
void Animation::play() {
if(!playing) {
current = 0;
@ -11,7 +13,7 @@ namespace components {
}
float Animation::twitching() {
float tick = ease::sine(float(frames) / (subframe + 0.0001) * ease_rate);
float tick = 1 - std::powf(ease_rate, subframe + 0.0001);
switch(easing) {
case ease::NONE:
@ -21,13 +23,15 @@ namespace components {
case ease::OUT_CIRC:
return ease::out_circ(tick);
case ease::OUT_BOUNCE:
return ease::sine(ease::out_bounce(tick));
return ease::out_bounce(tick);
case ease::IN_OUT_BACK:
return ease::sine(ease::in_out_back(tick));
return ease::in_out_back(tick);
case ease::RANDOM:
return Random::uniform_real(0.0001f, 1.0f);
case ease::NORM_DIST:
return Random::normal(0.5f, 0.1f);
case ease::LINEAR:
return tick;
default:
dbc::sentinel(
fmt::format("Invalid easing {} given to animation",
@ -65,8 +69,8 @@ namespace components {
scale_out.y = std::lerp(min_y, max_y, tick);
} break;
case ease::SLIDE: {
pos_out.x += std::lerp(pos_out.x, pos_out.x + max_x, tick);
pos_out.y += std::lerp(pos_out.y, pos_out.y + max_y, tick);
pos_out.x = std::lerp(min_x, max_x, tick);
pos_out.y = std::lerp(min_y, max_y, tick);
} break;
default:
dbc::sentinel("Unknown animation.motion setting.");