Ease2 is the new way to do easing functions.
This commit is contained in:
parent
31b815d43e
commit
c0f69ed026
9 changed files with 151 additions and 75 deletions
66
animate2.cpp
66
animate2.cpp
|
|
@ -4,6 +4,7 @@
|
|||
#include "dbc.hpp"
|
||||
#include "rand.hpp"
|
||||
|
||||
|
||||
namespace animate2 {
|
||||
std::vector<sf::IntRect> Animate2::calc_frames() {
|
||||
std::vector<sf::IntRect> frames;
|
||||
|
|
@ -77,70 +78,11 @@ namespace animate2 {
|
|||
|
||||
float Transform::twitching(Sequence& seq) {
|
||||
float tick = 1 - std::powf(ease_rate, seq.subframe + 0.0001);
|
||||
|
||||
switch(easing) {
|
||||
case ease::NONE:
|
||||
return 0.0;
|
||||
case ease::SINE:
|
||||
return std::abs(std::sin(seq.subframe * ease_rate));
|
||||
case ease::OUT_CIRC:
|
||||
return ease::out_circ(tick);
|
||||
case ease::OUT_BOUNCE:
|
||||
return ease::out_bounce(tick);
|
||||
case ease::IN_OUT_BACK:
|
||||
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",
|
||||
int(easing)));
|
||||
}
|
||||
return easing(tick);
|
||||
}
|
||||
|
||||
void Transform::lerp(Sequence& seq, sf::Vector2f& pos_out, sf::Vector2f& scale_out) {
|
||||
float tick = twitching(seq);
|
||||
|
||||
if(stationary) {
|
||||
switch(motion) {
|
||||
case ease::SHAKE: {
|
||||
pos_out.x += std::lerp(min_x, max_x, tick);
|
||||
} break;
|
||||
case ease::BOUNCE: {
|
||||
pos_out.y -= std::lerp(min_y, max_y, tick);
|
||||
} break;
|
||||
case ease::RUSH: {
|
||||
scale_out.x = std::lerp(min_x, max_x, tick);
|
||||
scale_out.y = std::lerp(min_y, max_y, 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(min_x, max_x, tick);
|
||||
} break;
|
||||
case ease::SQUASH: {
|
||||
scale_out.y *= std::lerp(min_y, max_y, tick);
|
||||
} break;
|
||||
case ease::STRETCH: {
|
||||
scale_out.x = std::lerp(min_x, max_x, tick);
|
||||
} break;
|
||||
case ease::GROW: {
|
||||
scale_out.y = std::lerp(min_y, max_y, tick);
|
||||
} break;
|
||||
case ease::SLIDE: {
|
||||
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.");
|
||||
}
|
||||
} else {
|
||||
dbc::sentinel("scale should not run");
|
||||
scale_out.x = std::lerp(scale_out.x * min_x, scale_out.x * max_x, tick);
|
||||
scale_out.y = std::lerp(scale_out.y * min_y, scale_out.y * max_y, tick);
|
||||
}
|
||||
float tick = std::abs(twitching(seq));
|
||||
return motion(*this, pos_out, scale_out, tick);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue