X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fgeom.c;fp=src%2Fgeom.c;h=f7e174036bddbede79797e504872526a26e1fc95;hb=0b9d8564e9c3785a69829a8faa67f5169185d8fd;hp=0000000000000000000000000000000000000000;hpb=3266468aa891bea6bda03f64ecba7da2a29d09c3;p=meshfrac diff --git a/src/geom.c b/src/geom.c new file mode 100644 index 0000000..f7e1740 --- /dev/null +++ b/src/geom.c @@ -0,0 +1,23 @@ +#include "geom.h" + +float plane_dist(const struct plane *p, const cgm_vec3 *pt) +{ + return fabs(plane_sdist(p, pt)); +} + +float plane_sdist(const struct plane *p, const cgm_vec3 *pt) +{ + cgm_vec3 v = p->pt; + cgm_vsub(&v, pt); + return cgm_vdot(&v, &p->norm); +} + +void midplane(struct plane *p, const cgm_vec3 *a, const cgm_vec3 *b) +{ + p->norm = *b; + cgm_vsub(&p->norm, a); + cgm_vnormalize(&p->norm); + p->pt.x = a->x + p->norm.x * 0.5f; + p->pt.y = a->y + p->norm.y * 0.5f; + p->pt.z = a->z + p->norm.z * 0.5f; +}