92 lines
2.1 KiB
C
92 lines
2.1 KiB
C
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <cstdint>
|
||
|
|
|
||
|
|
namespace extra2d {
|
||
|
|
|
||
|
|
enum class TweenEasing : uint8_t {
|
||
|
|
Linear,
|
||
|
|
QuadIn,
|
||
|
|
QuadOut,
|
||
|
|
QuadInOut,
|
||
|
|
CubicIn,
|
||
|
|
CubicOut,
|
||
|
|
CubicInOut,
|
||
|
|
QuartIn,
|
||
|
|
QuartOut,
|
||
|
|
QuartInOut,
|
||
|
|
QuintIn,
|
||
|
|
QuintOut,
|
||
|
|
QuintInOut,
|
||
|
|
SineIn,
|
||
|
|
SineOut,
|
||
|
|
SineInOut,
|
||
|
|
ExpoIn,
|
||
|
|
ExpoOut,
|
||
|
|
ExpoInOut,
|
||
|
|
CircIn,
|
||
|
|
CircOut,
|
||
|
|
CircInOut,
|
||
|
|
ElasticIn,
|
||
|
|
ElasticOut,
|
||
|
|
ElasticInOut,
|
||
|
|
BackIn,
|
||
|
|
BackOut,
|
||
|
|
BackInOut,
|
||
|
|
BounceIn,
|
||
|
|
BounceOut,
|
||
|
|
BounceInOut,
|
||
|
|
Smooth,
|
||
|
|
Fade,
|
||
|
|
};
|
||
|
|
|
||
|
|
class EasingFunctions {
|
||
|
|
public:
|
||
|
|
using EasingFunc = float (*)(float);
|
||
|
|
|
||
|
|
static float apply(float t, TweenEasing easing);
|
||
|
|
static EasingFunc get(TweenEasing easing);
|
||
|
|
|
||
|
|
static float linear(float t);
|
||
|
|
static float quadIn(float t);
|
||
|
|
static float quadOut(float t);
|
||
|
|
static float quadInOut(float t);
|
||
|
|
static float cubicIn(float t);
|
||
|
|
static float cubicOut(float t);
|
||
|
|
static float cubicInOut(float t);
|
||
|
|
static float quartIn(float t);
|
||
|
|
static float quartOut(float t);
|
||
|
|
static float quartInOut(float t);
|
||
|
|
static float quintIn(float t);
|
||
|
|
static float quintOut(float t);
|
||
|
|
static float quintInOut(float t);
|
||
|
|
static float sineIn(float t);
|
||
|
|
static float sineOut(float t);
|
||
|
|
static float sineInOut(float t);
|
||
|
|
static float expoIn(float t);
|
||
|
|
static float expoOut(float t);
|
||
|
|
static float expoInOut(float t);
|
||
|
|
static float circIn(float t);
|
||
|
|
static float circOut(float t);
|
||
|
|
static float circInOut(float t);
|
||
|
|
static float elasticIn(float t);
|
||
|
|
static float elasticOut(float t);
|
||
|
|
static float elasticInOut(float t);
|
||
|
|
static float backIn(float t);
|
||
|
|
static float backOut(float t);
|
||
|
|
static float backInOut(float t);
|
||
|
|
static float bounceIn(float t);
|
||
|
|
static float bounceOut(float t);
|
||
|
|
static float bounceInOut(float t);
|
||
|
|
static float smooth(float t);
|
||
|
|
static float fade(float t);
|
||
|
|
|
||
|
|
private:
|
||
|
|
static constexpr float PI = 3.14159265358979323846f;
|
||
|
|
static constexpr float HALF_PI = 1.57079632679489661923f;
|
||
|
|
static constexpr float BACK_CONST = 1.70158f;
|
||
|
|
static constexpr float ELASTIC_CONST = 2.0f * PI / 3.0f;
|
||
|
|
};
|
||
|
|
|
||
|
|
} // namespace extra2d
|