summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChunEon Park <hermet@hermet.pe.kr>2014-12-05 23:17:38 +0900
committerChunEon Park <hermet@hermet.pe.kr>2014-12-05 23:17:38 +0900
commit2e1032e28f0cd704ffaf28cea0b5ad533ae2b6c1 (patch)
tree1ad9d9eef77f3578a6aaed24b9ba3d12ceed7703
parentbcd7736914b5a7f78a5dc19330b738dc8e94f518 (diff)
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
-rw-r--r--src/lib/ecore/ecore_anim.c65
1 files changed, 7 insertions, 58 deletions
diff --git a/src/lib/ecore/ecore_anim.c b/src/lib/ecore/ecore_anim.c
index e248f05..3b8f987 100644
--- a/src/lib/ecore/ecore_anim.c
+++ b/src/lib/ecore/ecore_anim.c
@@ -308,69 +308,18 @@ _pos_map_spring(double pos,
308} 308}
309 309
310static double 310static double
311_cubic_bezier_a (double a1, double a2)
312{
313 return 1.0 - 3.0 * a2 + 3.0 * a1;
314}
315
316static double
317_cubic_bezier_b (double a1, double a2)
318{
319 return 3.0 * a2 - 6.0 * a1;
320}
321
322static double
323_cubic_bezier_c(double a1)
324{
325 return 3.0 * a1;
326}
327
328static double
329_cubic_bezier_calc(double t,
330 double a1,
331 double a2)
332{
333 return ((_cubic_bezier_a(a1, a2) * t +
334 _cubic_bezier_b(a1, a2)) * t +
335 _cubic_bezier_c(a1)) * t;
336}
337
338static double
339_cubic_bezier_slope_get(double t,
340 double a1,
341 double a2)
342{
343 return 3.0 * _cubic_bezier_a(a1, a2) * t * t +
344 2.0 * _cubic_bezier_b(a1, a2) * t +
345 _cubic_bezier_c(a1);
346}
347
348static double
349_cubic_bezier_t_get(double a,
350 double x1,
351 double x2)
352{
353 double guess_t = a;
354 for (int i = 0; i < 4; ++i)
355 {
356 double current_slope = _cubic_bezier_slope_get(a, x1, x2);
357 if (current_slope == 0.0)
358 return guess_t;
359 double current_x = _cubic_bezier_calc(guess_t, x1, x2) - a;
360 guess_t -= current_x / current_slope;
361 }
362 return guess_t;
363}
364
365static double
366_pos_map_cubic_bezier(double pos, 311_pos_map_cubic_bezier(double pos,
367 double x1, 312 double x1 EINA_UNUSED,
368 double y1, 313 double y1,
369 double x2, 314 double x2 EINA_UNUSED,
370 double y2) 315 double y2)
371{ 316{
372 if (x1 == y1 && x2 == y2) return pos; 317 if (x1 == y1 && x2 == y2) return pos;
373 return _cubic_bezier_calc(_cubic_bezier_t_get(pos, x1, x2), y1, y2); 318
319 /* Bezier Cubic formula:
320 y(t) = (1 - t)^3 + 3t(1 - t)^2 + 3t^2(1 - t) + t^3 */
321 return (pow((1 - pos), 3) * 0) + (3 * pos * pow((1 - pos), 2) * y1) +
322 (3 * pow(pos, 2) * (1 - pos) * y2) + (pow(pos, 3) * 1);
374} 323}
375 324
376#define DBL_TO(Fp) eina_f32p32_double_to(Fp) 325#define DBL_TO(Fp) eina_f32p32_double_to(Fp)