erebus

annotate 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
rev   line source
nuclear@0 1 #include "bvol.h"
nuclear@0 2
nuclear@0 3 bool AABox::intersect(const Ray &ray) const
nuclear@0 4 {
nuclear@0 5 Vector3 param[2] = {vmin, vmax};
nuclear@0 6 Vector3 inv_dir(1.0 / ray.dir.x, 1.0 / ray.dir.y, 1.0 / ray.dir.z);
nuclear@0 7 int sign[3] = {inv_dir.x < 0, inv_dir.y < 0, inv_dir.z < 0};
nuclear@0 8
nuclear@0 9 float tmin = (param[sign[0]].x - ray.origin.x) * inv_dir.x;
nuclear@0 10 float tmax = (param[1 - sign[0]].x - ray.origin.x) * inv_dir.x;
nuclear@0 11 float tymin = (param[sign[1]].y - ray.origin.y) * inv_dir.y;
nuclear@0 12 float tymax = (param[1 - sign[1]].y - ray.origin.y) * inv_dir.y;
nuclear@0 13
nuclear@0 14 if(tmin > tymax || tymin > tmax) {
nuclear@0 15 return false;
nuclear@0 16 }
nuclear@0 17 if(tymin > tmin) {
nuclear@0 18 tmin = tymin;
nuclear@0 19 }
nuclear@0 20 if(tymax < tmax) {
nuclear@0 21 tmax = tymax;
nuclear@0 22 }
nuclear@0 23
nuclear@0 24 float tzmin = (param[sign[2]].z - ray.origin.z) * inv_dir.z;
nuclear@0 25 float tzmax = (param[1 - sign[2]].z - ray.origin.z) * inv_dir.z;
nuclear@0 26
nuclear@0 27 if(tmin > tzmax || tzmin > tmax) {
nuclear@0 28 return false;
nuclear@0 29 }
nuclear@0 30 if(tzmin > tmin) {
nuclear@0 31 tmin = tzmin;
nuclear@0 32 }
nuclear@0 33 if(tzmax < tmax) {
nuclear@0 34 tmax = tzmax;
nuclear@0 35 }
nuclear@0 36
nuclear@0 37 return true;
nuclear@0 38 }