vrshoot
diff libs/vmath/vmath.h @ 0:b2f14e535253
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 01 Feb 2014 19:58:19 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/vmath/vmath.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,97 @@ 1.4 +/* 1.5 +libvmath - a vector math library 1.6 +Copyright (C) 2004-2013 John Tsiombikas <nuclear@member.fsf.org> 1.7 + 1.8 +This program is free software: you can redistribute it and/or modify 1.9 +it under the terms of the GNU Lesser General Public License as published 1.10 +by the Free Software Foundation, either version 3 of the License, or 1.11 +(at your option) any later version. 1.12 + 1.13 +This program is distributed in the hope that it will be useful, 1.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of 1.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.16 +GNU Lesser General Public License for more details. 1.17 + 1.18 +You should have received a copy of the GNU Lesser General Public License 1.19 +along with this program. If not, see <http://www.gnu.org/licenses/>. 1.20 +*/ 1.21 + 1.22 +#ifndef VMATH_H_ 1.23 +#define VMATH_H_ 1.24 + 1.25 +#include <math.h> 1.26 +#include "vmath_types.h" 1.27 + 1.28 +#ifndef M_PI 1.29 +#define M_PI PI 1.30 +#endif 1.31 + 1.32 +#ifndef M_E 1.33 +#define M_E 2.718281828459045 1.34 +#endif 1.35 + 1.36 +#define PI 3.141592653589793 1.37 +#define HALF_PI 1.570796326794897 1.38 +#define QUARTER_PI 0.785398163397448 1.39 +#define TWO_PI 6.283185307179586 1.40 + 1.41 + 1.42 +#define RAD_TO_DEG(a) ((((scalar_t)a) * 360.0) / TWO_PI) 1.43 +#define DEG_TO_RAD(a) (((scalar_t)a) * (PI / 180.0)) 1.44 + 1.45 +#define SQ(x) ((x) * (x)) 1.46 + 1.47 +#define MIN(a, b) ((a) < (b) ? (a) : (b)) 1.48 +#define MAX(a, b) ((a) > (b) ? (a) : (b)) 1.49 + 1.50 +#ifndef __GNUC__ 1.51 +#define round(x) ((x) >= 0 ? (x) + 0.5 : (x) - 0.5) 1.52 +#endif 1.53 + 1.54 +#ifdef __cplusplus 1.55 +extern "C" { 1.56 +#endif /* __cplusplus */ 1.57 + 1.58 +void enable_fpexcept(void); 1.59 +void disable_fpexcept(void); 1.60 + 1.61 +static inline scalar_t smoothstep(float a, float b, float x); 1.62 + 1.63 +static inline scalar_t frand(scalar_t range); 1.64 +static inline vec3_t sphrand(scalar_t rad); 1.65 + 1.66 +scalar_t integral(scalar_t (*f)(scalar_t), scalar_t low, scalar_t high, int samples); 1.67 +scalar_t gaussian(scalar_t x, scalar_t mean, scalar_t sdev); 1.68 + 1.69 +static inline scalar_t lerp(scalar_t a, scalar_t b, scalar_t t); 1.70 + 1.71 +scalar_t bspline(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t); 1.72 +scalar_t spline(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t); 1.73 +scalar_t bezier(scalar_t a, scalar_t b, scalar_t c, scalar_t d, scalar_t t); 1.74 + 1.75 +scalar_t noise1(scalar_t x); 1.76 +scalar_t noise2(scalar_t x, scalar_t y); 1.77 +scalar_t noise3(scalar_t x, scalar_t y, scalar_t z); 1.78 + 1.79 +scalar_t fbm1(scalar_t x, int octaves); 1.80 +scalar_t fbm2(scalar_t x, scalar_t y, int octaves); 1.81 +scalar_t fbm3(scalar_t x, scalar_t y, scalar_t z, int octaves); 1.82 + 1.83 +scalar_t turbulence1(scalar_t x, int octaves); 1.84 +scalar_t turbulence2(scalar_t x, scalar_t y, int octaves); 1.85 +scalar_t turbulence3(scalar_t x, scalar_t y, scalar_t z, int octaves); 1.86 + 1.87 +#ifdef __cplusplus 1.88 +} 1.89 +#endif /* __cplusplus */ 1.90 + 1.91 +#include "vmath.inl" 1.92 + 1.93 +#include "vector.h" 1.94 +#include "matrix.h" 1.95 +#include "quat.h" 1.96 +#include "sphvec.h" 1.97 +#include "ray.h" 1.98 +#include "geom.h" 1.99 + 1.100 +#endif /* VMATH_H_ */