solution for 4.1b,c
authorRoland Hieber <rohieb@rohieb.name>
Sun, 31 Jan 2010 04:17:28 +0000 (05:17 +0100)
committerRoland Hieber <rohieb@rohieb.name>
Sun, 31 Jan 2010 04:17:28 +0000 (05:17 +0100)
Box.cxx
InfinitePlane.cxx

diff --git a/Box.cxx b/Box.cxx
index ef9f750..b1951e4 100644 (file)
--- a/Box.cxx
+++ b/Box.cxx
@@ -1,6 +1,6 @@
 #include "Box.hxx"
 
-Box::Box()
+Box::Box() : m_min(-Infinity), m_max(Infinity)
 {
 }
 
@@ -10,11 +10,15 @@ Box::~Box()
 
 Box::Box(const Box& b)
 {
+  m_min = b.m_min;
+  m_max = b.m_max;
 }
 
 Box&
 Box::operator=(const Box& b)
 {
+  m_min = b.m_min;
+  m_max = b.m_max;
   return *this;
 }
 
@@ -26,9 +30,17 @@ Box::Clear()
 void
 Box::Extend(const Vec3f& a)
 {
+  // for all three coordinates, move m_max or m_min to the point
+  for(size_t i = 0; i < 3; i++) {
+    if(a[i] > m_max[i]) {
+      m_max[i] = a[i];
+    } else if(a[i] < m_min[i]) {
+      m_min[i] = a[i];
+    } // else: do nothing, coordinate is inside the box
+  }
 }
 
-void 
+void
 Box::Extend(const Box& box)
 {
 }
index c11fb8a..13d6e53 100644 (file)
@@ -1,11 +1,11 @@
 #include "InfinitePlane.hxx"
 
 InfinitePlane::InfinitePlane(const Vec3f& a, const Vec3f& n, Shader* shader)
-  : Primitive(shader), 
+  : Primitive(shader),
     m_a(a),
     m_n(n)
 {
-  
+
 }
 
 InfinitePlane::~InfinitePlane()
@@ -17,9 +17,9 @@ InfinitePlane::Intersect(Ray& ray)
 {
   Vec3f diff = m_a - ray.origin();
   float t = diff.dot(m_n) / ray.direction().dot(m_n);
-  if (t < Epsilon || t > ray.t()) 
+  if (t < Epsilon || t > ray.t())
     return false;
-  
+
   ray.setT(t);
   ray.setHit(this);
 
@@ -35,7 +35,21 @@ InfinitePlane::GetNormal(Ray& ray)
 Box
 InfinitePlane::CalcBounds()
 {
-  return Box();
+  if(fabs(m_n[0]-1) < Epsilon && m_n[1] < Epsilon && m_n[2] < Epsilon) {
+    // plane is parallel to y and z axes
+    return Box(Vec3f(m_a[0]-Epsilon, Infinity, Infinity),
+      Vec3f(m_a[0]+Epsilon, Infinity, Infinity));
+  } else if(m_n[0] < Epsilon && fabs(m_n[1]-1) < Epsilon && m_n[2] < Epsilon) {
+    // plane is parallel to x and z axes
+    return Box(Vec3f(Infinity, m_a[1]-Epsilon, Infinity),
+      Vec3f(Infinity, m_a[1]+Epsilon, Infinity));
+  } else if(m_n[0] < Epsilon && m_n[1] < Epsilon && fabs(m_n[2]-1) < Epsilon ) {
+    // plane is parallel to x and y axes
+    return Box(Vec3f(Infinity, Infinity, m_a[2]-Epsilon),
+      Vec3f(Infinity, Infinity, m_a[2]+Epsilon));
+  } else
+    // no real border
+    return Box();
 }
 
 bool
This page took 0.028678 seconds and 4 git commands to generate.