goat3d

view libs/vmath/vmath.h @ 51:fa5c52ea9d59

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 17 Jan 2014 18:16:09 +0200
parents 4deb0b12fe14
children
line source
1 /*
2 libvmath - a vector math library
3 Copyright (C) 2004-2013 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 VMATH_INLINE scalar_t smoothstep(float a, float b, float x);
57 static VMATH_INLINE scalar_t frand(scalar_t range);
58 static VMATH_INLINE vec3_t sphrand(scalar_t rad);
60 scalar_t integral(scalar_t (*f)(scalar_t), scalar_t low, scalar_t high, int samples);
61 scalar_t gaussian(scalar_t x, scalar_t mean, scalar_t sdev);
63 static VMATH_INLINE scalar_t lerp(scalar_t a, scalar_t b, scalar_t t);
65 scalar_t bspline(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t);
66 scalar_t spline(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t);
67 scalar_t bezier(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t);
69 scalar_t noise1(scalar_t x);
70 scalar_t noise2(scalar_t x, scalar_t y);
71 scalar_t noise3(scalar_t x, scalar_t y, scalar_t z);
73 scalar_t fbm1(scalar_t x, int octaves);
74 scalar_t fbm2(scalar_t x, scalar_t y, int octaves);
75 scalar_t fbm3(scalar_t x, scalar_t y, scalar_t z, int octaves);
77 scalar_t turbulence1(scalar_t x, int octaves);
78 scalar_t turbulence2(scalar_t x, scalar_t y, int octaves);
79 scalar_t turbulence3(scalar_t x, scalar_t y, scalar_t z, int octaves);
81 #ifdef __cplusplus
82 }
83 #endif /* __cplusplus */
85 #include "vmath.inl"
87 #include "vector.h"
88 #include "matrix.h"
89 #include "quat.h"
90 #include "sphvec.h"
91 #include "ray.h"
92 #include "geom.h"
94 #endif /* VMATH_H_ */