124 lines
2.8 KiB
C++
124 lines
2.8 KiB
C++
|
|
#include <iostream>
|
|
#include "Scene.h"
|
|
#include "Light.h"
|
|
#include "parser/parser.h"
|
|
#include "parser/nodes.h"
|
|
|
|
using namespace std;
|
|
|
|
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);
|
|
m_shapes.push_back(plane);
|
|
|
|
refptr<Material> m = new Material();
|
|
m->setDiffuseColor(Color::red);
|
|
m->setAmbientColor(Color::red);
|
|
|
|
refptr<Shape> shape = new Sphere(1.0);
|
|
m_transform.translate(1.0, 5.0, 0.5);
|
|
shape->setTransform(m_transform);
|
|
shape->setMaterial(m);
|
|
m_shapes.push_back(shape);
|
|
|
|
m = new Material();
|
|
m->setDiffuseColor(Color::blue);
|
|
m->setAmbientColor(Color::blue);
|
|
|
|
shape = new Box(new Vector(1.8, 1.8, 0.5));
|
|
m_transform.translate(0, 0, -2.0);
|
|
shape->setTransform(m_transform);
|
|
shape->setMaterial(m);
|
|
m_shapes.push_back(shape);
|
|
|
|
m = new Material();
|
|
m->setDiffuseColor(Color::cyan);
|
|
m->setAmbientColor(Color::cyan);
|
|
|
|
shape = new Cyl(1.0, 0.0, 2.0);
|
|
m_transform.translate(-1.3, 2.5, 3.5);
|
|
m_transform.rotate(45, 1, 0, 0);
|
|
shape->setTransform(m_transform);
|
|
shape->setMaterial(m);
|
|
m_shapes.push_back(shape);
|
|
|
|
m = new Material();
|
|
m->setDiffuseColor(Color::yellow);
|
|
m->setAmbientColor(Color::yellow);
|
|
|
|
shape = new Box(new Vector(1, 1, 1));
|
|
m_transform.rotate(-45, 1, 0, 0);
|
|
m_transform.translate(-1.7, -0.5, -2.0);
|
|
m_transform.rotate(45, 0, 0, 1);
|
|
m_transform.rotate(45, 1, 0, 0);
|
|
shape->setTransform(m_transform);
|
|
shape->setMaterial(m);
|
|
m_shapes.push_back(shape);
|
|
|
|
refptr<Light> light = new PointLight();
|
|
light->setPosition(Vector(2, -1, 2));
|
|
m_lights.push_back(light);
|
|
}
|
|
|
|
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]);
|
|
}
|
|
}
|
|
|
|
refptr<Material> processMaterial(refptr<Node> node)
|
|
{
|
|
if (typeid(*node) != typeid(MaterialNode))
|
|
return refptr<Material>(NULL);
|
|
|
|
refptr<Material> material = new Material();
|
|
|
|
/* TODO: finish */
|
|
|
|
return material;
|
|
}
|
|
|
|
refptr<Shape> processShape(refptr<Node> node)
|
|
{
|
|
/* TODO: finish */
|
|
}
|
|
|
|
refptr<Light> processLight(refptr<Node> node)
|
|
{
|
|
/* TODO: finish */
|
|
}
|
|
|