erebus

annotate liberebus/src/bvol.cc @ 3:a932848de652

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