X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Flevel.c;fp=src%2Flevel.c;h=fcdc405e76576ba25ac55305b3762a567eb8a546;hb=ee39e383f97259441df726c76cf26dcef7e9c054;hp=1bd1c19478cdb506ee2f19202fbb0c2847cf4e3b;hpb=a886acd491daf3faa62d45bf5503eb2c5313f335;p=cyberay diff --git a/src/level.c b/src/level.c index 1bd1c19..fcdc405 100644 --- a/src/level.c +++ b/src/level.c @@ -86,6 +86,29 @@ void destroy_level(struct level *lvl) int ray_level(cgm_ray *ray, struct level *lvl, float tmax, struct rayhit *hit) { + int found = 0; + struct rayhit hit0; + + if(!hit) { + if(ray_bvhnode(ray, lvl->st_root, tmax, 0)) return 1; + if(ray_bvhnode(ray, lvl->dyn_root, tmax, 0)) return 1; + return 0; + } + + hit0.t = FLT_MAX; + if(ray_bvhnode(ray, lvl->st_root, tmax, hit)) { + hit0 = *hit; + found = 1; + } + if(ray_bvhnode(ray, lvl->dyn_root, tmax, hit) && hit->t < hit0.t) { + hit0 = *hit; + found = 1; + } + + if(found) { + *hit = hit0; + return 1; + } return 0; }