2 This file is part of cave9.
4 cave9 is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 cave9 is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with cave9. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef math_h_included
19 #define math_h_included
21 #include <SDL_opengl.h>
26 typedef unsigned char bool;
32 #define EPSILON 0.000001
34 typedef GLfloat Vec3
[3];
36 #define MAX(x,y) ((x)>(y)?(x):(y))
37 #define MIN(x,y) ((x)<(y)?(x):(y))
38 #define CLAMP(x,y,z) ((x)<(y)?(y):((x)>(z)?(z):(x)))
42 #define RAND (rand()/(float)RAND_MAX)
49 #define CROSS(a,b,c) \
50 a[0]=b[1]*c[2]-b[2]*c[1]; \
51 a[1]=b[2]*c[0]-b[0]*c[2]; \
52 a[2]=b[0]*c[1]-b[1]*c[0];
55 (a[0]*b[0]+a[1]*b[1]+a[2]*b[2])
67 #define ADDSCALE(a,b,x) \
82 #define SCALE2(a,b,k) \
90 #define SET(a,x,y,z) \
97 float invlen = 1/LEN(a); \
102 float xhalf
= 0.5f
*x
;
103 int i
= *(int*)&x
; // get bits for floating value
104 i
= 0x5f3759df - (i
>>1); // gives initial guess y0
105 x
= *(float*)&i
; // convert bits back to float
106 x
= x
*(1.5f
-xhalf
*x
*x
); // Newton step, repeating increases accuracy
112 // vim600:fdm=syntax:fdn=1: