X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fgeom.c;h=a704babdaf49b5aa71cd88901b5a3acced103fce;hb=HEAD;hp=07f7a9b8beccea14362f02a333056d88726927dc;hpb=4e99a80f90725d45deddf8118782fb9d49a60743;p=cyberay diff --git a/src/geom.c b/src/geom.c index 07f7a9b..a704bab 100644 --- a/src/geom.c +++ b/src/geom.c @@ -68,6 +68,25 @@ int ray_aabox_any(cgm_ray *ray, struct aabox *box, float tmax) return 1; } +void aabox_init(struct aabox *box) +{ + box->vmin.x = box->vmin.y = box->vmin.z = FLT_MAX; + box->vmax.x = box->vmax.y = box->vmax.z = -FLT_MAX; +} + +void aabox_addface(struct aabox *box, struct triangle *tri) +{ + int i; + for(i=0; i<3; i++) { + if(tri->v[i].pos.x < box->vmin.x) box->vmin.x = tri->v[i].pos.x; + if(tri->v[i].pos.x > box->vmax.x) box->vmax.x = tri->v[i].pos.x; + if(tri->v[i].pos.y < box->vmin.y) box->vmin.y = tri->v[i].pos.y; + if(tri->v[i].pos.y > box->vmax.y) box->vmax.y = tri->v[i].pos.y; + if(tri->v[i].pos.z < box->vmin.z) box->vmin.z = tri->v[i].pos.z; + if(tri->v[i].pos.z > box->vmax.z) box->vmax.z = tri->v[i].pos.z; + } +} + void aabox_union(struct aabox *res, struct aabox *a, struct aabox *b) { res->vmin.x = a->vmin.x < b->vmin.x ? a->vmin.x : b->vmin.x;