pluged clutter_fixed_sin into clutter-alpha; updated change log

This commit is contained in:
Tomas Frydrych 2007-01-15 19:43:09 +00:00
parent 95840c47bf
commit 44a89898ca
3 changed files with 69 additions and 24 deletions

View File

@ -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> 2007-01-07 Matthew Allum <mallum@openedhand.com>
* clutter/clutter-actor.c: (clutter_actor_allocate_coords): * clutter/clutter-actor.c: (clutter_actor_allocate_coords):

View File

@ -493,9 +493,26 @@ clutter_ramp_func (ClutterAlpha *alpha,
static guint32 static guint32
sincx_func (ClutterAlpha *alpha, sincx_func (ClutterAlpha *alpha,
float angle, ClutterFixed angle,
float offset) 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 static guint32
@ -538,7 +555,11 @@ guint32
clutter_sine_func (ClutterAlpha *alpha, clutter_sine_func (ClutterAlpha *alpha,
gpointer dummy) gpointer dummy)
{ {
#if 0
return sinc_func (alpha, 2.0, 1.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, clutter_sine_inc_func (ClutterAlpha *alpha,
gpointer dummy) gpointer dummy)
{ {
#if 0
return sinc_func (alpha, 0.5, 1.0); return sinc_func (alpha, 0.5, 1.0);
#else
return sincx_func (alpha, CFX_ONE / 2, CFX_ONE);
#endif
} }

View File

@ -83,49 +83,60 @@ static ClutterFixed sin_tbl [] =
*/ */
#define CFX_SIN_STEP 0x00000192 #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 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) */ /* reduce to <0, 2*pi) */
if (anx >= CFX_2PI) if (angle >= CFX_2PI)
{ {
ClutterFixed f = CLUTTER_FIXED_DIV (anx, CFX_2PI); ClutterFixed f = CLUTTER_FIXED_DIV (angle, CFX_2PI);
anx = anx - f; angle = angle - f;
} }
/* reduce to first quadrant and sign */ /* reduce to first quadrant and sign */
int sign = 1; if (angle > CFX_PI)
if (anx > CFX_PI)
{ {
sign = -1; sign = -1;
if (anx > CFX_PI + CFX_PI_2) if (angle > CFX_PI + CFX_PI_2)
{ {
/* fourth qudrant */ /* fourth qudrant */
anx = CFX_2PI - anx; angle = CFX_2PI - angle;
} }
else else
{ {
/* third quadrant */ /* third quadrant */
anx -= CFX_PI; angle -= CFX_PI;
} }
} }
else else
{ {
if (anx > CFX_PI_2) if (angle > CFX_PI_2)
{ {
/* second quadrant */ /* 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 * and return weighted average
* *
* Handle the end of the table gracefully * Handle the end of the table gracefully
*/ */
int indx1 = CLUTTER_FIXED_DIV (anx, CFX_SIN_STEP); indx1 = CLUTTER_FIXED_DIV (angle, CFX_SIN_STEP);
int indx2; indx2;
indx1 = CLUTTER_FIXED_INT (indx1); indx1 = CLUTTER_FIXED_INT (indx1);
@ -139,16 +150,16 @@ clutter_fixed_sin (ClutterFixed anx)
indx2 = indx1 + 1; indx2 = indx1 + 1;
} }
ClutterFixed low = sin_tbl[indx1]; low = sin_tbl[indx1];
ClutterFixed high = sin_tbl[indx2]; high = sin_tbl[indx2];
ClutterFixed d1 = anx - indx1 * CFX_SIN_STEP; d1 = angle - indx1 * CFX_SIN_STEP;
ClutterFixed d2 = indx2 * CFX_SIN_STEP - anx; 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) if (sign < 0)
anx = (1 + ~anx); angle = (1 + ~angle);
return anx; return angle;
} }