![]() |
![]() |
![]() |
Clutter 0.3 Reference Manual | ![]() |
---|---|---|---|---|
typedef ClutterFixed; #define CFX_Q #define CFX_ONE #define CFX_MAX #define CFX_MIN typedef ClutterAngle; #define CFX_PI #define CFX_2PI #define CFX_PI_2 #define CFX_PI_4 #define CFX_120 #define CFX_180 #define CFX_240 #define CFX_360 #define CFX_60 #define CFX_255 #define CFX_DIV #define CFX_INT #define CFX_MUL #define CFX_HALF #define CFX_QMUL (x,y) #define CLUTTER_FIXED_TO_FLOAT (x) #define CLUTTER_FIXED_TO_DOUBLE (x) #define CLUTTER_FLOAT_TO_FIXED (x) #define CLUTTER_FLOAT_TO_INT (x) #define CLUTTER_INT_TO_FIXED (x) #define CLUTTER_FIXED_INT (x) #define CLUTTER_FIXED_FRACTION (x) #define CLUTTER_FIXED_FLOOR (x) #define CLUTTER_FIXED_CEIL (x) #define CLUTTER_FIXED_MUL (x,y) #define CLUTTER_FIXED_DIV (x,y) #define CLUTTER_ANGLE_FROM_DEG (x) #define CLUTTER_ANGLE_FROM_DEGF (x) #define CLUTTER_ANGLE_FROM_DEGX (x) #define CLUTTER_ANGLE_TO_DEGF (x) #define clutter_cosi (angle) #define clutter_cosx (angle) ClutterFixed clutter_sini (ClutterAngle angle); ClutterFixed clutter_sinx (ClutterFixed angle); gint clutter_sqrti (gint x); ClutterFixed clutter_sqrtx (ClutterFixed x); ClutterFixed clutter_log2x (guint x); guint clutter_pow2x (ClutterFixed x); guint clutter_powx (guint x, ClutterFixed y); ClutterFixed clutter_qmulx (ClutterFixed op1, ClutterFixed op2); ClutterFixed clutter_tani (ClutterAngle angle);
Clutter has a fixed point API targeted at platforms without a floating point unit, such as embedded devices. This API should be preferred to the floating point one as it does not trigger the slow path of software emulation, relying on integer math for fixed-to-floating and floating-to-fixed conversion.
Basic rules of Fixed Point arithmethic:
Two fixed point numbers can be directly added and subtracted.
To add other numerical type to a fixed point number it has to be first converted to fixed point.
A fixed point number can be directly multiplied or divided by an integer.
Two fixed point numbers can only be multiplied and divided by the provided CLUTTER_FIXED_MUL and CLUTTER_FIXED_DIV macros.
typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */
Integer representation of an angle such that 1024 corresponds to full circle (i.e., 2*Pi).
#define CLUTTER_ANGLE_FROM_DEG(x) (CLUTTER_FLOAT_TO_INT ((x * 1024.0) / 360.0))
x : |
#define CLUTTER_ANGLE_FROM_DEGF(x) (CLUTTER_FLOAT_TO_INT (((float)x * 1024.0f) / 360.0f))
x : |
#define CLUTTER_ANGLE_FROM_DEGX(x) (CFX_INT(((x/360)*1024) + CFX_HALF))
x : |
#define clutter_cosi(angle) (clutter_sini ((angle) + 256))
Very fast fixed point implementation of cosine function.
ClutterAngle is an integer such that 1024 represents full circle.
angle : |
a ClutterAngle angle |
Since 0.2
#define clutter_cosx(angle) (clutter_sinx((angle) + CFX_PI_2))
Fixed point cosine function
angle : |
a ClutterFixed angle in radians |
Since 0.2
ClutterFixed clutter_sini (ClutterAngle angle);
Very fast fixed point implementation of sine function.
ClutterAngle is an integer such that 1024 represents full circle.
angle : |
a ClutterAngle |
Returns : | ClutterFixed sine value. |
Since 0.2
ClutterFixed clutter_sinx (ClutterFixed angle);
Fixed point implementation of sine function
angle : |
a ClutterFixed angle in radians |
Returns : | ClutterFixed sine value. |
Since 0.2
gint clutter_sqrti (gint x);
Very fast fixed point implementation of square root for integers.
This function is about 10x faster than clib sqrt()
on x86, and (this is
not a typo!) more than 800x faster on ARM without FPU. It's error is < 5%
for arguments < 132 and < 10% for arguments < 5591.
x : |
integer value |
Returns : | integer square root. |
Since 0.2
ClutterFixed clutter_sqrtx (ClutterFixed x);
A fixed point implementation of squre root
x : |
a ClutterFixed |
Returns : | ClutterFixed square root. |
Since 0.2
ClutterFixed clutter_log2x (guint x);
Calculates base 2 logarithm.
This function is some 2.5 times faster on x86, and over 12 times faster on
fpu-less arm, than using libc log()
.
x : |
value to calculate base 2 logarithm from |
Returns : | base 2 logarithm. |
Since 0.4
guint clutter_pow2x (ClutterFixed x);
Calculates 2 to x power.
This function is around 11 times faster on x86, and around 22 times faster on fpu-less arm than libc pow(2, x).
x : |
exponent |
Returns : | 2 in x power. |
Since 0.4
guint clutter_powx (guint x, ClutterFixed y);
Calculates x to y power. (Note, if x is a constant it will be faster to calculate the power as clutter_pow2x (CLUTTER_FIXED_MUL(y, log2 (x)))
x : |
base |
y : |
ClutterFixed exponent |
Returns : | x in y power. |
Since 0.4
ClutterFixed clutter_qmulx (ClutterFixed op1, ClutterFixed op2);
op1 : |
|
op2 : |
|
Returns : |
ClutterFixed clutter_tani (ClutterAngle angle);
Very fast fixed point implementation of tan function.
ClutterAngle is an integer such that 1024 represents full circle.
angle : |
a ClutterAngle |
Returns : | ClutterFixed sine value. |
Since 0.3