Add lights to the scene

This commit is contained in:
Eryn Wells 2013-09-10 21:49:01 -07:00
parent 14b246b6e9
commit 6bb7689ac0
2 changed files with 26 additions and 1 deletions

View file

@ -115,6 +115,11 @@ Scene::render()
}
/*
* Scene::add_shape --
*
* Add a shape to the scene.
*/
void
Scene::add_shape(Shape *shape)
{
@ -122,6 +127,23 @@ Scene::add_shape(Shape *shape)
}
/*
* Scene::add_light --
*
* Add a light to the scene.
*/
void
Scene::add_light(Light *light)
{
lights.push_back(light);
}
/*
* Scene::trace_ray --
*
* Trace the given ray through the scene, recursing until depth has been reached.
*/
Color
Scene::trace_ray(const Ray &ray, const int depth)
{
@ -144,7 +166,7 @@ Scene::trace_ray(const Ray &ray, const int depth)
}
// If there was no intersection, return black.
if (intersected_shape == NULL) {
if (intersected_shape != NULL) {
return Color::Black;
}

View file

@ -16,6 +16,7 @@
#include "basics.h"
class Light;
class Shape;
class Writer;
@ -36,12 +37,14 @@ public:
void render();
void add_shape(Shape *obj);
void add_light(Light *light);
private:
Color trace_ray(const Ray &ray, const int depth);
int width, height;
std::list<Shape *> shapes;
std::list<Light *> lights;
bool _is_rendered;
Color *pixels;