Main Page   Namespace List   Alphabetical List   Data Structures   File List   Data Fields   Globals  

macros.h

Go to the documentation of this file.
00001 
00002 //                          macros.h                                      //
00003 //                         ----------                                     //
00004 //    begin                : Tue Nov 25 2003                              //
00005 //    copyright            : (C) 2003 by cbaudry (CEA/DSM/DAPNIA/SPP)     //
00006 //    email                : cedric.baudry@tremplin-utc.fr                //
00008 
00010 //                                                                        //
00011 //   This program is free software; you can redistribute it and/or modify //
00012 //   it under the terms of the GNU General Public License as published by //
00013 //   the Free Software Foundation, version 2 of the License               //
00014 //                                                                        //
00016 
00017 #pragma once
00018 
00019 /*
00020     As macro instructions are always inline, they're faster than functions (neither function call nor
00021     context changing).
00022     Include this file at last to avoid skipping other more important macro definitions.
00023     
00024 
00025 #defines:
00026     pi                 - with 20 decimals just for fun
00027     AND, OR, NOT       - logical (not bitwise) operators
00028 
00029   macros:
00030     GLERROR            - prints gl errors to stdout
00031     DEBUG              - prints info to stdout
00032     MIN, MAX           - min and max of two values
00033     IMIN, IMAX         - index of the min or max
00034     ABS                - absolute value
00035     TEST_BIT(x,b)      - checks if bit 'b' of x is set
00036     SET_BIT(x,b)       - sets bit 'b' of x
00037     CLEAR_BIT(x,b)     - clears bit 'b' of x
00038     TOGGLE_BIT(x,b)    - toggles bit 'b' of x
00039     flushout           - short for fflush(stdout)
00040     flusherr           - short for fflush(stderr)
00041     randf              - returns a random value between 0 and 1
00042     SIGN(x)            - returns 1 for positive, -1 for negative
00043     DEG2RAD, RAD2DEG   - radian-degree conversion
00044     CLAMP(x,lo,hi)     - clamps x to the interval (lo,hi)
00045 
00046 */
00047 
00048 #ifndef PI
00049 
00050   #define PI 3.14159265358979323846
00051 #endif
00052 
00053 
00054 #ifndef DEBUG
00055 
00056   #define verbose 1
00057   #define DEBUG                   if (verbose) printf
00058 #endif
00059 
00064 #define GLERROR                                                    \
00065     {                                                              \
00066         GLenum code = glGetError();                                \
00067         while (code!=GL_NO_ERROR)                                  \
00068         {                                                          \
00069             printf("Gl error: %s\n",(char *) gluErrorString(code));\
00070                 code = glGetError();                               \
00071         }                                                          \
00072     }
00073 
00074 
00075 /* boolean tests */
00076 #ifndef AND
00077   #define AND &&
00078   #define OR  ||
00079   #define NOT !
00080 #endif
00081 
00082 
00083 #ifndef MAX
00084 
00085   #define MAX(a,b)  ((a)>(b) ? (a) : (b))
00086 
00087   #define MIN(a,b)  ((a)<(b) ? (a) : (b))
00088 #endif
00089 
00090 
00091 #ifndef IMAX
00092 
00093   #define IMAX(a,b)  ((a)>(b) ? (0) : (1))
00094 
00095   #define IMIN(a,b)  ((a)<(b) ? (0) : (1))
00096 #endif
00097 
00098 #ifndef ABS
00099 
00100   #define ABS(a) ((a)>=0 ? (a) : (-(a)))
00101 #endif
00102 
00103 /*  bit comparisons and operations */
00104 #ifndef TEST_BIT
00105   #define TEST_BIT( x, b )   (((x) & (1<<(b))) != 0 )
00106   #define SET_BIT( x, b )    ((x) |= (1 << (b)))
00107   #define CLEAR_BIT( x, b )  ((x) &= ~(1 << (b)))
00108   #define TOGGLE_BIT( x, b ) ((TEST_BIT(x,b))?(CLEAR_BIT(x,b)):(SET_BIT(x,b)))
00109 #endif
00110 
00111 
00112 #ifndef flushout
00113 
00114   #define flushout fflush(stdout)
00115 
00116   #define flusherr fflush(stderr)
00117 #endif
00118 
00119 
00120 #ifndef randf
00121 
00124   #define randf()  ((float) rand() / (float)RAND_MAX )
00125 #endif
00126 
00127 
00128 #ifndef SIGN
00129 
00130   #define SIGN(x) ((x)>=0 ?  1  :  -1)
00131 #endif
00132 
00133 
00134 #ifndef DEG2RAD
00135 
00136   #define DEG2RAD(x) ((x)/180.0*pi)
00137 
00138   #define RAD2DEG(x) ((x)/pi*180.0)
00139 #endif
00140 
00141 
00142 #ifndef CLAMP
00143 
00144   #define CLAMP(x,lo,hi)  {if ((x) < (lo)) {(x)=(lo);} else if((x) > (hi)){(x)=(hi);}}
00145 #endif
00146 
00147 

Generated on Wed Feb 18 16:32:50 2004 for POVAMA by doxygen1.2.18