improve easing funcs

This commit is contained in:
Recep Aslantas
2018-06-15 08:55:59 +03:00
parent 564324f5d2
commit 02f6c67393

View File

@@ -145,7 +145,7 @@ glm_ease_quint_inout(float t) {
if (t < 0.5f) { if (t < 0.5f) {
f = t * t; f = t * t;
return 16.0f * f * f * f; return 16.0f * f * f * t;
} }
f = 2.0f * t - 2.0f; f = 2.0f * t - 2.0f;
@@ -157,20 +157,16 @@ glm_ease_quint_inout(float t) {
CGLM_INLINE CGLM_INLINE
float float
glm_ease_exp_in(float t) { glm_ease_exp_in(float t) {
float c; if (t == 0.0f)
if (t <= 0.0f)
return t; return t;
c = t - 1.0f; return powf(2.0f, 10.0f * (t - 1.0f));
return powf(2.0f, c * 10.0f);
} }
CGLM_INLINE CGLM_INLINE
float float
glm_ease_exp_out(float t) { glm_ease_exp_out(float t) {
if (t >= 1.0f) if (t == 1.0f)
return t; return t;
return 1.0f - powf(2.0f, -10.0f * t); return 1.0f - powf(2.0f, -10.0f * t);
@@ -179,6 +175,9 @@ glm_ease_exp_out(float t) {
CGLM_INLINE CGLM_INLINE
float float
glm_ease_exp_inout(float t) { glm_ease_exp_inout(float t) {
if (t == 0.0f || t == 1.0f)
return t;
if (t < 0.5f) if (t < 0.5f)
return 0.5f * powf(2.0f, (20.0f * t) - 10.0f); return 0.5f * powf(2.0f, (20.0f * t) - 10.0f);
@@ -239,14 +238,14 @@ glm_ease_back_inout(float t) {
x = 0.5; x = 0.5;
n = t / 0.5f; n = t / 0.5f;
if (n < 1) { if (n < 1.0f) {
z = ((s + 1) * n) - s; z = (s + 1) * n - s;
m = n * n * z; m = n * n * z;
return x * m; return x * m;
} }
n -= 2; n -= 2.0f;
z = ((s + 1) * n) + s; z = (s + 1.0f) * n + s;
m = (n * n * z) + 2; m = (n * n * z) + 2;
return x * m; return x * m;
@@ -272,10 +271,10 @@ glm_ease_elast_inout(float t) {
a = 2.0f * t; a = 2.0f * t;
if (t < 0.5f) if (t < 0.5f)
return 0.5f * sinf(13.0f * CGLM_PI_2 * (a)) return 0.5f * sinf(13.0f * CGLM_PI_2 * a)
* powf(2.0f, 10.0f * ((a) - 1.0f)); * powf(2.0f, 10.0f * (a - 1.0f));
return 0.5f * (sinf(-13.0f * CGLM_PI_2 * ((a - 1.0f) + 1.0f)) return 0.5f * (sinf(-13.0f * CGLM_PI_2 * a)
* powf(2.0f, -10.0f * (a - 1.0f)) + 2.0f); * powf(2.0f, -10.0f * (a - 1.0f)) + 2.0f);
} }