2006-08-29 15:09:43 -04:00
|
|
|
/*
|
|
|
|
* Clutter.
|
|
|
|
*
|
|
|
|
* An OpenGL based 'interactive canvas' library.
|
|
|
|
*
|
|
|
|
* Authored By Matthew Allum <mallum@openedhand.com>
|
2007-04-12 08:42:07 -04:00
|
|
|
* Tomas Frydrych <tf@openedhand.com>
|
2006-08-29 15:09:43 -04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006 OpenedHand
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _HAVE_CLUTTER_FIXED_H
|
|
|
|
#define _HAVE_CLUTTER_FIXED_H
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
2007-01-17 11:00:00 -05:00
|
|
|
/**
|
|
|
|
* ClutterFixed:
|
|
|
|
*
|
|
|
|
* Fixed point number (16.16)
|
|
|
|
*/
|
2006-08-29 15:09:43 -04:00
|
|
|
typedef gint32 ClutterFixed;
|
2007-01-17 11:00:00 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ClutterAngle:
|
|
|
|
*
|
2007-01-18 05:33:24 -05:00
|
|
|
* Integer representation of an angle such that 1024 corresponds to
|
2007-01-18 03:54:10 -05:00
|
|
|
* full circle (i.e., 2*Pi).
|
2007-01-17 11:00:00 -05:00
|
|
|
*/
|
2007-01-16 03:14:53 -05:00
|
|
|
typedef gint32 ClutterAngle; /* angle such that 1024 == 2*PI */
|
2006-08-29 15:09:43 -04:00
|
|
|
|
2007-07-11 03:16:21 -04:00
|
|
|
#define CLUTTER_ANGLE_FROM_DEG(x) (CLUTTER_FLOAT_TO_INT (((x) * 1024.0) / 360.0))
|
|
|
|
#define CLUTTER_ANGLE_FROM_DEGF(x) (CLUTTER_FLOAT_TO_INT (((float)(x) * 1024.0f) / 360.0f))
|
|
|
|
#define CLUTTER_ANGLE_FROM_DEGX(x) (CFX_INT((((x)/360)*1024) + CFX_HALF))
|
|
|
|
#define CLUTTER_ANGLE_TO_DEG(x) (((x) * 360.0)/ 1024.0)
|
|
|
|
#define CLUTTER_ANGLE_TO_DEGF(x) (((float)(x) * 360.0)/ 1024.0)
|
|
|
|
#define CLUTTER_ANGLE_TO_DEGX(x) (CLUTTER_INT_TO_FIXED((x) * 45)/128)
|
2007-05-25 08:07:24 -04:00
|
|
|
|
2007-08-07 07:35:22 -04:00
|
|
|
/*
|
|
|
|
* some commonly used constants
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CFX_Q:
|
|
|
|
*
|
|
|
|
* Size in bits of decimal part of floating point value.
|
|
|
|
*/
|
2007-01-15 13:37:12 -05:00
|
|
|
#define CFX_Q 16 /* Decimal part size in bits */
|
2007-08-07 07:35:22 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CFX_ONE:
|
|
|
|
*
|
|
|
|
* 1.0 represented as a fixed point value.
|
|
|
|
*/
|
2007-01-15 13:37:12 -05:00
|
|
|
#define CFX_ONE (1 << CFX_Q) /* 1 */
|
2007-08-07 07:35:22 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CFX_HALF:
|
|
|
|
*
|
|
|
|
* 0.5 represented as a fixed point value.
|
|
|
|
*/
|
2007-04-27 20:37:11 -04:00
|
|
|
#define CFX_HALF 32768
|
2007-08-07 07:35:22 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CFX_MAX:
|
|
|
|
*
|
|
|
|
* Maximum fixed point value.
|
|
|
|
*/
|
2007-01-15 13:37:12 -05:00
|
|
|
#define CFX_MAX 0x7fffffff
|
2007-01-16 05:39:18 -05:00
|
|
|
|
2007-08-07 07:35:22 -04:00
|
|
|
/**
|
|
|
|
* CFX_MIN:
|
|
|
|
*
|
|
|
|
* Minimum fixed point value.
|
2007-01-16 05:39:18 -05:00
|
|
|
*/
|
2007-08-07 07:35:22 -04:00
|
|
|
#define CFX_MIN 0x80000000
|
2007-01-17 11:00:00 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CFX_PI:
|
|
|
|
*
|
|
|
|
* Fixed point representation of Pi
|
|
|
|
*/
|
2007-01-15 13:37:12 -05:00
|
|
|
#define CFX_PI 0x0003243f
|
2007-01-17 11:00:00 -05:00
|
|
|
/**
|
|
|
|
* CFX_2PI:
|
|
|
|
*
|
|
|
|
* Fixed point representation of Pi*2
|
|
|
|
*/
|
2007-01-15 13:37:12 -05:00
|
|
|
#define CFX_2PI 0x0006487f
|
2007-01-17 11:00:00 -05:00
|
|
|
/**
|
2007-06-01 06:00:35 -04:00
|
|
|
* CFX_PI_2:
|
2007-01-17 11:00:00 -05:00
|
|
|
*
|
|
|
|
* Fixed point representation of Pi/2
|
|
|
|
*/
|
2007-01-15 13:37:12 -05:00
|
|
|
#define CFX_PI_2 0x00019220 /* pi/2 */
|
2007-01-17 11:00:00 -05:00
|
|
|
/**
|
2007-06-01 06:00:35 -04:00
|
|
|
* CFX_PI_4:
|
2007-01-17 11:00:00 -05:00
|
|
|
*
|
|
|
|
* Fixed point representation of Pi/4
|
|
|
|
*/
|
2007-01-15 13:37:12 -05:00
|
|
|
#define CFX_PI_4 0x0000c910 /* pi/4 */
|
2007-01-17 11:00:00 -05:00
|
|
|
/**
|
|
|
|
* CFX_360:
|
|
|
|
*
|
|
|
|
* Fixed point representation of the number 360
|
|
|
|
*/
|
2007-01-16 05:39:18 -05:00
|
|
|
#define CFX_360 CLUTTER_INT_TO_FIXED (360)
|
2007-01-17 11:00:00 -05:00
|
|
|
/**
|
|
|
|
* CFX_240:
|
|
|
|
*
|
|
|
|
* Fixed point representation of the number 240
|
|
|
|
*/
|
2007-01-16 05:39:18 -05:00
|
|
|
#define CFX_240 CLUTTER_INT_TO_FIXED (240)
|
2007-01-17 11:00:00 -05:00
|
|
|
/**
|
|
|
|
* CFX_180:
|
|
|
|
*
|
|
|
|
* Fixed point representation of the number 180
|
|
|
|
*/
|
2007-01-16 05:39:18 -05:00
|
|
|
#define CFX_180 CLUTTER_INT_TO_FIXED (180)
|
2007-01-17 11:00:00 -05:00
|
|
|
/**
|
|
|
|
* CFX_120:
|
|
|
|
*
|
|
|
|
* Fixed point representation of the number 120
|
|
|
|
*/
|
2007-01-16 05:39:18 -05:00
|
|
|
#define CFX_120 CLUTTER_INT_TO_FIXED (120)
|
2007-01-17 11:00:00 -05:00
|
|
|
/**
|
|
|
|
* CFX_60:
|
|
|
|
*
|
|
|
|
* Fixed point representation of the number 60
|
|
|
|
*/
|
2007-01-16 05:39:18 -05:00
|
|
|
#define CFX_60 CLUTTER_INT_TO_FIXED (60)
|
2007-01-17 11:00:00 -05:00
|
|
|
/**
|
|
|
|
* CFX_255:
|
|
|
|
*
|
|
|
|
* Fixed point representation of the number 255
|
|
|
|
*/
|
2007-01-17 08:03:52 -05:00
|
|
|
#define CFX_255 CLUTTER_INT_TO_FIXED (255)
|
2006-08-29 15:09:43 -04:00
|
|
|
|
2007-08-07 07:35:22 -04:00
|
|
|
/**
|
|
|
|
* CLUTTER_FIXED_TO_FLOAT:
|
2007-08-07 10:03:58 -04:00
|
|
|
* @x: a fixed point value
|
2007-08-07 07:35:22 -04:00
|
|
|
*
|
|
|
|
* Convert a fixed point value to float.
|
|
|
|
*/
|
2007-01-18 03:54:10 -05:00
|
|
|
#define CLUTTER_FIXED_TO_FLOAT(x) ((float) ((int)(x) / 65536.0))
|
2007-08-07 07:35:22 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CLUTTER_FIXED_TO_DOUBLE:
|
2007-08-07 10:03:58 -04:00
|
|
|
* @x: a fixed point value
|
2007-08-07 07:35:22 -04:00
|
|
|
*
|
|
|
|
* Convert a fixed point value to double.
|
|
|
|
*/
|
2007-01-18 03:54:10 -05:00
|
|
|
#define CLUTTER_FIXED_TO_DOUBLE(x) ((double) ((int)(x) / 65536.0))
|
2007-01-15 13:37:12 -05:00
|
|
|
|
2007-08-07 07:35:22 -04:00
|
|
|
/**
|
|
|
|
* CLUTTER_FLOAT_TO_FIXED:
|
2007-08-07 10:03:58 -04:00
|
|
|
* @x: a floating point value
|
2007-08-07 07:35:22 -04:00
|
|
|
*
|
|
|
|
* Convert a float value to fixed.
|
|
|
|
*/
|
2007-06-07 11:28:59 -04:00
|
|
|
#define CLUTTER_FLOAT_TO_FIXED(x) (_clutter_double_to_fixed ((x)))
|
2007-08-07 07:35:22 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CLUTTER_FLOAT_TO_INT:
|
2007-08-07 10:03:58 -04:00
|
|
|
* @x: a floating point value
|
2007-08-07 07:35:22 -04:00
|
|
|
*
|
|
|
|
* Convert a float value to int.
|
|
|
|
*/
|
2007-06-07 11:28:59 -04:00
|
|
|
#define CLUTTER_FLOAT_TO_INT(x) (_clutter_double_to_int ((x)))
|
2007-08-07 07:35:22 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CLUTTER_FLOAT_TO_UINT:
|
2007-08-07 10:03:58 -04:00
|
|
|
* @x: a floating point value
|
2007-08-07 07:35:22 -04:00
|
|
|
*
|
|
|
|
* Convert a float value to unsigned int.
|
|
|
|
*/
|
2007-07-04 11:30:44 -04:00
|
|
|
#define CLUTTER_FLOAT_TO_UINT(x) (_clutter_double_to_uint ((x)))
|
2006-08-29 15:09:43 -04:00
|
|
|
|
2007-08-07 07:35:22 -04:00
|
|
|
/**
|
|
|
|
* CLUTTER_INT_TO_FIXED:
|
2007-08-07 10:03:58 -04:00
|
|
|
* @x: an integer value
|
2007-08-07 07:35:22 -04:00
|
|
|
*
|
|
|
|
* Convert an integer value to fixed point.
|
|
|
|
*/
|
2007-06-07 11:28:59 -04:00
|
|
|
#define CLUTTER_INT_TO_FIXED(x) ((x) << CFX_Q)
|
2007-08-07 07:35:22 -04:00
|
|
|
|
2007-10-02 10:53:32 -04:00
|
|
|
/**
|
|
|
|
* CLUTTER_FIXED_TO_INT:
|
|
|
|
* @x: a fixed point value
|
|
|
|
*
|
|
|
|
* Converts a fixed point value to integer (removing the decimal part).
|
|
|
|
*
|
|
|
|
* Since: 0.6
|
|
|
|
*/
|
|
|
|
#define CLUTTER_FIXED_TO_INT(x) ((x) >> CFX_Q)
|
|
|
|
|
2007-08-07 07:35:22 -04:00
|
|
|
/**
|
|
|
|
* CLUTTER_FIXED_INT:
|
2007-08-07 10:03:58 -04:00
|
|
|
* @x: a fixed point value
|
2007-08-07 07:35:22 -04:00
|
|
|
*
|
|
|
|
* Convert a fixed point value to integer (removing decimal part).
|
2007-10-02 10:53:32 -04:00
|
|
|
*
|
|
|
|
* Deprecated:0.6: Use %CLUTTER_FIXED_TO_INT instead
|
2007-08-07 07:35:22 -04:00
|
|
|
*/
|
2007-10-02 10:53:32 -04:00
|
|
|
#define CLUTTER_FIXED_INT(x) CLUTTER_FIXED_TO_INT((x))
|
2007-08-07 07:35:22 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CLUTTER_FIXED_FRACTION:
|
2007-08-07 10:03:58 -04:00
|
|
|
* @x: a fixed point value
|
2007-08-07 07:35:22 -04:00
|
|
|
*
|
2007-10-02 10:53:32 -04:00
|
|
|
* Retrieves the fractionary part of a fixed point value
|
2007-08-07 07:35:22 -04:00
|
|
|
*/
|
2007-01-18 03:54:10 -05:00
|
|
|
#define CLUTTER_FIXED_FRACTION(x) ((x) & ((1 << CFX_Q) - 1))
|
2007-08-07 07:35:22 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CLUTTER_FIXED_FLOOR:
|
2007-08-07 10:03:58 -04:00
|
|
|
* @x: a fixed point value
|
2007-08-07 07:35:22 -04:00
|
|
|
*
|
|
|
|
* Round down a fixed point value to an integer.
|
|
|
|
*/
|
2007-01-18 03:54:10 -05:00
|
|
|
#define CLUTTER_FIXED_FLOOR(x) (((x) >= 0) ? ((x) >> CFX_Q) \
|
|
|
|
: ~((~(x)) >> CFX_Q))
|
2007-08-07 07:35:22 -04:00
|
|
|
/**
|
|
|
|
* CLUTTER_FIXED_CEIL:
|
2007-08-07 10:03:58 -04:00
|
|
|
* @x: a fixed point value
|
2007-08-07 07:35:22 -04:00
|
|
|
*
|
|
|
|
* Round up a fixed point value to an integer.
|
|
|
|
*/
|
2007-06-07 11:28:59 -04:00
|
|
|
#define CLUTTER_FIXED_CEIL(x) (CLUTTER_FIXED_FLOOR (x + 0xffff))
|
2006-08-29 15:09:43 -04:00
|
|
|
|
2007-08-07 07:35:22 -04:00
|
|
|
/**
|
|
|
|
* CLUTTER_FIXED_MUL:
|
2007-08-07 10:03:58 -04:00
|
|
|
* @x: a fixed point value
|
|
|
|
* @y: a fixed point value
|
2007-08-07 07:35:22 -04:00
|
|
|
*
|
|
|
|
* Multiply two fixed point values
|
|
|
|
*/
|
2007-01-18 03:54:10 -05:00
|
|
|
#define CLUTTER_FIXED_MUL(x,y) ((x) >> 8) * ((y) >> 8)
|
2006-08-29 15:09:43 -04:00
|
|
|
|
2007-08-07 07:35:22 -04:00
|
|
|
/**
|
2007-08-07 10:03:58 -04:00
|
|
|
* CLUTTER_FIXED_DIV:
|
|
|
|
* @x: a fixed point value
|
|
|
|
* @y: a fixed point value
|
2007-08-07 07:35:22 -04:00
|
|
|
*
|
2007-08-07 10:03:58 -04:00
|
|
|
* Divide two fixed point values
|
2007-08-07 07:35:22 -04:00
|
|
|
*/
|
|
|
|
#define CLUTTER_FIXED_DIV(x,y) ((((x) << 8)/(y)) << 8)
|
2007-01-17 11:00:00 -05:00
|
|
|
|
2007-08-07 07:35:22 -04:00
|
|
|
/* Some handy fixed point short aliases to avoid exessively long lines */
|
|
|
|
/* FIXME: Remove from public API */
|
2007-06-07 11:28:59 -04:00
|
|
|
#define CFX_INT CLUTTER_FIXED_INT
|
|
|
|
#define CFX_MUL CLUTTER_FIXED_MUL
|
|
|
|
#define CFX_DIV CLUTTER_FIXED_DIV
|
2007-06-12 07:42:29 -04:00
|
|
|
#define CFX_QMUL(x,y) clutter_qmulx (x,y)
|
2007-01-16 05:39:18 -05:00
|
|
|
|
2007-01-15 13:37:12 -05:00
|
|
|
/* Fixed point math routines */
|
2007-03-29 06:41:23 -04:00
|
|
|
extern inline
|
|
|
|
ClutterFixed clutter_qmulx (ClutterFixed op1, ClutterFixed op2);
|
|
|
|
|
2007-01-17 08:51:14 -05:00
|
|
|
ClutterFixed clutter_sinx (ClutterFixed angle);
|
2007-01-17 08:03:52 -05:00
|
|
|
ClutterFixed clutter_sini (ClutterAngle angle);
|
2007-01-16 03:14:53 -05:00
|
|
|
|
2007-03-29 06:41:23 -04:00
|
|
|
ClutterFixed clutter_tani (ClutterAngle angle);
|
|
|
|
|
2007-01-16 03:14:53 -05:00
|
|
|
/* convenience macros for the cos functions */
|
2007-01-17 11:00:00 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_cosx:
|
|
|
|
* @angle: a #ClutterFixed angle in radians
|
|
|
|
*
|
|
|
|
* Fixed point cosine function
|
|
|
|
*
|
|
|
|
* Return value: #ClutterFixed cosine value.
|
|
|
|
*
|
|
|
|
* Note: Implemneted as a macro.
|
|
|
|
*
|
|
|
|
* Since: 0.2
|
|
|
|
*/
|
2007-06-25 09:43:13 -04:00
|
|
|
#define clutter_cosx(angle) (clutter_sinx((angle) + CFX_PI_2))
|
2007-01-17 11:00:00 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_cosi:
|
|
|
|
* @angle: a #ClutterAngle angle
|
|
|
|
*
|
|
|
|
* Very fast fixed point implementation of cosine function.
|
|
|
|
*
|
|
|
|
* ClutterAngle is an integer such that 1024 represents
|
|
|
|
* full circle.
|
|
|
|
*
|
|
|
|
* Return value: #ClutterFixed cosine value.
|
|
|
|
*
|
|
|
|
* Note: Implemneted as a macro.
|
|
|
|
*
|
|
|
|
* Since: 0.2
|
|
|
|
*/
|
2007-06-07 11:28:59 -04:00
|
|
|
#define clutter_cosi(angle) (clutter_sini ((angle) + 256))
|
2007-01-17 08:03:52 -05:00
|
|
|
|
|
|
|
ClutterFixed clutter_sqrtx (ClutterFixed x);
|
2007-01-17 08:51:14 -05:00
|
|
|
gint clutter_sqrti (gint x);
|
2007-01-15 13:37:12 -05:00
|
|
|
|
2007-05-17 03:09:18 -04:00
|
|
|
ClutterFixed clutter_log2x (guint x);
|
|
|
|
guint clutter_pow2x (ClutterFixed x);
|
|
|
|
guint clutter_powx (guint x, ClutterFixed y);
|
2007-01-19 11:04:06 -05:00
|
|
|
|
|
|
|
/* <private> */
|
|
|
|
extern inline
|
|
|
|
ClutterFixed _clutter_double_to_fixed (double value);
|
|
|
|
|
|
|
|
extern inline
|
2007-05-31 05:29:12 -04:00
|
|
|
gint _clutter_double_to_int (double value);
|
2007-01-19 11:04:06 -05:00
|
|
|
|
2007-07-04 11:30:44 -04:00
|
|
|
extern inline
|
|
|
|
guint _clutter_double_to_uint (double value);
|
|
|
|
|
2006-08-29 15:09:43 -04:00
|
|
|
G_END_DECLS
|
|
|
|
|
2007-06-07 11:28:59 -04:00
|
|
|
#endif /* _HAVE_CLUTTER_FIXED_H */
|