diff options
Diffstat (limited to 'dimension')
-rw-r--r-- | dimension/common.nonterminals | 1 | ||||
-rw-r--r-- | dimension/common.rules | 13 | ||||
-rw-r--r-- | dimension/common.terminals | 2 | ||||
-rw-r--r-- | dimension/grammar.epilogue | 1 | ||||
-rw-r--r-- | dimension/lexer.l | 1 | ||||
-rw-r--r-- | dimension/parse.h | 1 | ||||
-rw-r--r-- | dimension/realize.c | 30 |
7 files changed, 39 insertions, 10 deletions
diff --git a/dimension/common.nonterminals b/dimension/common.nonterminals index 09a4f5f..ad95ccb 100644 --- a/dimension/common.nonterminals +++ b/dimension/common.nonterminals @@ -40,6 +40,7 @@ %type <astnode> OBJECT %type <astnode> FINITE_SOLID_OBJECT %type <astnode> BOX +%type <astnode> CONE %type <astnode> CYLINDER %type <astnode> MAYBE_OPEN %type <astnode> SPHERE diff --git a/dimension/common.rules b/dimension/common.rules index d91cac3..040f4a6 100644 --- a/dimension/common.rules +++ b/dimension/common.rules @@ -283,6 +283,7 @@ OBJECT: FINITE_SOLID_OBJECT ; FINITE_SOLID_OBJECT: BOX + | CONE | CYLINDER | SPHERE ; @@ -297,6 +298,18 @@ BOX: "box" "{" } ; +CONE: "cone" "{" + VECTOR "," FLOAT "," VECTOR "," FLOAT + MAYBE_OPEN + OBJECT_MODIFIERS + "}" + { + dmnsn_astnode object + = dmnsn_new_astnode5(DMNSN_AST_CONE, @$, $3, $5, $7, $9, $10); + $$ = dmnsn_new_astnode2(DMNSN_AST_OBJECT, @$, object, $11); + } +; + CYLINDER: "cylinder" "{" VECTOR "," VECTOR "," FLOAT MAYBE_OPEN diff --git a/dimension/common.terminals b/dimension/common.terminals index af75bb4..ffe13dc 100644 --- a/dimension/common.terminals +++ b/dimension/common.terminals @@ -134,7 +134,7 @@ %token DMNSN_T_COMPONENT %token DMNSN_T_COMPOSITE %token DMNSN_T_CONCAT -%token DMNSN_T_CONE +%token DMNSN_T_CONE "cone" %token DMNSN_T_CONFIDENCE %token DMNSN_T_CONIC_SWEEP %token DMNSN_T_CONSERVE_ENERGY diff --git a/dimension/grammar.epilogue b/dimension/grammar.epilogue index d766a07..6e5a90b 100644 --- a/dimension/grammar.epilogue +++ b/dimension/grammar.epilogue @@ -134,6 +134,7 @@ dmnsn_astnode_string(dmnsn_astnode_type astnode_type) dmnsn_astnode_map(DMNSN_AST_OBJECT, "object"); dmnsn_astnode_map(DMNSN_AST_BOX, "box"); + dmnsn_astnode_map(DMNSN_AST_CONE, "cone"); dmnsn_astnode_map(DMNSN_AST_CYLINDER, "cylinder"); dmnsn_astnode_map(DMNSN_AST_DIFFERENCE, "difference"); dmnsn_astnode_map(DMNSN_AST_INTERSECTION, "intersection"); diff --git a/dimension/lexer.l b/dimension/lexer.l index dd25363..c871b91 100644 --- a/dimension/lexer.l +++ b/dimension/lexer.l @@ -184,6 +184,7 @@ unsigned long wchar; "camera" RETURN_TOKEN(DMNSN_T_CAMERA); "color" RETURN_TOKEN(DMNSN_T_COLOR); "colour" RETURN_TOKEN(DMNSN_T_COLOR); +"cone" RETURN_TOKEN(DMNSN_T_CONE); "cos" RETURN_TOKEN(DMNSN_T_COS); "cosh" RETURN_TOKEN(DMNSN_T_COSH); "cylinder" RETURN_TOKEN(DMNSN_T_CYLINDER); diff --git a/dimension/parse.h b/dimension/parse.h index d9b9195..556465e 100644 --- a/dimension/parse.h +++ b/dimension/parse.h @@ -48,6 +48,7 @@ typedef enum { DMNSN_AST_OBJECT, DMNSN_AST_BOX, + DMNSN_AST_CONE, DMNSN_AST_CYLINDER, DMNSN_AST_DIFFERENCE, DMNSN_AST_INTERSECTION, diff --git a/dimension/realize.c b/dimension/realize.c index dc315d8..b5f6e50 100644 --- a/dimension/realize.c +++ b/dimension/realize.c @@ -845,17 +845,28 @@ dmnsn_realize_box(dmnsn_astnode astnode) static dmnsn_object * dmnsn_realize_cylinder(dmnsn_astnode astnode) { - dmnsn_assert(astnode.type == DMNSN_AST_CYLINDER, "Expected a cylinder."); - - dmnsn_astnode pnode1, pnode2, radius, open; - dmnsn_array_get(astnode.children, 0, &pnode1); - dmnsn_array_get(astnode.children, 1, &pnode2); - dmnsn_array_get(astnode.children, 2, &radius); - dmnsn_array_get(astnode.children, 3, &open); + dmnsn_astnode pnode1, rnode1, pnode2, rnode2, open; + + if (astnode.type == DMNSN_AST_CONE) { + dmnsn_array_get(astnode.children, 0, &pnode1); + dmnsn_array_get(astnode.children, 1, &rnode1); + dmnsn_array_get(astnode.children, 2, &pnode2); + dmnsn_array_get(astnode.children, 3, &rnode2); + dmnsn_array_get(astnode.children, 4, &open); + } else if (astnode.type == DMNSN_AST_CYLINDER) { + dmnsn_array_get(astnode.children, 0, &pnode1); + dmnsn_array_get(astnode.children, 1, &pnode2); + dmnsn_array_get(astnode.children, 2, &rnode1); + dmnsn_array_get(astnode.children, 2, &rnode2); + dmnsn_array_get(astnode.children, 3, &open); + } else { + dmnsn_assert(false, "Expected a cone or cylinder."); + } dmnsn_vector p1 = dmnsn_realize_vector(pnode1); dmnsn_vector p2 = dmnsn_realize_vector(pnode2); - double r = dmnsn_realize_float(radius); + double r1 = dmnsn_realize_float(rnode1); + double r2 = dmnsn_realize_float(rnode2); dmnsn_vector dir = dmnsn_vector_sub(p2, p1); double l = dmnsn_vector_norm(dir); @@ -864,7 +875,7 @@ dmnsn_realize_cylinder(dmnsn_astnode astnode) double theta2 = dmnsn_vector_axis_angle(dmnsn_y, dir, dmnsn_z); dmnsn_object *cylinder - = dmnsn_new_cylinder(r, r, dmnsn_realize_integer(open)); + = dmnsn_new_cylinder(r1, r2, dmnsn_realize_integer(open)); /* Transformations: lift the cylinder to start at the origin, scale, rotate, and translate properly */ cylinder->trans = dmnsn_translation_matrix(dmnsn_new_vector(0.0, 1.0, 0.0)); @@ -1034,6 +1045,7 @@ dmnsn_realize_object(dmnsn_astnode astnode, dmnsn_array *lights) case DMNSN_AST_BOX: object = dmnsn_realize_box(onode); break; + case DMNSN_AST_CONE: case DMNSN_AST_CYLINDER: object = dmnsn_realize_cylinder(onode); break; |