From: Roland Hieber Date: Tue, 26 Jan 2010 14:45:26 +0000 (+0100) Subject: solution for 3.1a) X-Git-Url: https://git.rohieb.name/MicroTrace.git/commitdiff_plain/bb70135ac47130d65f8885b9c5fa9fa970b00cae?hp=49b259147e3ece2ed0aa4ad72b686970031cfc46 solution for 3.1a) --- diff --git a/PointLight.cxx b/PointLight.cxx index 1ce5f0b..7b8c8d2 100644 --- a/PointLight.cxx +++ b/PointLight.cxx @@ -21,7 +21,12 @@ PointLight::PointLight() bool PointLight::Illuminate(Ray& ray, Vec3f& intensity) { + float dist = ((ray.origin() + ray.direction() * ray.t()) - m_pos).norm(); + float c1 = 1, c2 = 0.5, c3 = 0; + float in = 1 / (c1 + c2*dist + c3*dist*dist); + + intensity = Vec3f(in, in, in); return false; } diff --git a/Scene.cxx b/Scene.cxx index bbd6785..a1d3acd 100644 --- a/Scene.cxx +++ b/Scene.cxx @@ -2,11 +2,11 @@ #include "PerspectiveCamera.hxx" 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,7 +29,7 @@ Scene::operator=(const Scene& s) return *this; } -void +void Scene::Add(Primitive* p) { m_primitives.push_back(p); @@ -38,6 +38,7 @@ Scene::Add(Primitive* p) void Scene::Add(Light* l) { + m_lights.push_back(l); } bool @@ -49,7 +50,7 @@ Scene::Intersect(Ray& ray) { intersect |= m_primitives[i]->Intersect(ray); } - + return intersect; } @@ -66,7 +67,7 @@ Scene::RayTrace(Ray& ray) return (intersect) ? ray.hit()->shader()->Shade(ray) : m_bgColor; } -const Camera* +const Camera* Scene::camera() const { return m_camera;