added Scene::processNode() and Scene::processChildren()
git-svn-id: svn://anubis/fart/trunk@126 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
30932d00e9
commit
b9cc1fe9f9
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -12,6 +12,7 @@ class Node
|
||||
virtual ~Node();
|
||||
void addChild(refptr<Node> child) { m_children.push_back(child); }
|
||||
void addChildren(refptr<Node> other);
|
||||
std::vector< refptr<Node> > & getChildren() { return m_children; }
|
||||
|
||||
virtual int getInteger() { return 0; }
|
||||
virtual double getNumber() { return 0.0; }
|
||||
|
@ -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);
|
||||
}
|
||||
;
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user