Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

glui_internal.h

Go to the documentation of this file.
00001 #ifndef GLUI_INTERNAL_H
00002 #define GLUI_INTERNAL_H
00003 
00004 #include <cstdio>
00005 #include <cmath>
00006 
00007 #ifndef AND
00008 #define AND &&
00009 #define OR  ||
00010 #define NOT !
00011 #endif
00012 
00013 #ifndef MAX
00014 #define MAX(a,b)  ((a)>(b) ? (a) : (b))
00015 #define MIN(a,b)  ((a)<(b) ? (a) : (b))
00016 #endif
00017 
00018 #ifndef ABS
00019 #define ABS(a) ((a)>=0 ? (a) : (-(a)))
00020 #endif
00021 
00022 /********************  bit comparisons and operations ***************/
00023 #ifndef TEST_BIT
00024 #define TEST_BIT( x, b )   (((x) & (1<<(b))) != 0 )
00025 #define SET_BIT( x, b )    ((x) |= (1 << (b)))
00026 #define CLEAR_BIT( x, b )  ((x) &= ~(1 << (b)))
00027 #define TOGGLE_BIT( x, b ) ((TEST_BIT(x,b)) ?(CLEAR_BIT(x,b)):(SET_BIT(x,b)))
00028 #endif
00029 
00030 #ifndef TEST_AND
00031 #define TEST_AND( a, b ) ((a&b)==b)
00032 #endif
00033 
00034 
00035 #ifndef M_PI
00036 #define M_PI 3.141592654
00037 #endif
00038 
00039 /*********** flush the stdout and stderr output streams *************/
00040 #ifndef flushout
00041 #define flushout fflush(stdout)
00042 #define flusherr fflush(stderr)
00043 #endif
00044 
00045 /********** Debugging functions *************************************/
00046 #ifndef error_return
00047 #define error_return( c ); {fprintf(stderr,c);return;}
00048 #endif
00049 
00050 /************************* floating-point random ********************/
00051 #ifndef randf
00052 #define randf()  ((float) rand() / (float)RAND_MAX )
00053 #endif
00054 
00055 #ifndef SIGN
00056 #define SIGN(x) ((x)>=0 ?  1  :  -1)
00057 #endif
00058 
00059 /****************** conversion between degrees and radians **********/
00060 #ifndef DEG2RAD
00061 #define DEG2RAD(x) ((x)/180.0*M_PI)
00062 #define RAD2DEG(x) ((x)/M_PI*180.0)
00063 #endif
00064 
00065 /***************** clamp a value to some fixed interval *************/
00066 #ifndef CLAMP
00067 #define CLAMP(x,lo,hi)  {if ((x) < (lo)) {(x)=(lo);} else if((x) > (hi)) {(x)=(hi);}}
00068 #endif
00069 
00070 /************ check if a value lies within a closed interval *********/
00071 #ifndef IN_BOUNDS
00072 #define IN_BOUNDS( x, lo, hi ) ( (x) >= (lo) AND (x) <= (hi) )
00073 #endif
00074 
00075 /************ check if a 2D point lies within a 2D box ***************/
00076 #ifndef PT_IN_BOX
00077 #define PT_IN_BOX( x, y, lo_x, hi_x, lo_y, hi_y ) \
00078 ( IN_BOUNDS(x,lo_x,hi_x) AND IN_BOUNDS(y,lo_y,hi_y) )
00079 #endif
00080 
00081 /****** check if value lies on proper side of another value     *****/
00082 /*** if side is positive => proper side is positive, else negative **/
00083 #ifndef CHECK_PROPER_SIDE
00084 #define CHECK_PROPER_SIDE(x,val,side) ((side) > 0 ? (x) > (val) : (x) < (val))
00085 #endif
00086 
00087 
00088 /***** Small value when we want to do a comparison to 'close to zero' *****/
00089 #ifndef FUDGE
00090 #define FUDGE .00001
00091 #endif
00092 
00093 
00094 /******************* swap two values, using a temp variable *********/
00095 #ifndef SWAP2
00096 #define SWAP2(a,b,t) {t=a;a=b;b=t;}     
00097 #endif
00098 
00099 #define VEC3_TO_ARRAY(v,a)  a[0]=v[0], a[1]=v[1], a[2]=v[2]
00100 
00101 /**** Return the ASCII control code given the non-control ASCII character */
00102 #define CTRL(c) ( (c>=('a'-1)) ? (c-'a'+1) : (c-'A'+1) )
00103 
00104 
00105 #endif /* GLUI_INTERNAL_H */

Generated on Fri Sep 15 17:51:57 2006 for GLUI by doxygen 1.3.6