src/octree.cc
branchpyrit
changeset 49 558fde7da82a
parent 44 3763b26244f0
child 91 9d66d323c354
--- a/src/octree.cc	Wed Mar 26 17:03:38 2008 +0100
+++ b/src/octree.cc	Fri Mar 28 00:53:20 2008 +0100
@@ -171,7 +171,7 @@
 
 	int a = 0;
 	Vector3 ro(ray.o);
-	Vector3 rdir(1.0/ray.dir.x, 1.0/ray.dir.y, 1.0/ray.dir.z);
+	Vector3 rdir(ray.dir);
 
 	if (rdir.x < 0.0)
 	{
@@ -192,6 +192,13 @@
 		a |= 1;
 	}
 
+	if (rdir.x == 0.0) rdir.x = Eps;
+	if (rdir.y == 0.0) rdir.y = Eps;
+	if (rdir.z == 0.0) rdir.z = Eps;
+	rdir.x = 1.0/rdir.x;
+	rdir.y = 1.0/rdir.y;
+	rdir.z = 1.0/rdir.z;
+
 	tx0 = (bbox.L.x - ro.x) * rdir.x;
 	tx1 = (bbox.H.x - ro.x) * rdir.x;
 	ty0 = (bbox.L.y - ro.y) * rdir.y;
@@ -199,7 +206,7 @@
 	tz0 = (bbox.L.z - ro.z) * rdir.z;
 	tz1 = (bbox.H.z - ro.z) * rdir.z;
 
-	if (max3(tx0,ty0,tz0) > min3(tx1,ty1,tz1))
+	if (max3(tx0,ty0,tz0) >= min3(tx1,ty1,tz1))
 		return NULL;
 
 	node = root;