InVoxel() for all Primitives, including fix for Triangle::CalcBounds()
[MicroTrace.git] / Sphere.cxx
index fd9ba89..137ce8f 100644 (file)
@@ -1,7 +1,7 @@
 #include "Sphere.hxx"
 
 Sphere::Sphere(const Vec3f& center, float radius, Shader* shader)
-  : Primitive(shader), 
+  : Primitive(shader),
     m_center(center),
     m_radius(radius)
 {
@@ -20,22 +20,22 @@ Sphere::Intersect(Ray& ray)
 
   if( B*B-4*A*C < 0 )
     return false;
-  
+
   float root = sqrtf(B*B-4*A*C);
   float t = (-B-root)/(2.0f*A);
   if(t > ray.t())
     return false;
-      
+
   if( t < Epsilon )
     {
       t = (-B+root)/(2.0f*A);
       if( t < Epsilon || t > ray.t())
        return false;
     }
-  
+
   ray.setT(t);
   ray.setHit(this);
-  
+
   return true;
 }
 
@@ -52,11 +52,15 @@ Sphere::GetNormal(Ray& ray)
 Box
 Sphere::CalcBounds()
 {
-  return Box();
+  Vec3f min(m_center[0] - m_radius/2, m_center[1] - m_radius/2,
+    m_center[2] - m_radius/2);
+  Vec3f max(m_center[0] + m_radius/2, m_center[1] + m_radius/2,
+    m_center[2] + m_radius/2);
+  return Box(min, max);
 }
 
 bool
 Sphere::InVoxel(const Box& box)
 {
-  return false;
+  return CalcBounds().Overlaps(box);
 }
This page took 0.027039 seconds and 4 git commands to generate.