CalcBounds for other Primitives... ;-)
authorRoland Hieber <rohieb@rohieb.name>
Sun, 31 Jan 2010 21:02:21 +0000 (22:02 +0100)
committerRoland Hieber <rohieb@rohieb.name>
Sun, 31 Jan 2010 21:02:21 +0000 (22:02 +0100)
Box.cxx
Box.hxx
Sphere.cxx
Triangle.cxx

diff --git a/Box.cxx b/Box.cxx
index b1951e4..e68ef40 100644 (file)
--- a/Box.cxx
+++ b/Box.cxx
@@ -1,6 +1,11 @@
 #include "Box.hxx"
 
-Box::Box() : m_min(-Infinity), m_max(Infinity)
+Box::Box() : m_min(Infinity, Infinity, Infinity),
+  m_max(-Infinity, -Infinity, -Infinity)
+{
+}
+
+Box::Box(Vec3f min, Vec3f max) : m_min(min), m_max(max)
 {
 }
 
diff --git a/Box.hxx b/Box.hxx
index 1417e80..1d46e03 100644 (file)
--- a/Box.hxx
+++ b/Box.hxx
@@ -7,11 +7,12 @@ class Box
 {
 public:
   Box();
+  Box(Vec3f min, Vec3f max);
   ~Box();
 
   Box(const Box& b);
   Box& operator=(const Box& b);
-  
+
   //! Extend the bounding box to contain point a
   void Extend(const Vec3f& a);
   //! Clear the bounding box, i.e. set dimensions to infinity.
index fd9ba89..6060361 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,7 +52,11 @@ 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
index ed12db0..b718555 100644 (file)
@@ -22,33 +22,33 @@ Triangle::Intersect(Ray& ray)
 {
   const Vec3f edge1 = m_b-m_a;
   const Vec3f edge2 = m_c-m_a;
-  
+
   const Vec3f pvec = ray.direction().cross(edge2);
-  
+
   const float det = edge1.dot(pvec);
   if (fabs(det) < Epsilon) return false;
-  
+
   const float inv_det = 1.0f / det;
-  
+
   const Vec3f tvec = ray.origin()-m_a;
   float lambda = tvec.dot( pvec );
   lambda *= inv_det;
-    
-  if (lambda < 0.0f || lambda > 1.0f) 
+
+  if (lambda < 0.0f || lambda > 1.0f)
     return false;
 
   const Vec3f qvec = tvec.cross(edge1);
   float mue = ray.direction().dot(qvec);
   mue *= inv_det;
-  
-  if (mue < 0.0f || mue+lambda > 1.0f) 
+
+  if (mue < 0.0f || mue+lambda > 1.0f)
     return false;
 
   float f = edge2.dot(qvec);
   f *= inv_det;
-  if (ray.t() <= f || f < Epsilon ) 
+  if (ray.t() <= f || f < Epsilon )
     return false;
-  
+
   ray.setT(f);
   ray.setHit(this);
 
@@ -64,6 +64,10 @@ Triangle::GetNormal(Ray& ray)
 Box
 Triangle::CalcBounds()
 {
+  Box bounds;
+  bounds.Extend(m_a);
+  bounds.Extend(m_b);
+  bounds.Extend(m_c);
   return Box();
 }
 
This page took 0.041651 seconds and 4 git commands to generate.