Animator now can apply transforms using the timer alpha which mostly works.

This commit is contained in:
Zed A. Shaw 2026-01-28 00:29:39 -05:00
parent 7f14a39edf
commit 785d0240da
4 changed files with 29 additions and 31 deletions

View file

@ -71,9 +71,8 @@ namespace animate2 {
update_frame();
}
void Animate2::motion(sf::Vector2f& pos, sf::Vector2f& scale) {
$transform.twitching($sequence);
$transform.lerp($sequence, pos, scale);
void Animate2::motion(sf::Vector2f& pos, sf::Vector2f& scale, float alpha) {
$transform.lerp($sequence, pos, scale, alpha);
}
void Timer::start() {
@ -106,25 +105,25 @@ namespace animate2 {
accumulator += frame_duration;
// find the tick count based on DELTA
double tick_count = accumulator / DELTA;
// alpha is then the remainder/fractional part
double alpha = modf(tick_count, &tick_count);
double tick_count = floor(accumulator / DELTA);
// reduce accumulator by the number of DELTAS
accumulator -= tick_count * DELTA;
// that leaves the remaining errors for next loop
// alpha is then what we lerp...but WHY?!
alpha = accumulator / DELTA;
// return the number of even DELTA ticks and the alpha
return {int(tick_count), alpha};
}
float Transform::twitching(Sequence& seq) {
float tick = 1 - std::powf(ease_rate, seq.subframe + 0.0001);
return easing(tick);
float Transform::twitching(Sequence& seq, float alpha) {
return easing(alpha);
}
void Transform::lerp(Sequence& seq, sf::Vector2f& pos_out, sf::Vector2f& scale_out) {
float tick = std::abs(twitching(seq));
void Transform::lerp(Sequence& seq, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float alpha) {
float tick = std::abs(twitching(seq, alpha));
return motion(*this, pos_out, scale_out, tick);
}
}