dungeon_crawler

view prototype/vmath/vmath.h @ 79:110b2af4b9d8

fixed the shader non-conformity by explicitly converting 2.2 to vec3 before passing it to pow for the texel inverse-gamma thing
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 27 Oct 2012 01:54:39 +0300
parents
children
line source
1 /*
2 libvmath - a vector math library
3 Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
19 #ifndef VMATH_H_
20 #define VMATH_H_
22 #include <math.h>
23 #include "vmath_types.h"
25 #ifndef M_PI
26 #define M_PI PI
27 #endif
29 #ifndef M_E
30 #define M_E 2.718281828459045
31 #endif
33 #define PI 3.141592653589793
34 #define HALF_PI 1.570796326794897
35 #define QUARTER_PI 0.785398163397448
36 #define TWO_PI 6.283185307179586
39 #define RAD_TO_DEG(a) ((((scalar_t)a) * 360.0) / TWO_PI)
40 #define DEG_TO_RAD(a) (((scalar_t)a) * (PI / 180.0))
42 #define SQ(x) ((x) * (x))
44 #define MIN(a, b) ((a) < (b) ? (a) : (b))
45 #define MAX(a, b) ((a) > (b) ? (a) : (b))
47 #ifndef __GNUC__
48 #define round(x) ((x) >= 0 ? (x) + 0.5 : (x) - 0.5)
49 #endif
51 #ifdef __cplusplus
52 extern "C" {
53 #endif /* __cplusplus */
55 static inline scalar_t frand(scalar_t range);
56 static inline vec3_t sphrand(scalar_t rad);
58 scalar_t integral(scalar_t (*f)(scalar_t), scalar_t low, scalar_t high, int samples);
59 scalar_t gaussian(scalar_t x, scalar_t mean, scalar_t sdev);
61 static inline scalar_t lerp(scalar_t a, scalar_t b, scalar_t t);
63 scalar_t bspline(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t);
64 scalar_t spline(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t);
65 scalar_t bezier(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t);
67 scalar_t noise1(scalar_t x);
68 scalar_t noise2(scalar_t x, scalar_t y);
69 scalar_t noise3(scalar_t x, scalar_t y, scalar_t z);
71 scalar_t fbm1(scalar_t x, int octaves);
72 scalar_t fbm2(scalar_t x, scalar_t y, int octaves);
73 scalar_t fbm3(scalar_t x, scalar_t y, scalar_t z, int octaves);
75 scalar_t turbulence1(scalar_t x, int octaves);
76 scalar_t turbulence2(scalar_t x, scalar_t y, int octaves);
77 scalar_t turbulence3(scalar_t x, scalar_t y, scalar_t z, int octaves);
79 #ifdef __cplusplus
80 }
81 #endif /* __cplusplus */
83 #include "vmath.inl"
85 #include "vector.h"
86 #include "matrix.h"
87 #include "quat.h"
88 #include "sphvec.h"
89 #include "ray.h"
90 #include "geom.h"
92 #endif /* VMATH_H_ */