From 72c0d1475e78f034fdc791c7712ee568112d50b0 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Tue, 10 Sep 2013 21:04:56 -0700 Subject: [PATCH] Yay! --- src/object.h | 4 ++-- src/scene.cc | 44 ++++++++++++++++++++++++++++++++++++-------- src/scene.h | 13 ++++++++++--- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/src/object.h b/src/object.h index eb2cec8..4be5b5e 100644 --- a/src/object.h +++ b/src/object.h @@ -34,8 +34,8 @@ public: Shape(); Shape(Vector3 o); - virtual int does_intersect(const Ray &ray, float **t) = 0; - virtual Vector3 compute_normal(const Vector3 &p) = 0; + virtual int does_intersect(const Ray &ray, float **t) const = 0; + virtual Vector3 compute_normal(const Vector3 &p) const = 0; }; #endif diff --git a/src/scene.cc b/src/scene.cc index 910599b..29c528c 100644 --- a/src/scene.cc +++ b/src/scene.cc @@ -6,13 +6,16 @@ */ #include +#include + #include "basics.h" #include "object.h" #include "scene.h" +#include "writer.h" Scene::Scene() - : height(640), width(480), + : width(640), height(480), pixels(NULL) { } @@ -34,13 +37,37 @@ Scene::is_rendered() } +int +Scene::get_width() + const +{ + return width; +} + + +int +Scene::get_height() + const +{ + return height; +} + + +const Color * +Scene::get_pixels() + const +{ + return pixels; +} + + /* * scene_load -- * * Load scene objects into this Scene from the given file. */ void -Scene::read(FILE *file) +Scene::read(const std::string &filename) { } @@ -50,8 +77,10 @@ Scene::read(FILE *file) * Write a rendered scene to the given file. */ void -Scene::write(FILE *file) -{ } +Scene::write(Writer &writer, const std::string &filename) +{ + writer.write_scene(*this, filename); +} /* @@ -77,7 +106,8 @@ Scene::render() d = Vector3(0, 0, 1); d.normalize(); primary_ray = Ray(o, d); - pixels[y * width + x] = trace_ray(primary_ray, 0); + Color c = trace_ray(primary_ray, 0); + pixels[y * width + x] = c; } } @@ -95,8 +125,6 @@ Scene::add_shape(Shape *shape) Color Scene::trace_ray(const Ray &ray, const int depth) { - Color out_color = Color::Black; - // Find intersections of this ray with objects in the scene. Shape *intersected_shape = NULL; float *t = NULL; @@ -117,7 +145,7 @@ Scene::trace_ray(const Ray &ray, const int depth) // If there was no intersection, return black. if (intersected_shape == NULL) { - return out_color; + return Color::Black; } // TODO: Lighting. diff --git a/src/scene.h b/src/scene.h index 0d59fd4..326f117 100644 --- a/src/scene.h +++ b/src/scene.h @@ -12,8 +12,12 @@ #define __SCENE_H__ #include +#include +#include "basics.h" + class Shape; +class Writer; class Scene @@ -23,9 +27,12 @@ public: ~Scene(); bool is_rendered() const; + int get_width() const; + int get_height() const; + const Color *get_pixels() const; - void read(FILE *f); - void write(FILE *f); + void read(const std::string &filename); + void write(Writer &writer, const std::string &filename); void render(); void add_shape(Shape *obj); @@ -33,7 +40,7 @@ public: private: Color trace_ray(const Ray &ray, const int depth); - int height, width; + int width, height; std::list shapes; bool _is_rendered;