filled out Scene::processBool() to handle all boolean shapes; added Node::isShape() virtual function to determine whether a node object represents a shape node

git-svn-id: svn://anubis/fart/trunk@167 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop committed 2009-02-28 21:22:30 +00:00
1 parent 5a83786103
commit 32fcafc687
3 files changed
+114 -14

No files matched your search

+97 -10
View File
@@ -13,8 +13,8 @@ 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);
refptr<Node> node = parse(filename);
processNode(node);
Transform transform;
@@ -122,23 +122,40 @@ void Scene::processNode(refptr<Node> node)
{
processChildren(node);
}
else if ( typeid(*node) == typeid(BoxNode) )
}
refptr<Shape> Scene::processShape(refptr<Node> node)
{
if ( typeid(*node) == typeid(BoxNode) )
{
cout << "saw a box" << endl;
}
else if ( typeid(*node) == typeid(MaterialNode) )
{
refptr<Material> mat = processMaterial(node);
return processBox(node);
}
else if ( typeid(*node) == typeid(PlaneNode) )
{
cout << "saw a plane" << endl;
return processPlane(node);
}
else if ( typeid(*node) == typeid(SphereNode) )
{
cout << "saw a sphere" << endl;
return processSphere(node);
}
else if ( typeid(*node) == typeid(CylNode) )
{
return processCyl(node);
}
else if ( typeid(*node) == typeid(IntersectNode) )
{
return processBool(node);
}
else if ( typeid(*node) == typeid(UnionNode) )
{
return processBool(node);
}
else if ( typeid(*node) == typeid(SubtractNode) )
{
return processBool(node);
}
return refptr<Shape>(NULL);
}
void Scene::processChildren(refptr<Node> node)
@@ -332,6 +349,76 @@ refptr<Shape> Scene::processSphere(refptr<Node> node)
return sphere;
}
refptr<Shape> Scene::processBool(refptr<Node> node)
{
refptr<Shape> shape1, shape2;
refptr<Material> material;
int shapes_seen = 0;
bool restore_transform = processTransforms(node);
for (Node_Iterator it = node->getChildren().begin();
it != node->getChildren().end();
it++)
{
if ( node->isShape() )
{
switch (shapes_seen)
{
case 0: shape1 = processShape(node);
break;
case 1: shape2 = processShape(node);
break;
}
shapes_seen++;
}
else if ( typeid(**it) == typeid(MaterialNode) )
{
material = processMaterial(*it);
}
}
if (shapes_seen < 2 || shape1.isNull() || shape2.isNull())
{
if (shapes_seen < 2)
cerr << __FILE__ << ": " << __LINE__
<< ": error: only saw "
<< shapes_seen
<< " child shapes!"
<< endl;
if (shape1.isNull())
cerr << __FILE__ << ": " << __LINE__
<< ": error: shape1 is null!" << endl;
if (shape2.isNull())
cerr << __FILE__ << ": " << __LINE__
<< ": error: shape2 is null!" << endl;
exit(3);
}
refptr<Shape> shape;
if ( typeid(*node) == typeid(IntersectNode) )
shape = new Intersect(shape1, shape2);
else if ( typeid(*node) == typeid(UnionNode) )
shape = new Union(shape1, shape2);
else if ( typeid(*node) == typeid(SubtractNode) )
shape = new Subtract(shape1, shape2);
else
{
cerr << __FILE__ << ": " << __LINE__
<< ": error: bool object unrecognized" << endl;
exit(3);
}
if ( ! material.isNull() )
shape->setMaterial(material);
shape->setTransform(m_transforms.top());
if (restore_transform)
m_transforms.pop();
return shape;
}
bool Scene::processTransforms(refptr<Node> node)
{
bool did_any = false;
+2
View File
@@ -64,6 +64,8 @@ class Scene
refptr<Light> processLight(refptr<Node> node);
refptr<Shape> processPlane(refptr<Node> node);
refptr<Shape> processSphere(refptr<Node> node);
refptr<Shape> processShape(refptr<Node> node);
refptr<Shape> processBool(refptr<Node> node);
bool processTransforms(refptr<Node> node);
/* rendering parameters */