X-Git-Url: https://git.rohieb.name/MicroTrace.git/blobdiff_plain/fd7caf7240f13d618697dbbc403142c1dd6057a6..df8007c9ec4440ac2388c7a4971e708c2b697832:/Scene.cxx diff --git a/Scene.cxx b/Scene.cxx index 9d78bc6..3085410 100644 --- 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 +std::vector 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(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&