istereo
diff libs/vmath/geom.h @ 28:c0ae8e668447
added vmath library
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Thu, 08 Sep 2011 08:30:42 +0300 |
parents | |
children | ff055bff6a15 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/vmath/geom.h Thu Sep 08 08:30:42 2011 +0300 1.3 @@ -0,0 +1,55 @@ 1.4 +#ifndef GEOM_H_ 1.5 +#define GEOM_H_ 1.6 + 1.7 +#include "vector.h" 1.8 +#include "ray.h" 1.9 + 1.10 +typedef struct { 1.11 + vec3_t norm; 1.12 + scalar_t d; 1.13 +} plane_t; 1.14 + 1.15 +typedef struct { 1.16 + vec3_t pos; 1.17 + scalar_t rad; 1.18 +} sphere_t; 1.19 + 1.20 +typedef struct { 1.21 + vec3_t min, max; 1.22 +} aabox_t; 1.23 + 1.24 +#ifdef __cplusplus 1.25 +extern "C" { 1.26 +#endif 1.27 + 1.28 +/* planes are good... you need planes, yes you do */ 1.29 +plane_t plane_cons(scalar_t nx, scalar_t ny, scalar_t nz, scalar_t d); 1.30 +plane_t plane_poly(vec3_t v0, vec3_t v1, vec3_t v2); 1.31 +plane_t plane_ptnorm(vec3_t pt, vec3_t normal); 1.32 + 1.33 +plane_t plane_invert(plane_t p); 1.34 + 1.35 +scalar_t plane_signed_dist(plane_t plane, vec3_t pt); 1.36 +scalar_t plane_dist(plane_t plane, vec3_t pt); 1.37 +vec3_t plane_point(plane_t plane); 1.38 + 1.39 +int plane_ray_intersect(ray_t ray, plane_t plane, scalar_t *pos); 1.40 + 1.41 +/* spheres always come in handy */ 1.42 +sphere_t sphere_cons(scalar_t x, scalar_t y, scalar_t z, scalar_t rad); 1.43 + 1.44 +int sphere_ray_intersect(ray_t ray, sphere_t sph, scalar_t *pos); 1.45 +int sphere_sphere_intersect(sphere_t sph1, sphere_t sph2, scalar_t *pos, scalar_t *rad); 1.46 + 1.47 +#ifdef __cplusplus 1.48 +} 1.49 + 1.50 +/* TODO 1.51 +class Plane : public plane_t { 1.52 +public: 1.53 +}; 1.54 +*/ 1.55 + 1.56 +#endif 1.57 + 1.58 +#endif /* GEOM_H_ */