46 {
47 Alpha = FMath::Clamp(Alpha, 0.f, 1.f);
48
49 switch (Type)
50 {
51 case EEaseType::Linear: return Alpha;
52 case EEaseType::EaseInQuad: return Alpha * Alpha;
53 case EEaseType::EaseOutQuad: return 1.f - FMath::Pow(1.f - Alpha, 2.f);
54 case EEaseType::EaseInOutQuad: return Alpha < 0.5f ? 2.f*Alpha*Alpha : 1.f - FMath::Pow(-2.f*Alpha+2.f,2.f)/2.f;
55 case EEaseType::EaseInCubic: return Alpha*Alpha*Alpha;
56 case EEaseType::EaseOutCubic: return 1.f - FMath::Pow(1.f - Alpha, 3.f);
57 case EEaseType::EaseInOutCubic: return Alpha < 0.5f ? 4.f*Alpha*Alpha*Alpha : 1.f - FMath::Pow(-2.f*Alpha+2.f,3.f)/2.f;
58 case EEaseType::EaseInQuart: return Alpha*Alpha*Alpha*Alpha;
59 case EEaseType::EaseOutQuart: return 1.f - FMath::Pow(1.f - Alpha, 4.f);
60 case EEaseType::EaseInOutQuart: return Alpha < 0.5f ? 8.f*Alpha*Alpha*Alpha*Alpha : 1.f - FMath::Pow(-2.f*Alpha+2.f,4.f)/2.f;
61 case EEaseType::EaseInQuint: return Alpha*Alpha*Alpha*Alpha*Alpha;
62 case EEaseType::EaseOutQuint: return 1.f - FMath::Pow(1.f - Alpha, 5.f);
63 case EEaseType::EaseInOutQuint: return Alpha < 0.5f ? 16.f*FMath::Pow(Alpha,5.f) : 1.f - FMath::Pow(-2.f*Alpha+2.f,5.f)/2.f;
64 case EEaseType::EaseInSine: return 1.f - FMath::Cos((Alpha * PI) / 2.f);
65 case EEaseType::EaseOutSine: return FMath::Sin((Alpha * PI) / 2.f);
66 case EEaseType::EaseInOutSine: return -(FMath::Cos(PI*Alpha) - 1.f)/2.f;
67 case EEaseType::EaseInExpo: return Alpha == 0.f ? 0.f : FMath::Pow(2.f, 10.f*Alpha - 10.f);
68 case EEaseType::EaseOutExpo: return Alpha == 1.f ? 1.f : 1.f - FMath::Pow(2.f, -10.f*Alpha);
69 case EEaseType::EaseInOutExpo: return Alpha == 0.f ? 0.f : Alpha == 1.f ? 1.f : Alpha < 0.5f ? FMath::Pow(2.f, 20.f*Alpha - 10.f)/2.f : (2.f - FMath::Pow(2.f,-20.f*Alpha + 10.f))/2.f;
70 case EEaseType::EaseInCirc: return 1.f - FMath::Sqrt(1.f - FMath::Pow(Alpha,2.f));
71 case EEaseType::EaseOutCirc: return FMath::Sqrt(1.f - FMath::Pow(Alpha-1.f,2.f));
72 case EEaseType::EaseInOutCirc: return Alpha < 0.5f ? (1.f - FMath::Sqrt(1.f - FMath::Pow(2.f*Alpha,2.f)))/2.f : (FMath::Sqrt(1.f - FMath::Pow(-2.f*Alpha+2.f,2.f))+1.f)/2.f;
73
74 case EEaseType::EaseInElastic: return Alpha == 0.f ? 0.f : Alpha == 1.f ? 1.f : -FMath::Pow(2.f, 10.f*Alpha - 10.f) * FMath::Sin((Alpha*10.f - 10.75f) * (2.f*PI/3.f));
75 case EEaseType::EaseOutElastic: return Alpha == 0.f ? 0.f : Alpha == 1.f ? 1.f : FMath::Pow(2.f, -10.f*Alpha) * FMath::Sin((Alpha*10.f - 0.75f) * (2.f*PI/3.f)) + 1.f;
76 case EEaseType::EaseInOutElastic: return Alpha == 0.f ? 0.f : Alpha == 1.f ? 1.f : Alpha < 0.5f ? -(FMath::Pow(2.f, 20.f*Alpha-10.f) * FMath::Sin((20.f*Alpha-11.125f)*(2.f*PI/4.5f)))/2.f : (FMath::Pow(2.f,-20.f*Alpha+10.f)*FMath::Sin((20.f*Alpha-11.125f)*(2.f*PI/4.5f)))/2.f + 1.f;
77
78 case EEaseType::EaseInBack:
79 {
80 constexpr float c1 = 1.70158f;
81 return Alpha*Alpha*((c1+1.f)*Alpha - c1);
82 }
83 case EEaseType::EaseOutBack:
84 {
85 constexpr float c1 = 1.70158f;
86 constexpr float c3 = c1 + 1.f;
87 return 1.f + (Alpha-1.f)*(Alpha-1.f)*(c3*(Alpha-1.f) + c1);
88 }
89 case EEaseType::EaseInOutBack:
90 {
91 constexpr float c1 = 1.70158f;
92 constexpr float c2 = c1*1.525f;
93 return Alpha < 0.5f ? (FMath::Pow(2.f*Alpha,2.f)*((c2+1.f)*2.f*Alpha - c2))/2.f : (FMath::Pow(2.f*Alpha-2.f,2.f)*((c2+1.f)*(Alpha*2.f-2.f)+c2)+2.f)/2.f;
94 }
95
96 case EEaseType::EaseInBounce:
return 1.f -
Ease(1.f - Alpha, EEaseType::EaseOutBounce);
97 case EEaseType::EaseOutBounce:
98 {
99 constexpr float n1 = 7.5625f;
100 constexpr float d1 = 2.75f;
101 float x = Alpha;
102 if (x < 1.f/d1) return n1*x*x;
103 else if (x < 2.f/d1) return n1*(x-=1.5f/d1)*x + 0.75f;
104 else if (x < 2.5f/d1) return n1*(x-=2.25f/d1)*x + 0.9375f;
105 else return n1*(x-=2.625f/d1)*x + 0.984375f;
106 }
107 case EEaseType::EaseInOutBounce:
return Alpha < 0.5f ? (1.f -
Ease(1.f - 2.f*Alpha, EEaseType::EaseOutBounce))/2.f : (1.f +
Ease(2.f*Alpha-1.f,
EEaseType::EaseOutBounce))/2.f;
108
109 default: return Alpha;
110 }
111 }
static float Ease(float Alpha, EEaseType Type)