+
+std::vector<Light*>
+Scene::lights() const
+{
+ return m_lights;
+}
+
+void
+Scene::setCamera(const Camera* camera)
+{
+ if(m_camera != 0)
+ delete m_camera;
+ m_camera = const_cast<Camera*>(camera);
+}
+
+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;
+ in.open(file.c_str(), std::ios::in);
+ if(in.bad() || in.fail())
+ {
+ std::cerr << "(Scene): Could not open file " << file << std::endl;
+ return;
+ }
+
+ // read lines
+ std::string line;
+ while(!in.eof())
+ {
+ std::getline(in, line);
+ this->parseOBJLine(line);
+ }
+
+ // finished parsing file -> close fileStream
+ in.close();
+
+ // build triangle list from parsed vertices
+ this->buildTriangleList(scale);
+
+ std::cerr << "(Scene): Finished parsing." << std::endl;
+}
+
+
+void
+Scene::parseOBJLine(const std::string& line)
+{
+ std::istringstream iss(line);
+ std::string key;
+ iss >> key;
+ if (key == "v")
+ {
+ // parse vertex //
+ this->parseVertex(iss);
+ }
+ else if (key == "f")
+ {
+ // parse face //
+ this->parseFace(iss);
+ }
+}
+
+void
+Scene::parseVertex(std::istringstream& iss)
+{
+ Vec3f v;
+ iss >> v[0] >> v[1] >> v[2];
+
+ m_vertices.push_back(v);
+ m_centroid += v;
+}
+
+void
+Scene::parseFace(std::istringstream& iss)
+{
+ Vec3f f;
+ iss >> f[0] >> f[1] >> f[2];
+ m_faces.push_back(f);
+}
+
+void
+Scene::buildTriangleList(float fac)
+{
+ for(unsigned int f = 0; f < m_faces.size(); ++f)
+ {
+ // 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,
+ 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;
+}
+
+void
+Scene::CalcBounds()
+{
+}
+
+const Box&
+Scene::GetSceneBox() const
+{
+ return m_scene_box;
+}