foo
[meshfrac] / src / geom.h
1 #ifndef GEOM_H_
2 #define GEOM_H_
3
4 #include "cgmath/cgmath.h"
5
6 struct plane {
7         cgm_vec3 pt, norm;
8 };
9
10 struct vertex {
11         cgm_vec3 pos, norm;
12         cgm_vec2 uv;
13 };
14
15 struct poly {
16         struct vertex *verts;   /* dynarr */
17 };
18
19 float plane_dist(const struct plane *p, const cgm_vec3 *pt);
20 float plane_sdist(const struct plane *p, const cgm_vec3 *pt);
21 void midplane(struct plane *p, const cgm_vec3 *a, const cgm_vec3 *b);
22
23 void poly_plane(const struct poly *poly, struct plane *plane);
24 int plane_poly(const struct plane *plane, struct poly *poly, float size);
25
26 /* returns negative if there's no intersection, parametric distance if there is */
27 float ray_plane(const cgm_ray *ray, const struct plane *plane);
28 float ray_poly(const cgm_ray *ray, const struct poly *poly);
29
30 int clip_poly(struct poly *pout, const struct poly *pin, const struct plane *plane);
31
32 #endif  /* GEOM_H_ */