diff --git a/src/scene.cc b/src/scene.cc index 721bc25..df94d50 100644 --- a/src/scene.cc +++ b/src/scene.cc @@ -18,6 +18,7 @@ Scene::Scene() : width(640), height(480), + camera(new PerspectiveCamera()), max_depth(5), min_weight(1e-4), ambient(new AmbientLight()), @@ -30,6 +31,11 @@ Scene::Scene() Scene::~Scene() { + if (camera) { + delete camera; + camera = NULL; + } + if (ambient != NULL) { delete ambient; } @@ -130,11 +136,7 @@ Scene::render() Vector3 o, d; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { - // Assemble a ray and trace it. - o = Vector3(x, y, -1000); - d = Vector3(0, 0, 1); - d.normalize(); - primary_ray = Ray(o, d); + primary_ray = camera->compute_primary_ray(x, width, y, height); Color c = trace_ray(primary_ray); pixels[y * width + x] = c; } diff --git a/src/scene.h b/src/scene.h index 1738e43..ca580f7 100644 --- a/src/scene.h +++ b/src/scene.h @@ -14,6 +14,7 @@ #include #include #include "basics.h" +#include "camera.h" class AmbientLight; @@ -49,6 +50,8 @@ private: // Pixel dimensions of the image. int width, height; + Camera *camera; + /* * Ray tracing parameters. max_depth indicates the maximum depth of the ray tree. min_weight indicates the minimum * specular weight to apply before giving up.