99 lines
3 KiB
C++
99 lines
3 KiB
C++
#include "easings.hpp"
|
|
#include "rand.hpp"
|
|
#include "animate2.hpp"
|
|
#include <fmt/core.h>
|
|
|
|
namespace ease2 {
|
|
using namespace animate2;
|
|
|
|
double none(float tick) {
|
|
return 0.0;
|
|
}
|
|
|
|
double sine(double x) {
|
|
// old one? return std::abs(std::sin(seq.subframe * ease_rate));
|
|
return (std::sin(x) + 1.0) / 2.0;
|
|
}
|
|
|
|
double out_circle(double x) {
|
|
return std::sqrt(1.0f - ((x - 1.0f) * (x - 1.0f)));
|
|
}
|
|
|
|
double out_bounce(double x) {
|
|
constexpr const double n1 = 7.5625;
|
|
constexpr const double d1 = 2.75;
|
|
|
|
if (x < 1 / d1) {
|
|
return n1 * x * x;
|
|
} else if (x < 2 / d1) {
|
|
x -= 1.5;
|
|
return n1 * (x / d1) * x + 0.75;
|
|
} else if (x < 2.5 / d1) {
|
|
x -= 2.25;
|
|
return n1 * (x / d1) * x + 0.9375;
|
|
} else {
|
|
x -= 2.625;
|
|
return n1 * (x / d1) * x + 0.984375;
|
|
}
|
|
}
|
|
|
|
double in_out_back(double x) {
|
|
constexpr const double c1 = 1.70158;
|
|
constexpr const double c2 = c1 * 1.525;
|
|
|
|
return x < 0.5
|
|
? (std::pow(2.0 * x, 2.0) * ((c2 + 1.0) * 2.0 * x - c2)) / 2.0
|
|
: (std::pow(2.0 * x - 2.0, 2.0) * ((c2 + 1.0) * (x * 2.0 - 2.0) + c2) + 2.0) / 2.0;
|
|
}
|
|
|
|
double random(double tick) {
|
|
return Random::uniform_real(0.0001f, 1.0f);
|
|
}
|
|
|
|
double normal_dist(double tick) {
|
|
return Random::normal(0.5f, 0.1f);
|
|
}
|
|
|
|
void move_shake(Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick) {
|
|
pos_out.x += std::lerp(tr.min_x, tr.max_x, tick);
|
|
}
|
|
|
|
void move_bounce(Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick) {
|
|
pos_out.y -= std::lerp(tr.min_y, tr.max_y, tick);
|
|
}
|
|
|
|
void move_rush(Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick) {
|
|
scale_out.x = std::lerp(tr.min_x, tr.max_x, tick);
|
|
scale_out.y = std::lerp(tr.min_y, tr.max_y, tick);
|
|
pos_out.y = pos_out.y - (pos_out.y * scale_out.y - pos_out.y);
|
|
}
|
|
|
|
void scale_squeeze(Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick) {
|
|
scale_out.x *= std::lerp(tr.min_x, tr.max_x, tick);
|
|
}
|
|
|
|
void scale_squash(Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick) {
|
|
scale_out.y *= std::lerp(tr.min_y, tr.max_y, tick);
|
|
}
|
|
|
|
void scale_stretch(Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick) {
|
|
scale_out.x = std::lerp(tr.min_x, tr.max_x, tick);
|
|
}
|
|
|
|
void scale_grow(Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick) {
|
|
scale_out.y = std::lerp(tr.min_y, tr.max_y, tick);
|
|
}
|
|
|
|
void move_slide(Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick) {
|
|
pos_out.x += std::lerp(tr.min_x, tr.max_x, tick);
|
|
pos_out.y += std::lerp(tr.min_y, tr.max_y, tick);
|
|
}
|
|
|
|
void move_none(Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick) {
|
|
}
|
|
|
|
void scale_only(Transform &tr, sf::Vector2f& pos_out, sf::Vector2f& scale_out, float tick) {
|
|
scale_out.x = std::lerp(scale_out.x * tr.min_x, scale_out.x * tr.max_x, tick);
|
|
scale_out.y = std::lerp(scale_out.y * tr.min_y, scale_out.y * tr.max_y, tick);
|
|
}
|
|
}
|