Better easings and motion but I need better data.

This commit is contained in:
Zed A. Shaw 2025-10-27 22:22:57 -04:00
parent f8158a3ea9
commit 949bbd4f15
10 changed files with 75 additions and 17 deletions

View file

@ -1,4 +1,5 @@
#include "animation.hpp"
#include "rand.hpp"
namespace components {
void Animation::play() {
@ -10,7 +11,7 @@ namespace components {
}
float Animation::twitching() {
float tick = ease::sine(float(frames) / subframe * ease_rate);
float tick = ease::sine(float(frames) / (subframe + 0.0001) * ease_rate);
switch(easing) {
case ease::NONE:
@ -23,6 +24,10 @@ namespace components {
return ease::sine(ease::out_bounce(tick));
case ease::IN_OUT_BACK:
return ease::sine(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);
default:
dbc::sentinel(
fmt::format("Invalid easing {} given to animation",
@ -38,9 +43,36 @@ namespace components {
float tick = twitching();
if(stationary) {
scale_out.x = std::lerp(scale_x, max_scale, tick);
scale_out.y = std::lerp(scale_y, max_scale, tick);
pos_out.y = pos_out.y - (pos_out.y * scale_out.y - pos_out.y);
switch(motion) {
case ease::SHAKE: {
pos_out.x += std::lerp(scale_x, max_scale, tick);
} break;
case ease::BOUNCE: {
pos_out.y -= std::lerp(scale_y, max_scale, tick);
} break;
case ease::RUSH: {
scale_out.x = std::lerp(scale_x, max_scale, tick);
scale_out.y = std::lerp(scale_y, max_scale, tick);
pos_out.y = pos_out.y - (pos_out.y * scale_out.y - pos_out.y);
} break;
case ease::SQUEEZE: {
scale_out.x *= std::lerp(scale_x, max_scale, tick);
} break;
case ease::SQUASH: {
scale_out.y *= std::lerp(scale_y, max_scale, tick);
} break;
case ease::STRETCH: {
scale_out.x = std::lerp(scale_x, max_scale, tick);
fmt::println("scale_x: {} max_scale: {} tick: {} scale_out.x: {}",
scale_x, max_scale, tick, scale_out.x);
} break;
case ease::GROW: {
scale_out.y = std::lerp(scale_y, max_scale, tick);
} break;
default:
dbc::sentinel("Unknown animation.motion setting.");
}
} else {
scale_out.x = std::lerp(scale_out.x * scale_x, scale_out.x * max_scale, tick);
scale_out.y = std::lerp(scale_out.y * scale_y, scale_out.y * max_scale, tick);
@ -86,7 +118,11 @@ namespace animation {
sprite.setTextureRect(rect);
sprite.setPosition(pos);
sprite.setScale(scale);
// BUG: make this an option: apply_scale, apply_position and ranges for x y
if(anim.motion != ease::SHAKE && anim.motion != ease::BOUNCE && anim.motion != ease::RUSH) {
sprite.setScale(scale);
}
return anim.playing;
}