ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
easing.cpp
Go to the documentation of this file.
2
3// Linear
4float asw::easing::linear(float t) {
5 return t;
6}
7
8// Quadratic
9float asw::easing::easeInQuad(float t) {
10 return t * t;
11}
12
14 return t * (2.0F - t);
15}
16
18 return t < 0.5F ? 2.0F * t * t : -1.0F + (4.0F - (2.0F * t)) * t;
19}
20
21// Cubic
23 return t * t * t;
24}
25
27 const float u = t - 1.0F;
28 return (u * u * u) + 1.0F;
29}
30
32 return t < 0.5F ? 4.0F * t * t * t
33 : (t - 1.0F) * (2.0F * t - 2.0F) * (2.0F * t - 2.0F) + 1.0F;
34}
35
36// Sine
38 return 1.0F - std::cosf(t * M_PI * 0.5F);
39}
40
42 return std::sinf(t * M_PI * 0.5F);
43}
44
46 return 0.5F * (1.0F - std::cosf(M_PI * t));
47}
48
49// Exponential
51 return t == 0.0F ? 0.0F : std::pow(2.0F, 10.0F * (t - 1.0F));
52}
53
55 return t == 1.0F ? 1.0F : 1.0F - std::pow(2.0F, -10.0F * t);
56}
57
59 if (t == 0.0F) {
60 return 0.0F;
61 }
62
63 if (t == 1.0F) {
64 return 1.0F;
65 }
66
67 if (t < 0.5F) {
68 return std::pow(2.0F, (20.0F * t) - 10.0F) * 0.5F;
69 }
70
71 return (2.0F - std::pow(2.0F, (-20.0F * t) + 10.0F)) * 0.5F;
72}
73
74// Elastic
76 if (t == 0.0F || t == 1.0F) {
77 return t;
78 }
79
80 return -std::pow(2.0F, 10.0F * (t - 1.0F)) *
81 std::sin((t - 1.075F) * (2.0F * M_PI) / 0.3F);
82}
83
85 if (t == 0.0F || t == 1.0F) {
86 return t;
87 }
88
89 return std::pow(2.0F, -10.0F * t) *
90 std::sin((t - 0.075F) * (2.0F * M_PI) / 0.3F) +
91 1.0F;
92}
93
94// Bounce
96 if (t < 1.0F / 2.75F) {
97 return 7.5625F * t * t;
98 }
99
100 if (t < 2.0F / 2.75F) {
101 t -= 1.5F / 2.75F;
102 return (7.5625F * t * t) + 0.75F;
103 }
104
105 if (t < 2.5F / 2.75F) {
106 t -= 2.25F / 2.75F;
107 return (7.5625F * t * t) + 0.9375F;
108 }
109
110 t -= 2.625F / 2.75F;
111
112 return (7.5625F * t * t) + 0.984375F;
113}
114
116 return 1.0F - easeOutBounce(1.0F - t);
117}
118
119// Back (overshoot)
121 constexpr float s = 1.70158F;
122 return t * t * ((s + 1.0F) * t - s);
123}
124
126 constexpr float s = 1.70158F;
127 const float u = t - 1.0F;
128 return u * u * ((s + 1.0F) * u + s) + 1.0F;
129}
Easing functions for animations.
float easeOutElastic(float t)
Definition easing.cpp:84
float easeInOutCubic(float t)
Definition easing.cpp:31
float linear(float t)
Definition easing.cpp:4
float easeOutExpo(float t)
Definition easing.cpp:54
float easeInQuad(float t)
Definition easing.cpp:9
float easeInOutExpo(float t)
Definition easing.cpp:58
float easeOutQuad(float t)
Definition easing.cpp:13
float easeOutCubic(float t)
Definition easing.cpp:26
float easeInOutQuad(float t)
Definition easing.cpp:17
float easeInOutSine(float t)
Definition easing.cpp:45
float easeInElastic(float t)
Definition easing.cpp:75
float easeInCubic(float t)
Definition easing.cpp:22
float easeOutBounce(float t)
Definition easing.cpp:95
float easeInExpo(float t)
Definition easing.cpp:50
float easeOutBack(float t)
Definition easing.cpp:125
float easeInBack(float t)
Definition easing.cpp:120
float easeInBounce(float t)
Definition easing.cpp:115
float easeInSine(float t)
Definition easing.cpp:37
float easeOutSine(float t)
Definition easing.cpp:41