X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fgeom.c;fp=src%2Fgeom.c;h=25c4d0afcd888786cacff9e01ccaeee7a42c21cb;hb=f1410762198ad4b0ca8c0b47bd484ff2d3e09ddd;hp=67c3c31d23072f3017009c2ca9a190e387faafe8;hpb=47382e57c60544c263e6822ea8d76025c758c7b2;p=meshfrac diff --git a/src/geom.c b/src/geom.c index 67c3c31..25c4d0a 100644 --- a/src/geom.c +++ b/src/geom.c @@ -223,3 +223,35 @@ int clip_poly(struct poly *pout, const struct poly *pin, const struct plane *pla return edges_clipped > 0 ? 0 : 1; } + +int poly_poly(const struct poly *p1, const struct poly *p2) +{ + int i, vnum1, vnum2; + float t; + cgm_ray ray; + + vnum1 = dynarr_size(p1->verts); + vnum2 = dynarr_size(p2->verts); + + for(i=0; iverts[i].pos; + ray.dir = p1->verts[(i + 1) & vnum1].pos; + cgm_vsub(&ray.dir, &ray.origin); + + if((t = ray_poly(&ray, p2)) >= 0.0f && t <= 1.0f) { + return 1; + } + } + + for(i=0; iverts[i].pos; + ray.dir = p2->verts[(i + 1) & vnum2].pos; + cgm_vsub(&ray.dir, &ray.origin); + + if((t = ray_poly(&ray, p1)) >= 0.0f && t <= 1.0f) { + return 1; + } + } + + return 0; +}