added Scene::process{Camera,Options,TransformBlock}()

git-svn-id: svn://anubis/fart/trunk@168 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-02-28 22:59:11 +00:00
parent 32fcafc687
commit bb07e12193
4 changed files with 92 additions and 13 deletions

View File

@ -12,7 +12,6 @@ typedef vector< refptr<Node> >::const_iterator Node_Iterator;
void Scene::load(const char * filename)
{
/* TODO: parse file somehow */
refptr<Node> node = parse(filename);
processNode(node);
@ -122,6 +121,43 @@ void Scene::processNode(refptr<Node> node)
{
processChildren(node);
}
else if ( node->isShape() )
{
refptr<Shape> shape = processShape(node);
if ( ! shape.isNull() )
m_shapes.push_back(shape);
}
else if ( typeid(*node) == typeid(LightNode) )
{
refptr<Light> light = processLight(node);
if ( ! light.isNull() )
m_lights.push_back(light);
}
else if ( typeid(*node) == typeid(CameraNode) )
{
processCamera(node);
}
else if ( typeid(*node) == typeid(OptionsNode) )
{
processOptions(node);
}
else if ( typeid(*node) == typeid(TranslateBlockNode) )
{
processTransformBlock(node);
}
else if ( typeid(*node) == typeid(RotateBlockNode) )
{
processTransformBlock(node);
}
else if ( typeid(*node) == typeid(ScaleBlockNode) )
{
processTransformBlock(node);
}
else
{
cerr << __FILE__ << ": " << __LINE__
<< ": error: unrecognized node!" << endl;
}
}
refptr<Shape> Scene::processShape(refptr<Node> node)
@ -167,6 +203,45 @@ void Scene::processChildren(refptr<Node> node)
}
}
void Scene::processCamera(refptr<Node> node)
{
Vector position(0, 0, 0);
Vector look_at(0, 1, 0);
Vector up(0, 0, 1);
for (Node_Iterator it = node->getChildren().begin();
it != node->getChildren().end();
it++)
{
if ( typeid(**it) == typeid(PositionNode) )
{
position = * (*it)->getVector();
}
else if ( typeid(**it) == typeid(LookAtNode) )
{
look_at = * (*it)->getVector();
}
else if ( typeid(**it) == typeid(UpNode) )
{
up = * (*it)->getVector();
}
else if ( typeid(**it) == typeid(VFOVNode) )
{
}
}
m_transforms.top().lookAt(position, look_at, up);
}
void Scene::processOptions(refptr<Node> node)
{
}
void Scene::processTransformBlock(refptr<Node> node)
{
}
refptr<Material> Scene::processMaterial(refptr<Node> node)
{
refptr<Material> material = new Material();
@ -276,7 +351,6 @@ refptr<Shape> Scene::processCyl(refptr<Node> node)
refptr<Light> Scene::processLight(refptr<Node> node)
{
/* TODO: finish */
return refptr<Light>(NULL);
}

View File

@ -67,6 +67,9 @@ class Scene
refptr<Shape> processShape(refptr<Node> node);
refptr<Shape> processBool(refptr<Node> node);
bool processTransforms(refptr<Node> node);
void processCamera(refptr<Node> node);
void processOptions(refptr<Node> node);
void processTransformBlock(refptr<Node> node);
/* rendering parameters */
int m_width;

View File

@ -113,8 +113,10 @@ class LightNode : public Node
{
};
class LookAtNode : public Node
class LookAtNode : public VectorNode
{
public:
LookAtNode(refptr<Vector> vector) : VectorNode(vector) {}
};
class MaterialNode : public Node
@ -153,8 +155,10 @@ class PlanePositionNode : public Node
double m_dist;
};
class PositionNode : public Node
class PositionNode : public VectorNode
{
public:
PositionNode(refptr<Vector> vector) : VectorNode(vector) {}
};
class RadiusNode : public NumberNode
@ -256,8 +260,10 @@ class UnionNode : public Node
bool isShape() { return true; }
};
class UpNode : public Node
class UpNode : public VectorNode
{
public:
UpNode(refptr<Vector> vector) : VectorNode(vector) {}
};
class VFOVNode : public Node

View File

@ -133,16 +133,13 @@ camera_items: /* empty */
;
camera_item: POSITION vector {
$$ = new PositionNode();
$$->addChild($2);
$$ = new PositionNode($2->getVector());
}
| LOOKAT vector {
$$ = new LookAtNode();
$$->addChild($2);
$$ = new LookAtNode($2->getVector());
}
| UP vector {
$$ = new UpNode();
$$->addChild($2);
$$ = new UpNode($2->getVector());
}
| VFOV vector {
$$ = new VFOVNode();
@ -193,8 +190,7 @@ light_items: /* empty */
;
light_item: POSITION vector {
$$ = new PositionNode();
$$->addChild($2);
$$ = new PositionNode($2->getVector());
}
| DIFFUSE vector {
$$ = new DiffuseNode($2->getVector());