[Bf-blender-cvs] [9b39a717937] master: Fix T62958: Improve exponential easing formula

Jacques Lucke noreply at git.blender.org
Tue Mar 26 15:45:06 CET 2019


Commit: 9b39a7179372d0360021a9d2e88190f17f34b29e
Author: Jacques Lucke
Date:   Tue Mar 26 15:43:51 2019 +0100
Branches: master
https://developer.blender.org/rB9b39a7179372d0360021a9d2e88190f17f34b29e

Fix T62958: Improve exponential easing formula

Reviewers: brecht

Differential Revision: https://developer.blender.org/D4596

===================================================================

M	source/blender/blenlib/intern/easing.c

===================================================================

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)



More information about the Bf-blender-cvs mailing list