Mesh now uses an oct-tree to store its triangles.
Mesh now uses an oct-tree to store its triangles.

--- a/AxisAlignedBox.cpp
+++ b/AxisAlignedBox.cpp
@@ -135,7 +135,7 @@
       iter!=intersections.end();
       iter++)
     {
-      //std::cout << (std::string)iter->xyz() << std::endl;
+      //std::cout << (std::string)(*iter) << std::endl;
       double distanceToIntersection=ray.distanceToPoint(*iter);
       if(distanceToIntersection>EPSILON && 
 	 (distanceToIntersection<smallestDistance ||

file:a/Mesh.cpp -> file:b/Mesh.cpp
--- a/Mesh.cpp
+++ b/Mesh.cpp
@@ -17,6 +17,7 @@
 
 IntersectionInformation Mesh::intersection(Ray ray) const
 {
+  //std::cout << "Mesh::intersection(Ray ray)" << std::endl;
   IntersectionInformation triinfo=_triangles.intersection(ray);
 
   if(triinfo.intersects())

--- a/OctTreeNode.cpp
+++ b/OctTreeNode.cpp
@@ -55,14 +55,22 @@
 	    }
 	}
 
+      bool forceLeaf=false;
       for(unsigned int i=0;i<8;i++)
+	if(partitions[i].size()==objects.size())
+	  forceLeaf=true;
+
+      if(!forceLeaf)
 	{
-	  if(partitions[i].size()>0)
-	    {
-	      OctTreeNode *node=new OctTreeNode(partitions[i]);
-	      _children.push_back(node);
-	    }
+	  for(unsigned int i=0;i<8;i++)
+	    if(partitions[i].size()>0)
+	      {
+		OctTreeNode *node=new OctTreeNode(partitions[i]);
+		_children.push_back(node);
+	      }
 	}
+      else
+	_objects=objects;
     }
   else
     _objects=objects;
@@ -87,6 +95,7 @@
 
 IntersectionInformation OctTreeNode::intersection(Ray ray) const
 { 
+  //std::cout << "OctTreeNode::intersection(Ray ray), this=" << this << ", leaf=" << isLeaf() << std::endl;
   if(isLeaf())
     return leafIntersection(ray);
   else
@@ -95,6 +104,7 @@
 
 IntersectionInformation OctTreeNode::leafIntersection(Ray ray) const
 {
+  //std::cout << "OctTreeNode::leafIntersection(Ray ray), this=" << this << std::endl;
   // Find the object that this ray intersects with
   double smallestDistance=-1;
   Object *closestObject=0;
@@ -116,14 +126,15 @@
 	    }
 	}
     }
-  
+
   //std::cout << "closestObject=" << closestObject << std::endl;
-  
+
   return closestIntersection;
 }
 
 IntersectionInformation OctTreeNode::nodeIntersection(Ray ray) const
 {
+  //std::cout << "OctTreeNode::nodeIntersection(Ray ray), this=" << this << std::endl;
   IntersectionInformation bbtest=_boundingBox.intersection(ray);
   if(!bbtest.intersects()) return IntersectionInformation();
   

file:a/Scene.cpp -> file:b/Scene.cpp
--- a/Scene.cpp
+++ b/Scene.cpp
@@ -241,6 +241,8 @@
   
 
   IntersectionInformation info=_objects.intersection(ray);
+  //std::cout << "info.intersects()=" << info.intersects() << std::endl;
+  //std::cout << "info.object()=" << info.object() << std::endl;
 
   // Determine color contribution from the closest object
   if(info.intersects())

--- a/tests/doughnut.txt
+++ b/tests/doughnut.txt
@@ -4,13 +4,13 @@
 camera_from	3 3 3
 camera_target	0 0 0
 camera_up    0.0 1.0 0.0
-camera_angle 90.0
+camera_angle 45.0
 camera_resolution 300 200
 
 background 0.0 0.0 0.0
 ambient_light 1.0 1.0 1.0
 point_light   10 10 10 3 3 3
 
-trace_depth 6
+trace_depth 0
 render doughnut.ppm