Scene::CalcBounds(), including Box::Extend(Box&), Box::Clear()
authorRoland Hieber <rhieber@gaffel.ibr.cs.tu-bs.de>
Wed, 3 Feb 2010 02:21:11 +0000 (03:21 +0100)
committerRoland Hieber <rhieber@gaffel.ibr.cs.tu-bs.de>
Wed, 3 Feb 2010 02:21:11 +0000 (03:21 +0100)
Box.cxx
Scene.cxx

diff --git a/Box.cxx b/Box.cxx
index d421525..febe7c7 100644 (file)
--- a/Box.cxx
+++ b/Box.cxx
@@ -31,6 +31,8 @@ Box::operator=(const Box& b)
 void
 Box::Clear()
 {
+  m_min = Vec3f(Infinity, Infinity, Infinity);
+  m_max = Vec3f(-Infinity, -Infinity, -Infinity);
 }
 
 void
@@ -49,6 +51,8 @@ Box::Extend(const Vec3f& a)
 void
 Box::Extend(const Box& box)
 {
+  Extend(box.min());
+  Extend(box.max());
 }
 
 bool Box::OverlapsHelper(Box b) const {
index 9d78bc6..3085410 100644 (file)
--- a/Scene.cxx
+++ b/Scene.cxx
@@ -8,11 +8,11 @@
 #include "Triangle.hxx"
 
 Scene::Scene()
-  : m_camera(new PerspectiveCamera(Vec3f(0,0,8), 
-                                  Vec3f(0,0,-1), 
-                                  Vec3f(0,1,0), 
-                                  60, 
-                                  640, 
+  : m_camera(new PerspectiveCamera(Vec3f(0,0,8),
+                                  Vec3f(0,0,-1),
+                                  Vec3f(0,1,0),
+                                  60,
+                                  640,
                                   480)
             ),
     m_bgColor(Vec3f(0,0,0)),
@@ -45,7 +45,7 @@ Scene::operator=(const Scene& s)
   return *this;
 }
 
-void 
+void
 Scene::Add(Primitive* p)
 {
   m_primitives.push_back(p);
@@ -66,7 +66,7 @@ Scene::Intersect(Ray& ray)
     {
       intersect |= m_primitives[i]->Intersect(ray);
     }
-  
+
   return intersect;
 }
 
@@ -83,13 +83,13 @@ Scene::RayTrace(Ray& ray)
   return (intersect) ? ray.hit()->shader()->Shade(ray) : m_bgColor;
 }
 
-const Camera* 
+const Camera*
 Scene::camera() const
 {
   return m_camera;
 }
 
-std::vector<Light*> 
+std::vector<Light*>
 Scene::lights() const
 {
   return m_lights;
@@ -107,16 +107,16 @@ void
 Scene::ParseOBJ(const std::string& file, float scale)
 {
   std::cerr << "(Scene): Parsing OBJ file : " << file << std::endl;
-  
+
   // clear old buffers
   m_vertices.clear();
   m_faces.clear();
-  
+
   // for the moment, we will attach a white eyelight shader to each object
   // in the future, you will extend your parser to also read in material definitiions
   if(m_shader == 0) // not yet defined
     m_shader = new EyeLightShader(this, Vec3f(1.0,1.0,1.0));
-  
+
 
   // now open file
   std::fstream in;
@@ -126,7 +126,7 @@ Scene::ParseOBJ(const std::string& file, float scale)
       std::cerr << "(Scene): Could not open file " << file << std::endl;
       return;
     }
-  
+
   // read lines
   std::string line;
   while(!in.eof())
@@ -140,7 +140,7 @@ Scene::ParseOBJ(const std::string& file, float scale)
 
   // build triangle list from parsed vertices
   this->buildTriangleList(scale);
-  
+
   std::cerr << "(Scene): Finished parsing." << std::endl;
 }
 
@@ -151,12 +151,12 @@ Scene::parseOBJLine(const std::string& line)
   std::istringstream iss(line);
   std::string key;
   iss >> key;
-  if (key == "v") 
+  if (key == "v")
     {
       // parse vertex //
       this->parseVertex(iss);
     }
-  else if (key == "f") 
+  else if (key == "f")
     {
       // parse face //
       this->parseFace(iss);
@@ -189,12 +189,12 @@ Scene::buildTriangleList(float fac)
       // stores indices of triangle into vertex list
       // remember: indices start at 1!!
       Vec3f face_idx = m_faces[f];
-      this->Add(new Triangle(m_vertices[ face_idx[0]-1 ] * fac, 
-                            m_vertices[ face_idx[1]-1 ] * fac, 
+      this->Add(new Triangle(m_vertices[ face_idx[0]-1 ] * fac,
+                            m_vertices[ face_idx[1]-1 ] * fac,
                             m_vertices[ face_idx[2]-1 ] * fac,
                             m_shader));
-      
-    } 
+
+    }
   m_centroid /= static_cast<float>(m_vertices.size());
   std::cerr << "(Scene): Model centroid = " << m_centroid * fac << std::endl;
 }
@@ -202,6 +202,10 @@ Scene::buildTriangleList(float fac)
 void
 Scene::CalcBounds()
 {
+  for(unsigned int i = 0; i < m_primitives.size(); ++i)
+  {
+    m_scene_box.Extend(m_primitives[i]->CalcBounds());
+  }
 }
 
 const Box&
This page took 0.061847 seconds and 4 git commands to generate.