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:
parent
0462a2e7bc
commit
e40677ba77
@ -190,7 +190,7 @@ refptr<Material> Scene::processMaterial(refptr<Node> node)
|
|||||||
|
|
||||||
refptr<Shape> Scene::processBox(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;
|
refptr<Material> material;
|
||||||
|
|
||||||
bool restore_transform = processTransforms(node);
|
bool restore_transform = processTransforms(node);
|
||||||
@ -201,24 +201,60 @@ refptr<Shape> Scene::processBox(refptr<Node> node)
|
|||||||
{
|
{
|
||||||
if ( typeid(**it) == typeid(SizeNode) )
|
if ( typeid(**it) == typeid(SizeNode) )
|
||||||
{
|
{
|
||||||
size = *(*it)->getVector();
|
size = (*it)->getVector();
|
||||||
}
|
}
|
||||||
else if ( typeid(**it) == typeid(MaterialNode) )
|
else if ( typeid(**it) == typeid(MaterialNode) )
|
||||||
{
|
{
|
||||||
material = processMaterial(*it);
|
material = processMaterial(*it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refptr<Shape> box = new Box(size);
|
||||||
|
if ( ! material.isNull() )
|
||||||
|
box->setMaterial(material);
|
||||||
|
box->setTransform(m_transforms.top());
|
||||||
|
|
||||||
if (restore_transform)
|
if (restore_transform)
|
||||||
m_transforms.pop();
|
m_transforms.pop();
|
||||||
|
|
||||||
return refptr<Shape>(NULL);
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
refptr<Shape> Scene::processCyl(refptr<Node> node)
|
refptr<Shape> Scene::processCyl(refptr<Node> node)
|
||||||
{
|
{
|
||||||
/* TODO: finish */
|
double radius1 = 1.0;
|
||||||
return refptr<Shape>(NULL);
|
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)
|
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)
|
refptr<Shape> Scene::processSphere(refptr<Node> node)
|
||||||
{
|
{
|
||||||
/* TODO: finish */
|
double radius = 1.0;
|
||||||
return refptr<Shape>(NULL);
|
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)
|
bool Scene::processTransforms(refptr<Node> node)
|
||||||
|
@ -78,6 +78,10 @@ class ColorNode : public VectorNode
|
|||||||
ColorNode(refptr<Vector> vector) : VectorNode(vector) {}
|
ColorNode(refptr<Vector> vector) : VectorNode(vector) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CylNode : public Node
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
class DiffuseNode : public VectorNode
|
class DiffuseNode : public VectorNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -43,6 +43,7 @@ ambient return AMBIENT;
|
|||||||
box return BOX;
|
box return BOX;
|
||||||
camera return CAMERA;
|
camera return CAMERA;
|
||||||
color return COLOR;
|
color return COLOR;
|
||||||
|
cyl return CYL;
|
||||||
diffuse return DIFFUSE;
|
diffuse return DIFFUSE;
|
||||||
height return HEIGHT;
|
height return HEIGHT;
|
||||||
intersect return INTERSECT;
|
intersect return INTERSECT;
|
||||||
|
@ -62,6 +62,7 @@ static refptr<Node> parsed_scene_node;
|
|||||||
%token BOX;
|
%token BOX;
|
||||||
%token CAMERA;
|
%token CAMERA;
|
||||||
%token COLOR;
|
%token COLOR;
|
||||||
|
%token CYL;
|
||||||
%token DIFFUSE;
|
%token DIFFUSE;
|
||||||
%token HEIGHT;
|
%token HEIGHT;
|
||||||
%token INTERSECT;
|
%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 {
|
intersect: INTERSECT LCURLY shape shape shape_items RCURLY {
|
||||||
$$ = new IntersectNode();
|
$$ = new IntersectNode();
|
||||||
$$->addChild($3);
|
$$->addChild($3);
|
||||||
@ -289,6 +310,7 @@ scene_item: camera { $$ = $1; }
|
|||||||
shape: plane { $$ = $1; }
|
shape: plane { $$ = $1; }
|
||||||
| sphere { $$ = $1; }
|
| sphere { $$ = $1; }
|
||||||
| box { $$ = $1; }
|
| box { $$ = $1; }
|
||||||
|
| cyl { $$ = $1; }
|
||||||
| union { $$ = $1; }
|
| union { $$ = $1; }
|
||||||
| intersect { $$ = $1; }
|
| intersect { $$ = $1; }
|
||||||
| subtract { $$ = $1; }
|
| subtract { $$ = $1; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user