converted shapes and lights collection in Scene to be refptrs instead of real pointers

git-svn-id: svn://anubis/fart/trunk@102 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-02-11 17:23:01 +00:00
parent 7f9b8b913a
commit 8a112009a6
4 changed files with 13 additions and 26 deletions

View File

@ -5,7 +5,7 @@
using namespace std;
Color Lighting::computePhong(const refptr<Material> material,
const std::vector<Light *> & lights,
const std::vector< refptr<Light> > & lights,
const Ray & viewRay,
const Vector & surfacePoint,
const Vector & surfaceNormal,
@ -18,7 +18,7 @@ Color Lighting::computePhong(const refptr<Material> material,
const Color & diffuseColor = material->getDiffuseColor();
const Color & specularColor = material->getSpecularColor();
for (std::vector<Light *>::const_iterator it = lights.begin();
for (std::vector< refptr<Light> >::const_iterator it = lights.begin();
it != lights.end();
it++)
{

View File

@ -13,7 +13,7 @@ class Lighting
{
public:
static Color computePhong(const refptr<Material> material,
const std::vector<Light *> & lights,
const std::vector< refptr<Light> > & lights,
const Ray & viewRay,
const Vector & surfacePoint,
const Vector & surfaceNormal,

View File

@ -71,37 +71,25 @@ Scene::~Scene()
{
if (m_data != NULL)
delete m_data;
for (vector<Shape *>::iterator it = m_shapes.begin();
it != m_shapes.end();
it++)
{
delete (*it);
}
for (vector<Light *>::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<Shape> 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> 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> light = new PointLight(Vector(2, -1, 2));
m_lights.push_back(light);
}
@ -197,7 +185,7 @@ vector<Scene::ShapeDistance> Scene::getRayHits(const Ray & ray)
double minSolidDist = 0.0;
/* loop through all shapes in the scene */
for (vector<Shape *>::iterator it = m_shapes.begin();
for (vector< refptr<Shape> >::iterator it = m_shapes.begin();
it != m_shapes.end();
it++)
{

View File

@ -6,6 +6,7 @@
#include <map>
#include <vector>
#include <utility>
#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<Shape *, double>
class ShapeDistance : public std::pair<refptr<Shape>, double>
{
public:
ShapeDistance(Shape * shape, double dist)
: std::pair<Shape *, double>(shape, dist)
ShapeDistance(refptr<Shape> shape, double dist)
: std::pair<refptr<Shape>, 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<Shape *> m_shapes;
std::vector<Light *> m_lights;
std::vector< refptr<Shape> > m_shapes;
std::vector< refptr<Light> > m_lights;
Transform m_transform;
double m_view_plane_dist;
int m_multisample_level_squared;