From 6e39efb9aaa1ed87b7320736ab08aabdbda4e4e1 Mon Sep 17 00:00:00 2001 From: Tomas Frydrych Date: Tue, 29 May 2007 09:21:18 +0000 Subject: [PATCH] fixed clutter cos functions; fixed tilt calculations in elliptic path --- ChangeLog | 15 +++++++++++ clutter/clutter-behaviour-ellipse.c | 41 +++++++++++++---------------- clutter/clutter-fixed.h | 4 +-- examples/behave.c | 2 +- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index af3fa1b85..78d4f5fb4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2007-05-29 Tomas Frydrych + + * clutter/clutter-fixed.h: + (clutter_cosx): + (clutter_cosi): + Fixed wrong sign in cos -> sin tranformation. + + * clutter/clutter-behaviour-ellipse.c: + (clutter_behaviour_ellipse_advance): + Replaced coordinace calculation for tilted ellipse with a sane + algorithm. + + * examples/behave.c: + Added tilt parameter to the example ellptic path. + 2007-05-29 Tomas Frydrych * clutter/cogl/gles/cogl.c: diff --git a/clutter/clutter-behaviour-ellipse.c b/clutter/clutter-behaviour-ellipse.c index bb1bef93c..f11a0ee9f 100644 --- a/clutter/clutter-behaviour-ellipse.c +++ b/clutter/clutter-behaviour-ellipse.c @@ -111,33 +111,30 @@ clutter_behaviour_ellipse_advance (ClutterBehaviourEllipse * e, if (e->priv->angle_tilt) { - /* Problem: sqrti is not giving us sufficient precission here - * and ClutterFixed range is too small to hold x^2+y^2 even for - * reasonable x, y values. + /* + * x2 = r * cos (angle + tilt) + * y2 = r * sin (angle + tilt) + * + * These can be trasformed to the formulas below using properties of + * sin (a + b) and cos (a + b) * - * We take advantage of sqrt (a * b^2) == sqrt (a) * b, - * and divide repeatedly by 4 until we get it into range, and then - * multiply the result by 2 the same number of times. */ - ClutterFixed r; - guint q = x*x + y*y; - gint shift = 0; + ClutterFixed x2, y2; - while (q > G_MAXINT16) - { - ++shift; - - q >>= 2; - } + x2 = x * clutter_cosi (e->priv->angle_tilt) - + y * clutter_sini (e->priv->angle_tilt); - r = clutter_sqrtx (CLUTTER_INT_TO_FIXED (q)) << shift; - - x = CFX_INT (CFX_MUL (r, clutter_cosi (angle + e->priv->angle_tilt))); - y = CFX_INT (CFX_MUL (r, clutter_sini (angle + e->priv->angle_tilt))); + y2 = y * clutter_cosi (e->priv->angle_tilt) + + x * clutter_sini (e->priv->angle_tilt); + + knot->x = CFX_INT (x2); + knot->y = CFX_INT (y2); + } + else + { + knot->x = x; + knot->y = y; } - - knot->x = x; - knot->y = y; #if 0 g_debug ("advancing to angle %d [%d, %d] (a: %d, b: %d)", diff --git a/clutter/clutter-fixed.h b/clutter/clutter-fixed.h index 10bdfd659..d252bd3e9 100644 --- a/clutter/clutter-fixed.h +++ b/clutter/clutter-fixed.h @@ -171,7 +171,7 @@ ClutterFixed clutter_tani (ClutterAngle angle); * * Since: 0.2 */ -#define clutter_cosx(angle) clutter_fixed_sin((angle) - CFX_PI_2) +#define clutter_cosx(angle) clutter_fixed_sin((angle) + CFX_PI_2) /** * clutter_cosi: @@ -188,7 +188,7 @@ ClutterFixed clutter_tani (ClutterAngle angle); * * Since: 0.2 */ -#define clutter_cosi(angle) clutter_sini((angle) - 256) +#define clutter_cosi(angle) clutter_sini((angle) + 256) ClutterFixed clutter_sqrtx (ClutterFixed x); gint clutter_sqrti (gint x); diff --git a/examples/behave.c b/examples/behave.c index 31a74bd6b..87718fa22 100644 --- a/examples/behave.c +++ b/examples/behave.c @@ -166,7 +166,7 @@ main (int argc, char *argv[]) case PATH_ELLIPSE: p_behave = clutter_behaviour_ellipse_new (alpha, 200, 200, 400, 300, - 0.0, 360.0, 0.0); + 0.0, 360.0, 120.0); break; case PATH_BSPLINE: