added Scene::processNode() and Scene::processChildren()

git-svn-id: svn://anubis/fart/trunk@126 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop committed 2009-02-18 01:10:57 +00:00
1 parent 30932d00e9
commit b9cc1fe9f9
5 files changed
+52 -13

No files matched your search

+36
View File
@@ -7,6 +7,7 @@
#include <map>
#include <algorithm> /* sort() */
#include <functional> /* binary_function */
#include <typeinfo> /* typeid operator support */
#include <math.h>
#include "BMP.h"
#include "util/Color.h"
@@ -77,9 +78,44 @@ Scene::~Scene()
delete m_data;
}
void Scene::processNode(refptr<Node> node)
{
if (node.isNull())
return;
if ( typeid(*node) == typeid(SceneNode) )
{
processChildren(node);
}
else if ( typeid(*node) == typeid(BoxNode) )
{
cout << "saw a box" << endl;
}
else if ( typeid(*node) == typeid(PlaneNode) )
{
cout << "saw a plane" << endl;
}
else if ( typeid(*node) == typeid(SphereNode) )
{
cout << "saw a sphere" << endl;
}
}
void Scene::processChildren(refptr<Node> node)
{
std::vector< refptr<Node> > & children = node->getChildren();
for (int i = 0, sz = children.size(); i < sz; i++)
{
processNode(children[i]);
}
}
void Scene::load(const char * filename)
{
refptr<Node> node = parse(filename);
processNode(node);
/* TODO: parse file somehow */
refptr<Shape> plane = new Plane(0, 0, 1, -2);
+4
View File
@@ -12,6 +12,8 @@
#include "shapes/Shape.h"
#include "Light.h"
#include "parser/parser.h"
#define SCENE_MAX_TRANSPARENT_HITS 8
#define SCENE_TRANSPARENCY_THRESHOLD 0.01
@@ -45,6 +47,8 @@ class Scene
void renderPixel(int x, int y, unsigned char * pixel);
Color traceRay(const Ray & ray);
std::vector<ShapeDistance> getRayHits(const Ray & ray);
void processNode(refptr<Node> node);
void processChildren(refptr<Node> node);
/* rendering parameters */
int m_width;