You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.0 KiB
44 lines
1.0 KiB
#pragma once
|
|
#include <cmath>
|
|
|
|
namespace ease {
|
|
|
|
enum Style {
|
|
NONE, SINE, OUT_CIRC, OUT_BOUNCE, IN_OUT_BACK
|
|
};
|
|
|
|
inline double sine(double x) {
|
|
return (std::sin(x) + 1.0) / 2.0;
|
|
}
|
|
|
|
inline double out_circ(double x) {
|
|
return std::sqrt(1.0f - std::pow(x - 1.0f, 2.0f));
|
|
}
|
|
|
|
inline 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;
|
|
}
|
|
}
|
|
|
|
inline 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;
|
|
}
|
|
}
|
|
|