pluged clutter_fixed_sin into clutter-alpha; updated change log
authorTomas Frydrych <tf@openedhand.com>
Mon, 15 Jan 2007 19:43:09 +0000 (19:43 +0000)
committerTomas Frydrych <tf@openedhand.com>
Mon, 15 Jan 2007 19:43:09 +0000 (19:43 +0000)
ChangeLog
clutter/clutter-alpha.c
clutter/clutter-fixed.c

index 22cc99c..312db8b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-01-15  Tomas Frydrych  <tf@openedhand.com>
+       
+       * clutter/clutter-fixed.h: (CLUTTER_FIXED_TO_DOUBLE/FLOAT):
+       Fixed macro so it works for negative values.
+       * clutter/clutter-fixed.c: (clutter_fixed_sin):
+       Implemented fixed point sin function.
+       * clutter/clutter-alpha.c: (clutter_sin_func, clutter_sin_inc_func):
+       Pluged in fixed point sin function.
+       
 2007-01-07  Matthew Allum  <mallum@openedhand.com>
 
        * clutter/clutter-actor.c: (clutter_actor_allocate_coords):
index 0a436cf..fe0e4f6 100644 (file)
@@ -493,9 +493,26 @@ clutter_ramp_func (ClutterAlpha *alpha,
 
 static guint32
 sincx_func (ClutterAlpha *alpha, 
-          float         angle,
-          float         offset)
+           ClutterFixed  angle,
+           ClutterFixed  offset)
 {
+  ClutterTimeline *timeline;
+  gint current_frame_num, n_frames;
+  ClutterFixed x, sine;
+  
+  timeline = clutter_alpha_get_timeline (alpha);
+
+  current_frame_num = clutter_timeline_get_current_frame (timeline);
+  n_frames = clutter_timeline_get_n_frames (timeline);
+
+  x = angle * current_frame_num / n_frames;
+  x = CLUTTER_FIXED_MUL (x, CFX_PI) - CLUTTER_FIXED_DIV (CFX_PI, angle);
+
+  sine = (clutter_fixed_sin (x) + offset)/2;
+
+  CLUTTER_NOTE (ALPHA, "sine: %2f\n", CLUTTER_FIXED_TO_DOUBLE (sine));
+
+  return CLUTTER_FIXED_INT (sine * CLUTTER_ALPHA_MAX_ALPHA);
 }
 
 static guint32
@@ -538,7 +555,11 @@ guint32
 clutter_sine_func (ClutterAlpha *alpha,
                    gpointer      dummy)
 {
+#if 0
   return sinc_func (alpha, 2.0, 1.0);
+#else
+  return sincx_func (alpha, CLUTTER_INT_TO_FIXED (2), CFX_ONE);
+#endif
 }
 
 /**
@@ -557,5 +578,9 @@ guint32
 clutter_sine_inc_func (ClutterAlpha *alpha,
                       gpointer      dummy)
 {
+#if 0
   return sinc_func (alpha, 0.5, 1.0);
+#else
+  return sincx_func (alpha, CFX_ONE / 2, CFX_ONE);
+#endif
 }
index 2028b48..8c09ffc 100644 (file)
@@ -83,49 +83,60 @@ static ClutterFixed sin_tbl [] =
  */
 #define CFX_SIN_STEP 0x00000192
 
+
+/**
+ * clutter_fixed_sin:
+ * @angle: a #ClutterAlpha
+ *
+ * Fixed point implementation of sine function
+ * Return value: sine value (as fixed point).
+ *
+ * Since: 0.2
+ */
 ClutterFixed
-clutter_fixed_sin (ClutterFixed anx)
+clutter_fixed_sin (ClutterFixed angle)
 {
+    int sign = 1, indx1, indx2;
+    ClutterFixed low, high, d1, d2;
+    
     /* reduce to <0, 2*pi) */
-    if (anx >= CFX_2PI)
+    if (angle >= CFX_2PI)
     {
-       ClutterFixed f = CLUTTER_FIXED_DIV (anx, CFX_2PI);
-       anx = anx - f;
+       ClutterFixed f = CLUTTER_FIXED_DIV (angle, CFX_2PI);
+       angle = angle - f;
     }
 
     /* reduce to first quadrant and sign */
-    int sign = 1;
-
-    if (anx > CFX_PI)
+    if (angle > CFX_PI)
     {
        sign = -1;
-       if (anx > CFX_PI + CFX_PI_2)
+       if (angle > CFX_PI + CFX_PI_2)
        {
            /* fourth qudrant */
-           anx = CFX_2PI - anx;
+           angle = CFX_2PI - angle;
        }
        else
        {
            /* third quadrant */
-           anx -= CFX_PI;
+           angle -= CFX_PI;
        }
     }
     else
     {
-       if (anx > CFX_PI_2)
+       if (angle > CFX_PI_2)
        {
            /* second quadrant */
-           anx = CFX_PI - anx;
+           angle = CFX_PI - angle;
        }
     }
 
-    /* Calculate indexes of the two nearest values in our table
+    /* Calculate indices of the two nearest values in our table
      * and return weighted average
      *
      * Handle the end of the table gracefully
      */
-    int indx1 = CLUTTER_FIXED_DIV (anx, CFX_SIN_STEP);
-    int indx2;
+    indx1 = CLUTTER_FIXED_DIV (angle, CFX_SIN_STEP);
+    indx2;
     
     indx1 = CLUTTER_FIXED_INT (indx1);
 
@@ -139,16 +150,16 @@ clutter_fixed_sin (ClutterFixed anx)
        indx2 = indx1 + 1;
     }
     
-    ClutterFixed low  = sin_tbl[indx1];
-    ClutterFixed high = sin_tbl[indx2];
+    low  = sin_tbl[indx1];
+    high = sin_tbl[indx2];
 
-    ClutterFixed d1 = anx - indx1 * CFX_SIN_STEP;
-    ClutterFixed d2 = indx2 * CFX_SIN_STEP - anx;
+    d1 = angle - indx1 * CFX_SIN_STEP;
+    d2 = indx2 * CFX_SIN_STEP - angle;
 
-    anx = ((low * d2 + high * d1) / (CFX_SIN_STEP));
+    angle = ((low * d2 + high * d1) / (CFX_SIN_STEP));
 
     if (sign < 0)
-       anx = (1 + ~anx);
+       angle = (1 + ~angle);
     
-    return anx;
+    return angle;
 }