diff --git a/src/scene.cc b/src/scene.cc index dc46e9e..f8434d8 100644 --- a/src/scene.cc +++ b/src/scene.cc @@ -5,6 +5,7 @@ * Eryn Wells */ +#include #include #include @@ -18,6 +19,7 @@ Scene::Scene() : width(640), height(480), max_depth(5), + nrays(0), pixels(NULL) { } @@ -93,6 +95,9 @@ Scene::write(Writer &writer, const std::string &filename) void Scene::render() { + std::chrono::time_point start, end; + start = std::chrono::system_clock::now(); + pixels = new Color[width * height]; Ray primary_ray; @@ -109,7 +114,11 @@ Scene::render() } } + end = std::chrono::system_clock::now(); + std::chrono::duration seconds = end - start; + _is_rendered = true; + printf("Scene rendered. %d rays traced in %f seconds.\n", nrays, seconds.count()); } @@ -150,6 +159,9 @@ Scene::trace_ray(const Ray &ray, const int depth) float nearest_t = INFINITY; int nints; + // Keep stats. + nrays++; + // Find intersections of this ray with objects in the scene. for (Shape *s : shapes) { nints = s->does_intersect(ray, &t); diff --git a/src/scene.h b/src/scene.h index bbe991d..a979e48 100644 --- a/src/scene.h +++ b/src/scene.h @@ -52,6 +52,9 @@ private: std::list shapes; std::list lights; + // Rendering stats + unsigned int nrays; + // Rendering output. bool _is_rendered; Color *pixels;