From 2e1032e28f0cd704ffaf28cea0b5ad533ae2b6c1 Mon Sep 17 00:00:00 2001 From: ChunEon Park Date: Fri, 5 Dec 2014 23:17:38 +0900 Subject: [PATCH] ecore/animator: fix the bezier cubic compuation. The previous compuation is totally wrong. Even it doesn't work correctly. (I have no idea what the orignal author was thinking?) Here we just need a simple and clear fomular to get the current progress frame. If i'm wrong, please ping me. @fix --- src/lib/ecore/ecore_anim.c | 65 ++++---------------------------------- 1 file changed, 7 insertions(+), 58 deletions(-) diff --git a/src/lib/ecore/ecore_anim.c b/src/lib/ecore/ecore_anim.c index e248f05901..3b8f98713d 100644 --- a/src/lib/ecore/ecore_anim.c +++ b/src/lib/ecore/ecore_anim.c @@ -307,70 +307,19 @@ _pos_map_spring(double pos, return _pos_map_sin((M_PI / 2.0) + (p2 * len)) * decay; } -static double -_cubic_bezier_a (double a1, double a2) -{ - return 1.0 - 3.0 * a2 + 3.0 * a1; -} - -static double -_cubic_bezier_b (double a1, double a2) -{ - return 3.0 * a2 - 6.0 * a1; -} - -static double -_cubic_bezier_c(double a1) -{ - return 3.0 * a1; -} - -static double -_cubic_bezier_calc(double t, - double a1, - double a2) -{ - return ((_cubic_bezier_a(a1, a2) * t + - _cubic_bezier_b(a1, a2)) * t + - _cubic_bezier_c(a1)) * t; -} - -static double -_cubic_bezier_slope_get(double t, - double a1, - double a2) -{ - return 3.0 * _cubic_bezier_a(a1, a2) * t * t + - 2.0 * _cubic_bezier_b(a1, a2) * t + - _cubic_bezier_c(a1); -} - -static double -_cubic_bezier_t_get(double a, - double x1, - double x2) -{ - double guess_t = a; - for (int i = 0; i < 4; ++i) - { - double current_slope = _cubic_bezier_slope_get(a, x1, x2); - if (current_slope == 0.0) - return guess_t; - double current_x = _cubic_bezier_calc(guess_t, x1, x2) - a; - guess_t -= current_x / current_slope; - } - return guess_t; -} - static double _pos_map_cubic_bezier(double pos, - double x1, + double x1 EINA_UNUSED, double y1, - double x2, + double x2 EINA_UNUSED, double y2) { if (x1 == y1 && x2 == y2) return pos; - return _cubic_bezier_calc(_cubic_bezier_t_get(pos, x1, x2), y1, y2); + + /* Bezier Cubic formula: + y(t) = (1 - t)^3 + 3t(1 - t)^2 + 3t^2(1 - t) + t^3 */ + return (pow((1 - pos), 3) * 0) + (3 * pos * pow((1 - pos), 2) * y1) + + (3 * pow(pos, 2) * (1 - pos) * y2) + (pow(pos, 3) * 1); } #define DBL_TO(Fp) eina_f32p32_double_to(Fp)