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:
parent
7f9b8b913a
commit
8a112009a6
@ -5,7 +5,7 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Color Lighting::computePhong(const refptr<Material> material,
|
Color Lighting::computePhong(const refptr<Material> material,
|
||||||
const std::vector<Light *> & lights,
|
const std::vector< refptr<Light> > & lights,
|
||||||
const Ray & viewRay,
|
const Ray & viewRay,
|
||||||
const Vector & surfacePoint,
|
const Vector & surfacePoint,
|
||||||
const Vector & surfaceNormal,
|
const Vector & surfaceNormal,
|
||||||
@ -18,7 +18,7 @@ Color Lighting::computePhong(const refptr<Material> material,
|
|||||||
const Color & diffuseColor = material->getDiffuseColor();
|
const Color & diffuseColor = material->getDiffuseColor();
|
||||||
const Color & specularColor = material->getSpecularColor();
|
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 != lights.end();
|
||||||
it++)
|
it++)
|
||||||
{
|
{
|
||||||
|
@ -13,7 +13,7 @@ class Lighting
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Color computePhong(const refptr<Material> material,
|
static Color computePhong(const refptr<Material> material,
|
||||||
const std::vector<Light *> & lights,
|
const std::vector< refptr<Light> > & lights,
|
||||||
const Ray & viewRay,
|
const Ray & viewRay,
|
||||||
const Vector & surfacePoint,
|
const Vector & surfacePoint,
|
||||||
const Vector & surfaceNormal,
|
const Vector & surfaceNormal,
|
||||||
|
@ -71,37 +71,25 @@ Scene::~Scene()
|
|||||||
{
|
{
|
||||||
if (m_data != NULL)
|
if (m_data != NULL)
|
||||||
delete m_data;
|
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)
|
void Scene::load(const char * filename)
|
||||||
{
|
{
|
||||||
/* TODO: parse file somehow */
|
/* 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);
|
m_shapes.push_back(plane);
|
||||||
|
|
||||||
Material * m = new Material();
|
Material * m = new Material();
|
||||||
m->setDiffuseColor(Color::red);
|
m->setDiffuseColor(Color::red);
|
||||||
m->setAmbientColor(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);
|
m_transform.translate(1.0, 5.0, 0.5);
|
||||||
shape->setTransform(m_transform);
|
shape->setTransform(m_transform);
|
||||||
shape->setMaterial(m);
|
shape->setMaterial(m);
|
||||||
m_shapes.push_back(shape);
|
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);
|
m_lights.push_back(light);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +185,7 @@ vector<Scene::ShapeDistance> Scene::getRayHits(const Ray & ray)
|
|||||||
double minSolidDist = 0.0;
|
double minSolidDist = 0.0;
|
||||||
|
|
||||||
/* loop through all shapes in the scene */
|
/* 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 != m_shapes.end();
|
||||||
it++)
|
it++)
|
||||||
{
|
{
|
||||||
|
13
main/Scene.h
13
main/Scene.h
@ -6,6 +6,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include "util/refptr.h"
|
||||||
#include "util/Ray.h"
|
#include "util/Ray.h"
|
||||||
#include "util/Color.h"
|
#include "util/Color.h"
|
||||||
#include "shapes/Shape.h"
|
#include "shapes/Shape.h"
|
||||||
@ -18,11 +19,11 @@ class Scene
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/* types */
|
/* types */
|
||||||
class ShapeDistance : public std::pair<Shape *, double>
|
class ShapeDistance : public std::pair<refptr<Shape>, double>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ShapeDistance(Shape * shape, double dist)
|
ShapeDistance(refptr<Shape> shape, double dist)
|
||||||
: std::pair<Shape *, double>(shape, dist)
|
: std::pair<refptr<Shape>, double>(shape, dist)
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -36,8 +37,6 @@ class Scene
|
|||||||
void setMultisampleLevel(int level) { m_multisample_level = level; }
|
void setMultisampleLevel(int level) { m_multisample_level = level; }
|
||||||
void setVFOV(double vfov) { m_vfov = vfov; }
|
void setVFOV(double vfov) { m_vfov = vfov; }
|
||||||
void setAmbientLight(const Color & al) { m_ambient_light = al; }
|
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; }
|
Transform & getTransform() { return m_transform; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -58,8 +57,8 @@ class Scene
|
|||||||
Color m_ambient_light;
|
Color m_ambient_light;
|
||||||
|
|
||||||
/* private data */
|
/* private data */
|
||||||
std::vector<Shape *> m_shapes;
|
std::vector< refptr<Shape> > m_shapes;
|
||||||
std::vector<Light *> m_lights;
|
std::vector< refptr<Light> > m_lights;
|
||||||
Transform m_transform;
|
Transform m_transform;
|
||||||
double m_view_plane_dist;
|
double m_view_plane_dist;
|
||||||
int m_multisample_level_squared;
|
int m_multisample_level_squared;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user