diff --git a/main/Lighting.cc b/main/Lighting.cc index 24fd6a8..73cee51 100644 --- a/main/Lighting.cc +++ b/main/Lighting.cc @@ -5,7 +5,7 @@ using namespace std; Color Lighting::computePhong(const refptr material, - const std::vector & lights, + const std::vector< refptr > & lights, const Ray & viewRay, const Vector & surfacePoint, const Vector & surfaceNormal, @@ -18,7 +18,7 @@ Color Lighting::computePhong(const refptr material, const Color & diffuseColor = material->getDiffuseColor(); const Color & specularColor = material->getSpecularColor(); - for (std::vector::const_iterator it = lights.begin(); + for (std::vector< refptr >::const_iterator it = lights.begin(); it != lights.end(); it++) { diff --git a/main/Lighting.h b/main/Lighting.h index cb66f03..643a1c6 100644 --- a/main/Lighting.h +++ b/main/Lighting.h @@ -13,7 +13,7 @@ class Lighting { public: static Color computePhong(const refptr material, - const std::vector & lights, + const std::vector< refptr > & lights, const Ray & viewRay, const Vector & surfacePoint, const Vector & surfaceNormal, diff --git a/main/Scene.cc b/main/Scene.cc index 09b43ae..b397565 100644 --- a/main/Scene.cc +++ b/main/Scene.cc @@ -71,37 +71,25 @@ Scene::~Scene() { if (m_data != NULL) delete m_data; - for (vector::iterator it = m_shapes.begin(); - it != m_shapes.end(); - it++) - { - delete (*it); - } - for (vector::iterator it = m_lights.begin(); - it != m_lights.end(); - it++) - { - delete (*it); - } } void Scene::load(const char * filename) { /* TODO: parse file somehow */ - Shape * plane = new Plane(0, 0, 1, -2); + refptr plane = new Plane(0, 0, 1, -2); m_shapes.push_back(plane); Material * m = new Material(); m->setDiffuseColor(Color::red); m->setAmbientColor(Color::red); - Shape * shape = new Sphere(1.0); + refptr shape = new Sphere(1.0); m_transform.translate(1.0, 5.0, 0.5); shape->setTransform(m_transform); shape->setMaterial(m); m_shapes.push_back(shape); - Light * light = new PointLight(Vector(2, -1, 2)); + refptr light = new PointLight(Vector(2, -1, 2)); m_lights.push_back(light); } @@ -197,7 +185,7 @@ vector Scene::getRayHits(const Ray & ray) double minSolidDist = 0.0; /* loop through all shapes in the scene */ - for (vector::iterator it = m_shapes.begin(); + for (vector< refptr >::iterator it = m_shapes.begin(); it != m_shapes.end(); it++) { diff --git a/main/Scene.h b/main/Scene.h index f4ce342..99e3c34 100644 --- a/main/Scene.h +++ b/main/Scene.h @@ -6,6 +6,7 @@ #include #include #include +#include "util/refptr.h" #include "util/Ray.h" #include "util/Color.h" #include "shapes/Shape.h" @@ -18,11 +19,11 @@ class Scene { public: /* types */ - class ShapeDistance : public std::pair + class ShapeDistance : public std::pair, double> { public: - ShapeDistance(Shape * shape, double dist) - : std::pair(shape, dist) + ShapeDistance(refptr shape, double dist) + : std::pair, double>(shape, dist) { }; }; @@ -36,8 +37,6 @@ class Scene void setMultisampleLevel(int level) { m_multisample_level = level; } void setVFOV(double vfov) { m_vfov = vfov; } void setAmbientLight(const Color & al) { m_ambient_light = al; } - void addShape(Shape * shape) { m_shapes.push_back(shape); } - void addLight(Light * light) { m_lights.push_back(light); } Transform & getTransform() { return m_transform; } protected: @@ -58,8 +57,8 @@ class Scene Color m_ambient_light; /* private data */ - std::vector m_shapes; - std::vector m_lights; + std::vector< refptr > m_shapes; + std::vector< refptr > m_lights; Transform m_transform; double m_view_plane_dist; int m_multisample_level_squared;