erebus
diff liberebus/src/bvol.cc @ 0:4abdce1361b9
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 27 Apr 2014 16:02:47 +0300 |
parents | |
children | 474a0244f57d |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/liberebus/src/bvol.cc Sun Apr 27 16:02:47 2014 +0300 1.3 @@ -0,0 +1,38 @@ 1.4 +#include "bvol.h" 1.5 + 1.6 +bool AABox::intersect(const Ray &ray) const 1.7 +{ 1.8 + Vector3 param[2] = {vmin, vmax}; 1.9 + Vector3 inv_dir(1.0 / ray.dir.x, 1.0 / ray.dir.y, 1.0 / ray.dir.z); 1.10 + int sign[3] = {inv_dir.x < 0, inv_dir.y < 0, inv_dir.z < 0}; 1.11 + 1.12 + float tmin = (param[sign[0]].x - ray.origin.x) * inv_dir.x; 1.13 + float tmax = (param[1 - sign[0]].x - ray.origin.x) * inv_dir.x; 1.14 + float tymin = (param[sign[1]].y - ray.origin.y) * inv_dir.y; 1.15 + float tymax = (param[1 - sign[1]].y - ray.origin.y) * inv_dir.y; 1.16 + 1.17 + if(tmin > tymax || tymin > tmax) { 1.18 + return false; 1.19 + } 1.20 + if(tymin > tmin) { 1.21 + tmin = tymin; 1.22 + } 1.23 + if(tymax < tmax) { 1.24 + tmax = tymax; 1.25 + } 1.26 + 1.27 + float tzmin = (param[sign[2]].z - ray.origin.z) * inv_dir.z; 1.28 + float tzmax = (param[1 - sign[2]].z - ray.origin.z) * inv_dir.z; 1.29 + 1.30 + if(tmin > tzmax || tzmin > tmax) { 1.31 + return false; 1.32 + } 1.33 + if(tzmin > tmin) { 1.34 + tmin = tzmin; 1.35 + } 1.36 + if(tzmax < tmax) { 1.37 + tmax = tzmax; 1.38 + } 1.39 + 1.40 + return true; 1.41 +} 1.42 \ No newline at end of file