erebus

view liberebus/src/bvol.cc @ 47:4b91c9a501d8

minor fix of strange code structure in the thread func
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 01 Feb 2016 14:56:15 +0200
parents 4abdce1361b9
children c4d48a21bc4a
line source
1 #include "bvol.h"
3 bool AABox::intersect(const Ray &ray) const
4 {
5 Vector3 param[2] = {vmin, vmax};
6 Vector3 inv_dir(1.0 / ray.dir.x, 1.0 / ray.dir.y, 1.0 / ray.dir.z);
7 int sign[3] = {inv_dir.x < 0, inv_dir.y < 0, inv_dir.z < 0};
9 float tmin = (param[sign[0]].x - ray.origin.x) * inv_dir.x;
10 float tmax = (param[1 - sign[0]].x - ray.origin.x) * inv_dir.x;
11 float tymin = (param[sign[1]].y - ray.origin.y) * inv_dir.y;
12 float tymax = (param[1 - sign[1]].y - ray.origin.y) * inv_dir.y;
14 if(tmin > tymax || tymin > tmax) {
15 return false;
16 }
17 if(tymin > tmin) {
18 tmin = tymin;
19 }
20 if(tymax < tmax) {
21 tmax = tymax;
22 }
24 float tzmin = (param[sign[2]].z - ray.origin.z) * inv_dir.z;
25 float tzmax = (param[1 - sign[2]].z - ray.origin.z) * inv_dir.z;
27 if(tmin > tzmax || tzmin > tmax) {
28 return false;
29 }
30 if(tzmin > tmin) {
31 tmin = tzmin;
32 }
33 if(tzmax < tmax) {
34 tmax = tzmax;
35 }
37 return true;
38 }