added "cyl" token to parser and parser rules for cyl object

git-svn-id: svn://anubis/fart/trunk@165 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-02-28 20:32:23 +00:00
parent 0462a2e7bc
commit e40677ba77
4 changed files with 96 additions and 7 deletions

View File

@ -190,7 +190,7 @@ refptr<Material> Scene::processMaterial(refptr<Node> node)
refptr<Shape> Scene::processBox(refptr<Node> node)
{
Vector size(1, 1, 1);
refptr<Vector> size = new Vector(1, 1, 1);
refptr<Material> material;
bool restore_transform = processTransforms(node);
@ -201,24 +201,60 @@ refptr<Shape> Scene::processBox(refptr<Node> node)
{
if ( typeid(**it) == typeid(SizeNode) )
{
size = *(*it)->getVector();
size = (*it)->getVector();
}
else if ( typeid(**it) == typeid(MaterialNode) )
{
material = processMaterial(*it);
}
}
refptr<Shape> box = new Box(size);
if ( ! material.isNull() )
box->setMaterial(material);
box->setTransform(m_transforms.top());
if (restore_transform)
m_transforms.pop();
return refptr<Shape>(NULL);
return box;
}
refptr<Shape> Scene::processCyl(refptr<Node> node)
{
/* TODO: finish */
return refptr<Shape>(NULL);
double radius1 = 1.0;
double radius2 = 1.0;
double height = 1.0;
refptr<Material> material;
bool restore_transform = processTransforms(node);
for (Node_Iterator it = node->getChildren().begin();
it != node->getChildren().end();
it++)
{
if ( typeid(**it) == typeid(SizeNode) )
{
const Vector & v = *(*it)->getVector();
radius1 = v[0];
radius2 = v[1];
height = v[2];
}
else if ( typeid(**it) == typeid(MaterialNode) )
{
material = processMaterial(*it);
}
}
refptr<Shape> cyl = new Cyl(radius1, radius2, height);
if ( ! material.isNull() )
cyl->setMaterial(material);
cyl->setTransform(m_transforms.top());
if (restore_transform)
m_transforms.pop();
return cyl;
}
refptr<Light> Scene::processLight(refptr<Node> node)
@ -235,8 +271,34 @@ refptr<Shape> Scene::processPlane(refptr<Node> node)
refptr<Shape> Scene::processSphere(refptr<Node> node)
{
/* TODO: finish */
return refptr<Shape>(NULL);
double radius = 1.0;
refptr<Material> material;
bool restore_transform = processTransforms(node);
for (Node_Iterator it = node->getChildren().begin();
it != node->getChildren().end();
it++)
{
if ( typeid(**it) == typeid(RadiusNode) )
{
radius = (*it)->getNumber();
}
else if ( typeid(**it) == typeid(MaterialNode) )
{
material = processMaterial(*it);
}
}
refptr<Shape> sphere = new Sphere(radius);
if ( ! material.isNull() )
sphere->setMaterial(material);
sphere->setTransform(m_transforms.top());
if (restore_transform)
m_transforms.pop();
return sphere;
}
bool Scene::processTransforms(refptr<Node> node)

View File

@ -78,6 +78,10 @@ class ColorNode : public VectorNode
ColorNode(refptr<Vector> vector) : VectorNode(vector) {}
};
class CylNode : public Node
{
};
class DiffuseNode : public VectorNode
{
public:

View File

@ -43,6 +43,7 @@ ambient return AMBIENT;
box return BOX;
camera return CAMERA;
color return COLOR;
cyl return CYL;
diffuse return DIFFUSE;
height return HEIGHT;
intersect return INTERSECT;

View File

@ -62,6 +62,7 @@ static refptr<Node> parsed_scene_node;
%token BOX;
%token CAMERA;
%token COLOR;
%token CYL;
%token DIFFUSE;
%token HEIGHT;
%token INTERSECT;
@ -149,6 +150,26 @@ camera_item: POSITION vector {
}
;
cyl: CYL LCURLY cyl_items RCURLY {
$$ = new CylNode();
$$->addChildren($3);
}
;
cyl_items: /* empty */
| cyl_item cyl_items {
$$ = new ItemsNode();
$$->addChild($1);
$$->addChildren($2);
}
;
cyl_item: SIZE vector {
$$ = new SizeNode($2->getVector());
}
| shape_item { $$ = $1; }
;
intersect: INTERSECT LCURLY shape shape shape_items RCURLY {
$$ = new IntersectNode();
$$->addChild($3);
@ -289,6 +310,7 @@ scene_item: camera { $$ = $1; }
shape: plane { $$ = $1; }
| sphere { $$ = $1; }
| box { $$ = $1; }
| cyl { $$ = $1; }
| union { $$ = $1; }
| intersect { $$ = $1; }
| subtract { $$ = $1; }