X-Git-Url: https://git.rohieb.name/MicroTrace.git/blobdiff_plain/0b29fae9afb220c13cc0c48c91031f0798b91ec7..dfcd78f3f458d8c4bfbc27b08ced5aae0f2e57d4:/Scene.cxx diff --git a/Scene.cxx b/Scene.cxx index 4998bd1..bbd6785 100644 --- a/Scene.cxx +++ b/Scene.cxx @@ -1,13 +1,12 @@ #include "Scene.hxx" #include "PerspectiveCamera.hxx" -#include Scene::Scene() - : m_camera(new PerspectiveCamera(Vec3f(0,0,8), - Vec3f(0,0,-1), - Vec3f(0,1,0), - 50, - 640, + : m_camera(new PerspectiveCamera(Vec3f(0,0,8), + Vec3f(0,0,-1), + Vec3f(0,1,0), + 50, + 640, 480) ), m_bgColor(Vec3f(0,0,0)) @@ -30,29 +29,28 @@ Scene::operator=(const Scene& s) return *this; } -void +void Scene::Add(Primitive* p) { m_primitives.push_back(p); } +void +Scene::Add(Light* l) +{ +} bool Scene::Intersect(Ray& ray) { - bool hit = false; - float t = std::numeric_limits::max(); - for (std::vector::iterator i = m_primitives.begin(); - i != m_primitives.end(); i++) { - // store closest object hit - if (hit |= (*i)->Intersect(ray)) { - if (ray.t() < t) { - ray.setHit(*i); - t = ray.t(); - } + bool intersect = false; + + for(unsigned int i = 0; i < m_primitives.size(); ++i) + { + intersect |= m_primitives[i]->Intersect(ray); } - } - return hit; + + return intersect; } bool @@ -64,14 +62,11 @@ Scene::Occluded(Ray& ray) Vec3f Scene::RayTrace(Ray& ray) { - if (Intersect(ray)) { - return ray.hit()->shader()->Shade(ray); - } else { - return Vec3f(0,0,0); - } + bool intersect = this->Intersect(ray); + return (intersect) ? ray.hit()->shader()->Shade(ray) : m_bgColor; } -const Camera* +const Camera* Scene::camera() const { return m_camera;