Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Extras / glui / glui_internal.h
1 #ifndef GLUI_INTERNAL_H
2 #define GLUI_INTERNAL_H
3
4 #include <cstdio>
5 #include <cmath>
6
7
8
9 #ifndef AND
10 #define AND &&
11 #define OR  ||
12 #define NOT !
13 #endif
14
15 #ifndef MAX
16 #define MAX(a,b)  ((a)>(b) ? (a) : (b))
17 #define MIN(a,b)  ((a)<(b) ? (a) : (b))
18 #endif
19
20 #ifndef ABS
21 #define ABS(a) ((a)>=0 ? (a) : (-(a)))
22 #endif
23
24 /********************  bit comparisons and operations ***************/
25 #ifndef TEST_BIT
26 #define TEST_BIT( x, b )   (((x) & (1<<(b))) != 0 )
27 #define SET_BIT( x, b )    ((x) |= (1 << (b)))
28 #define CLEAR_BIT( x, b )  ((x) &= ~(1 << (b)))
29 #define TOGGLE_BIT( x, b ) ((TEST_BIT(x,b)) ?(CLEAR_BIT(x,b)):(SET_BIT(x,b)))
30 #endif
31
32 #ifndef TEST_AND
33 #define TEST_AND( a, b ) ((a&b)==b)
34 #endif
35
36
37 #ifndef M_PI
38 #define M_PI 3.141592654
39 #endif
40
41 /*********** flush the stdout and stderr output streams *************/
42 #ifndef flushout
43 #define flushout fflush(stdout)
44 #define flusherr fflush(stderr)
45 #endif
46
47 /********** Debugging functions *************************************/
48 #ifndef error_return
49 #define error_return( c ); {fprintf(stderr,c);return;}
50 #endif
51
52 /************************* floating-point random ********************/
53 #ifndef randf
54 #define randf()  ((float) rand() / (float)RAND_MAX )
55 #endif
56
57 #ifndef SIGN
58 #define SIGN(x) ((x)>=0 ?  1  :  -1)
59 #endif
60
61 /****************** conversion between degrees and radians **********/
62 #ifndef DEG2RAD
63 #define DEG2RAD(x) ((x)/180.0*M_PI)
64 #define RAD2DEG(x) ((x)/M_PI*180.0)
65 #endif
66
67 /***************** clamp a value to some fixed interval *************/
68 #ifndef CLAMP
69 #define CLAMP(x,lo,hi)  {if ((x) < (lo)) {(x)=(lo);} else if((x) > (hi)) {(x)=(hi);}}
70 #endif
71
72 /************ check if a value lies within a closed interval *********/
73 #ifndef IN_BOUNDS
74 #define IN_BOUNDS( x, lo, hi ) ( (x) >= (lo) AND (x) <= (hi) )
75 #endif
76
77 /************ check if a 2D point lies within a 2D box ***************/
78 #ifndef PT_IN_BOX
79 #define PT_IN_BOX( x, y, lo_x, hi_x, lo_y, hi_y ) \
80 ( IN_BOUNDS(x,lo_x,hi_x) AND IN_BOUNDS(y,lo_y,hi_y) )
81 #endif
82
83 /****** check if value lies on proper side of another value     *****/
84 /*** if side is positive => proper side is positive, else negative **/
85 #ifndef CHECK_PROPER_SIDE
86 #define CHECK_PROPER_SIDE(x,val,side) ((side) > 0 ? (x) > (val) : (x) < (val))
87 #endif
88
89
90 /***** Small value when we want to do a comparison to 'close to zero' *****/
91 #ifndef FUDGE
92 #define FUDGE .00001
93 #endif
94
95
96 /******************* swap two values, using a temp variable *********/
97 #ifndef SWAP2
98 #define SWAP2(a,b,t) {t=a;a=b;b=t;}     
99 #endif
100
101 #define VEC3_TO_ARRAY(v,a)  a[0]=v[0], a[1]=v[1], a[2]=v[2]
102
103 /**** Return the ASCII control code given the non-control ASCII character */
104 #define CTRL(c) ( (c>=('a'-1)) ? (c-'a'+1) : (c-'A'+1) )
105
106
107 #endif /* GLUI_INTERNAL_H */