diff --git a/main/Scene.cc b/main/Scene.cc index 862639b..5ec98b7 100644 --- a/main/Scene.cc +++ b/main/Scene.cc @@ -7,6 +7,7 @@ #include #include /* sort() */ #include /* binary_function */ +#include /* typeid operator support */ #include #include "BMP.h" #include "util/Color.h" @@ -77,9 +78,44 @@ Scene::~Scene() delete m_data; } +void Scene::processNode(refptr 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) +{ + std::vector< refptr > & children = node->getChildren(); + for (int i = 0, sz = children.size(); i < sz; i++) + { + processNode(children[i]); + } +} + void Scene::load(const char * filename) { refptr node = parse(filename); + processNode(node); + /* TODO: parse file somehow */ refptr plane = new Plane(0, 0, 1, -2); diff --git a/main/Scene.h b/main/Scene.h index b3845e7..fdffad8 100644 --- a/main/Scene.h +++ b/main/Scene.h @@ -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 getRayHits(const Ray & ray); + void processNode(refptr node); + void processChildren(refptr node); /* rendering parameters */ int m_width; diff --git a/parser/nodes.h b/parser/nodes.h index e15f9b0..c50a361 100644 --- a/parser/nodes.h +++ b/parser/nodes.h @@ -12,6 +12,7 @@ class Node virtual ~Node(); void addChild(refptr child) { m_children.push_back(child); } void addChildren(refptr other); + std::vector< refptr > & getChildren() { return m_children; } virtual int getInteger() { return 0; } virtual double getNumber() { return 0.0; } diff --git a/parser/parser.yy b/parser/parser.yy index 8a6f9ec..f6aec75 100644 --- a/parser/parser.yy +++ b/parser/parser.yy @@ -113,9 +113,8 @@ box_item: SIZE vector { ; camera: CAMERA LCURLY camera_items RCURLY { - Vector default_position(0, -1, 0); - Vector default_look_at(0, 0, 0); - Vector default_up(0, 0, 1); + $$ = new CameraNode(); + $$->addChildren($3); } ; diff --git a/scenes/infinity.fart b/scenes/infinity.fart index d1ec7d9..94850b5 100644 --- a/scenes/infinity.fart +++ b/scenes/infinity.fart @@ -1,6 +1,4 @@ -#define mirror material { reflectance 1.0 } - scene { options @@ -14,15 +12,15 @@ scene { position <0, -2, 0> look_at <0, 0, 0> - up <0, 0, 1>; + up <0, 0, 1> } - plane { position <1, 0, 0>, -2 mirror } - plane { position <-1, 0, 0>, -2 mirror } - plane { position <0, 1, 0>, -2 mirror } - plane { position <0, -1, 0>, -2 mirror } - plane { position <0, 0, 1>, -2 mirror } - plane { position <0, 0, -1>, -2 mirror } + plane { position <1, 0, 0>, -2 } + plane { position <-1, 0, 0>, -2 } + plane { position <0, 1, 0>, -2 } + plane { position <0, -1, 0>, -2 } + plane { position <0, 0, 1>, -2 } + plane { position <0, 0, -1>, -2 } sphere { @@ -30,7 +28,8 @@ scene material { reflectance 0.2 - color <0.5, 0.5, 0.5> + ambient <0.5, 0.5, 0.5> + diffuse <0.5, 0.5, 0.5> shininess 80 } }