X-Git-Url: https://git.rohieb.name/MicroTrace.git/blobdiff_plain/0e3446ceb6fd6db0cb292671f37b46daaa2aed5b..3e9d9dd0040fc7b578bb49bac41e8292ce16a685:/Scene.cxx diff --git a/Scene.cxx b/Scene.cxx index 184b7e1..4998bd1 100644 --- a/Scene.cxx +++ b/Scene.cxx @@ -1,12 +1,13 @@ #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)) @@ -29,16 +30,29 @@ Scene::operator=(const Scene& s) return *this; } -void +void Scene::Add(Primitive* p) { + m_primitives.push_back(p); } bool Scene::Intersect(Ray& ray) { - return false; + 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(); + } + } + } + return hit; } bool @@ -50,10 +64,14 @@ Scene::Occluded(Ray& ray) Vec3f Scene::RayTrace(Ray& ray) { - return Vec3f(); + if (Intersect(ray)) { + return ray.hit()->shader()->Shade(ray); + } else { + return Vec3f(0,0,0); + } } -const Camera* +const Camera* Scene::camera() const { return m_camera;