broke traceRay() out into getRayHits()

git-svn-id: svn://anubis/fart/trunk@51 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop committed 2009-01-27 00:11:14 +00:00
1 parent 38b2304641
commit e8fd42f81f
4 files changed
+48 -11

No files matched your search

+35 -10
View File
@@ -2,11 +2,14 @@
#include "Scene.h"
#include <stdlib.h>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <math.h>
#include "BMP.h"
#include "shapes/Shape.h"
#include "shapes/Sphere.h"
#include "PointLight.h"
using namespace std;
Scene::Scene(map<string, const char *> options,
@@ -70,6 +73,12 @@ Scene::~Scene()
{
delete (*it);
}
for (vector<Light *>::iterator it = m_lights.begin();
it != m_lights.end();
it++)
{
delete (*it);
}
}
void Scene::load(const char * filename)
@@ -79,6 +88,9 @@ void Scene::load(const char * filename)
m_transform.translate(1.0, 5.0, 0.5);
shape->setTransform(m_transform);
m_shapes.push_back(shape);
Light * light = new PointLight(Vector(-1, -1, 1));
m_lights.push_back(light);
}
void Scene::render()
@@ -146,25 +158,38 @@ Vector Scene::traceRay(const Ray & ray)
{
Vector color;
vector< pair<Shape *, double> > hits = getRayHits(ray, 0.0);
if (hits.size() > 0)
{
color[0] = color[1] = color[2] = 1.0;
}
return color;
}
vector< pair<Shape *, double> >
Scene::getRayHits(const Ray & ray, double minDist)
{
vector< pair<Shape *, double> > hits;
/* loop through all shapes in the scene */
for (vector<Shape *>::iterator it = m_shapes.begin();
it != m_shapes.end();
it++)
{
/* then intersect this inversely transformed ray with the shape */
Solver::Result intersections = (*it)->intersect(ray);
if (intersections.numResults > 0)
{
color[0] = color[1] = color[2] = 1.0;
}
else
{
color[0] = 0.0;
color[1] = 0.0;
color[2] = 0.0;
for (int i = 0; i < intersections.numResults; i++)
{
if (intersections.results[i] > minDist)
{
hits.push_back(pair<Shape *, double>(*it, intersections.results[i]));
}
}
}
}
return color;
}
return hits;
}
+8
View File
@@ -5,8 +5,13 @@
#include <string>
#include <map>
#include <vector>
#include <utility>
#include "util/Ray.h"
#include "shapes/Shape.h"
#include "Light.h"
#define SCENE_MAX_TRANSPARENT_HITS 8
#define SCENE_TRANSPARENCY_THRESHOLD 0.01
class Scene
{
@@ -21,6 +26,8 @@ class Scene
void load(const char * filename);
void renderPixel(int x, int y, unsigned char * pixel);
Vector traceRay(const Ray & ray);
std::vector< std::pair<Shape *, double> >
getRayHits(const Ray & ray, double minDist);
/* rendering parameters */
int m_width;
@@ -32,6 +39,7 @@ class Scene
/* private data */
std::vector<Shape *> m_shapes;
std::vector<Light *> m_lights;
Transform m_transform;
double m_view_plane_dist;
int m_multisample_level_squared;