From 2e82f9e2ea3f4db656dbe89d080e23f29debba3f Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 10 Feb 2009 00:52:38 +0000 Subject: [PATCH] adding required arguments to shape constructors in scene description language git-svn-id: svn://anubis/fart/trunk@95 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- parser/parser.lex | 1 - parser/parser.yy | 40 ++++++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/parser/parser.lex b/parser/parser.lex index 4eebffb..7be38e9 100644 --- a/parser/parser.lex +++ b/parser/parser.lex @@ -43,7 +43,6 @@ multisample return MULTISAMPLE; options return OPTIONS; plane return PLANE; position return POSITION; -radius return RADIUS; reflectance return REFLECTANCE; scene return SCENE; shininess return SHININESS; diff --git a/parser/parser.yy b/parser/parser.yy index de2c41b..6c26db7 100644 --- a/parser/parser.yy +++ b/parser/parser.yy @@ -1,5 +1,6 @@ %{ + #include #include #include "main/Scene.h" @@ -34,6 +35,7 @@ class Node int type; double * the_double; Material * the_Material; + Shape * the_Shape; Vector * the_Vector; }; @@ -81,7 +83,6 @@ static Scene * g_scene; %token OPTIONS; %token PLANE; %token POSITION; -%token RADIUS; %token REFLECTANCE; %token SCENE; %token SHININESS; @@ -106,11 +107,10 @@ boolean_items_more: /* empty */ | material boolean_items_more ; -box: BOX LCURLY box_items RCURLY +box: BOX LPAREN vector RPAREN LCURLY box_items RCURLY ; box_items: shape_items - | SIZE vector box_items ; camera: CAMERA LCURLY camera_items RCURLY @@ -155,11 +155,17 @@ number: DEC_NUMBER { } ; -plane: PLANE LCURLY plane_items RCURLY +plane: PLANE LPAREN vector COMMA number RPAREN LCURLY plane_items RCURLY { + Plane * plane = new Plane((*($3->the_Vector))[0], + (*($3->the_Vector))[1], + (*($3->the_Vector))[2], + *($5->the_double)); + $$ = new Node(); + $$->the_Shape = plane; + } ; plane_items: shape_items - | POSITION vector COMMA number plane_items ; scene_spec: SCENE LCURLY scene_items RCURLY @@ -169,27 +175,26 @@ scene_items: /* empty */ | scene_item scene_items ; -scene_item: camera - | shape +scene_item: camera { $$ = $1; } + | shape { $$ = $1; } ; -shape: plane - | sphere - | box - | union - | intersect - | subtract +shape: plane { $$ = $1; } + | sphere { $$ = $1; } + | box { $$ = $1; } + | union { $$ = $1; } + | intersect { $$ = $1; } + | subtract { $$ = $1; } ; shape_items: /* empty */ - | material + | material { $$ = $1; } ; -sphere: SPHERE LCURLY sphere_items RCURLY +sphere: SPHERE LPAREN number RPAREN LCURLY sphere_items RCURLY ; sphere_items: shape_items - | RADIUS number sphere_items ; subtract: SUBTRACT LCURLY boolean_items RCURLY @@ -227,6 +232,7 @@ Node::Node() type = -1; the_double = NULL; the_Material = NULL; + the_Shape = NULL; the_Vector = NULL; } @@ -236,6 +242,8 @@ Node::~Node() delete the_double; if (the_Material != NULL) delete the_Material; + if (the_Shape != NULL) + delete the_Shape; if (the_Vector != NULL) delete the_Vector; }