diff options
author | Jacques Lucke <mail@jlucke.com> | 2019-03-26 17:43:51 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2019-03-26 17:43:51 +0300 |
commit | 9b39a7179372d0360021a9d2e88190f17f34b29e (patch) | |
tree | 3c22e3a1fc5936e2626a2570ad683c2c9114f124 /source/blender/blenlib/intern/easing.c | |
parent | 16a04dccd556d2969e0868aa91667449deae90d2 (diff) |
Fix T62958: Improve exponential easing formula
Reviewers: brecht
Differential Revision: https://developer.blender.org/D4596
Diffstat (limited to 'source/blender/blenlib/intern/easing.c')
-rw-r--r-- | source/blender/blenlib/intern/easing.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/source/blender/blenlib/intern/easing.c b/source/blender/blenlib/intern/easing.c index 07765276537..b1df6e4c58e 100644 --- a/source/blender/blenlib/intern/easing.c +++ b/source/blender/blenlib/intern/easing.c @@ -249,26 +249,37 @@ float BLI_easing_elastic_ease_in_out(float time, float begin, float change, floa } } +static const float pow_min = 0.0009765625f; /* = 2^(-10) */ +static const float pow_scale = 1.0f / (1.0f - 0.0009765625f); + float BLI_easing_expo_ease_in(float time, float begin, float change, float duration) { - return (time == 0.0f) ? begin : change * powf(2, 10 * (time / duration - 1)) + begin; + if (time == 0.0) { + return begin; + } + return change * (powf(2, 10 * (time / duration - 1)) - pow_min) * pow_scale + begin; } float BLI_easing_expo_ease_out(float time, float begin, float change, float duration) { - return (time == duration) ? begin + change : change * (-powf(2, -10 * time / duration) + 1) + begin; + if (time == 0.0) { + return begin; + } + return change * (1 - (powf(2, -10 * time / duration) - pow_min) * pow_scale) + begin; } float BLI_easing_expo_ease_in_out(float time, float begin, float change, float duration) { - if (time == 0.0f) - return begin; - if (time == duration) - return begin + change; - if ((time /= duration / 2) < 1) - return change / 2 * powf(2, 10 * (time - 1)) + begin; - time -= 1.0f; - return change / 2 * (-powf(2, -10 * time) + 2) + begin; + float duration_half = duration / 2.0f; + float change_half = change / 2.0f; + if (time <= duration_half) { + return BLI_easing_expo_ease_in( + time, begin, change_half, duration_half); + } + else { + return BLI_easing_expo_ease_out( + time - duration_half, begin + change_half, change_half, duration_half); + } } float BLI_easing_linear_ease(float time, float begin, float change, float duration) |