diff options
Diffstat (limited to 'dimension')
-rw-r--r-- | dimension/grammar.y | 85 | ||||
-rw-r--r-- | dimension/lexer.l | 8 | ||||
-rw-r--r-- | dimension/parse.h | 10 | ||||
-rw-r--r-- | dimension/realize.c | 3 |
4 files changed, 98 insertions, 8 deletions
diff --git a/dimension/grammar.y b/dimension/grammar.y index 01e2c0f..1a3e200 100644 --- a/dimension/grammar.y +++ b/dimension/grammar.y @@ -253,7 +253,7 @@ yyerror(YYLTYPE *locp, dmnsn_array *astree, dmnsn_token_iterator *iterator, %token DMNSN_T_ALWAYS_SAMPLE %token DMNSN_T_AMBIENT %token DMNSN_T_AMBIENT_LIGHT -%token DMNSN_T_ANGLE +%token DMNSN_T_ANGLE "angle" %token DMNSN_T_APERTURE %token DMNSN_T_APPEND %token DMNSN_T_ARC_ANGLE @@ -337,7 +337,7 @@ yyerror(YYLTYPE *locp, dmnsn_array *astree, dmnsn_token_iterator *iterator, %token DMNSN_T_DIFFUSE %token DMNSN_T_DIMENSION_SIZE %token DMNSN_T_DIMENSIONS -%token DMNSN_T_DIRECTION +%token DMNSN_T_DIRECTION "direction" %token DMNSN_T_DISC %token DMNSN_T_DISPERSION %token DMNSN_T_DISPERSION_SAMPLES @@ -430,9 +430,9 @@ yyerror(YYLTYPE *locp, dmnsn_array *astree, dmnsn_token_iterator *iterator, %token DMNSN_T_LINEAR_SWEEP %token DMNSN_T_LN %token DMNSN_T_LOAD_FILE -%token DMNSN_T_LOCATION +%token DMNSN_T_LOCATION "location" %token DMNSN_T_LOG -%token DMNSN_T_LOOK_AT +%token DMNSN_T_LOOK_AT "look_at" %token DMNSN_T_LOOKS_LIKE %token DMNSN_T_LOW_ERROR_FACTOR %token DMNSN_T_MAGNET @@ -496,7 +496,7 @@ yyerror(YYLTYPE *locp, dmnsn_array *astree, dmnsn_token_iterator *iterator, %token DMNSN_T_PARAMETRIC %token DMNSN_T_PASS_THROUGH %token DMNSN_T_PATTERN -%token DMNSN_T_PERSPECTIVE +%token DMNSN_T_PERSPECTIVE "perspective" %token DMNSN_T_PGM %token DMNSN_T_PHASE %token DMNSN_T_PHONG @@ -549,7 +549,7 @@ yyerror(YYLTYPE *locp, dmnsn_array *astree, dmnsn_token_iterator *iterator, %token DMNSN_T_RGBF "rgbf" %token DMNSN_T_RGBFT "rgbft" %token DMNSN_T_RGBT "rgbt" -%token DMNSN_T_RIGHT +%token DMNSN_T_RIGHT "right" %token DMNSN_T_RIPPLES %token DMNSN_T_ROTATE "rotate" %token DMNSN_T_ROUGHNESS @@ -565,7 +565,7 @@ yyerror(YYLTYPE *locp, dmnsn_array *astree, dmnsn_token_iterator *iterator, %token DMNSN_T_SINE_WAVE %token DMNSN_T_SINH %token DMNSN_T_SIZE -%token DMNSN_T_SKY +%token DMNSN_T_SKY "sky" %token DMNSN_T_SKY_SPHERE %token DMNSN_T_SLICE %token DMNSN_T_SLOPE @@ -631,7 +631,7 @@ yyerror(YYLTYPE *locp, dmnsn_array *astree, dmnsn_token_iterator *iterator, %token DMNSN_T_U_STEPS %token DMNSN_T_ULTRA_WIDE_ANGLE %token DMNSN_T_UNION -%token DMNSN_T_UP +%token DMNSN_T_UP "up" %token DMNSN_T_USE_ALPHA %token DMNSN_T_USE_COLOR %token DMNSN_T_USE_INDEX @@ -703,6 +703,14 @@ yyerror(YYLTYPE *locp, dmnsn_array *astree, dmnsn_token_iterator *iterator, /* Transformations */ %type <astnode> TRANSFORMATION +/* The camera */ +%type <astnode> CAMERA +%type <astnode> CAMERA_ITEMS +%type <astnode> CAMERA_ITEM +%type <astnode> CAMERA_TYPE +%type <astnode> CAMERA_VECTOR +%type <astnode> CAMERA_MODIFIER + /* Atmospheric effects */ %type <astnode> ATMOSPHERIC_EFFECT %type <astnode> BACKGROUND @@ -754,6 +762,7 @@ SCENE: /* empty */ { } ; SCENE_ITEM: ATMOSPHERIC_EFFECT + | CAMERA | OBJECT ; @@ -770,6 +779,56 @@ TRANSFORMATION: "rotate" VECTOR { } ; +/* Cameras */ + +CAMERA: "camera" "{" + CAMERA_ITEMS + "}" + { + $$ = $3; + } +; + +CAMERA_ITEMS: /* empty */ { + $$ = dmnsn_new_astnode(DMNSN_AST_CAMERA, @$); + } + | CAMERA_ITEMS CAMERA_ITEM { + $$ = $1; + dmnsn_array_push($$.children, &$2); + } + +CAMERA_ITEM: CAMERA_TYPE + | CAMERA_VECTOR + | CAMERA_MODIFIER + +CAMERA_TYPE: "perspective" { + $$ = dmnsn_new_astnode(DMNSN_AST_PERSPECTIVE, @$); + } + +CAMERA_VECTOR: "location" VECTOR { + $$ = dmnsn_new_astnode1(DMNSN_AST_LOCATION, @$, $2); + } + | "right" VECTOR { + $$ = dmnsn_new_astnode1(DMNSN_AST_RIGHT, @$, $2); + } + | "up" VECTOR { + $$ = dmnsn_new_astnode1(DMNSN_AST_UP, @$, $2); + } + | "sky" VECTOR { + $$ = dmnsn_new_astnode1(DMNSN_AST_SKY, @$, $2); + } + | "direction" VECTOR { + $$ = dmnsn_new_astnode1(DMNSN_AST_DIRECTION, @$, $2); + } + +CAMERA_MODIFIER: "angle" FLOAT { + $$ = dmnsn_new_astnode1(DMNSN_AST_ANGLE, @$, $2); + } + | "look_at" VECTOR { + $$ = dmnsn_new_astnode1(DMNSN_AST_LOOK_AT, @$, $2); + } + | TRANSFORMATION + /* Atmospheric effects */ ATMOSPHERIC_EFFECT: BACKGROUND @@ -1481,6 +1540,16 @@ dmnsn_astnode_string(dmnsn_astnode_type astnode_type) dmnsn_astnode_map(DMNSN_AST_SCALE, "scale"); dmnsn_astnode_map(DMNSN_AST_TRANSLATION, "translate"); + dmnsn_astnode_map(DMNSN_AST_CAMERA, "camera"); + dmnsn_astnode_map(DMNSN_AST_PERSPECTIVE, "perspective"); + dmnsn_astnode_map(DMNSN_AST_LOCATION, "location"); + dmnsn_astnode_map(DMNSN_AST_RIGHT, "right"); + dmnsn_astnode_map(DMNSN_AST_UP, "up"); + dmnsn_astnode_map(DMNSN_AST_SKY, "sky"); + dmnsn_astnode_map(DMNSN_AST_ANGLE, "angle"); + dmnsn_astnode_map(DMNSN_AST_LOOK_AT, "look_at"); + dmnsn_astnode_map(DMNSN_AST_DIRECTION, "direction"); + dmnsn_astnode_map(DMNSN_AST_BACKGROUND, "background"); dmnsn_astnode_map(DMNSN_AST_BOX, "box"); diff --git a/dimension/lexer.l b/dimension/lexer.l index d91855d..bfe5b8a 100644 --- a/dimension/lexer.l +++ b/dimension/lexer.l @@ -150,29 +150,37 @@ unsigned long wchar; } (?# Keywords) +"angle" PUSH_TOKEN(DMNSN_T_ANGLE); "background" PUSH_TOKEN(DMNSN_T_BACKGROUND); "box" PUSH_TOKEN(DMNSN_T_BOX); "blue" PUSH_TOKEN(DMNSN_T_BLUE); "camera" PUSH_TOKEN(DMNSN_T_CAMERA); "color" PUSH_TOKEN(DMNSN_T_COLOR); "colour" PUSH_TOKEN(DMNSN_T_COLOR); +"direction" PUSH_TOKEN(DMNSN_T_DIRECTION); "filter" PUSH_TOKEN(DMNSN_T_FILTER); "gray" PUSH_TOKEN(DMNSN_T_GRAY); "grey" PUSH_TOKEN(DMNSN_T_GRAY); "green" PUSH_TOKEN(DMNSN_T_GREEN); +"location" PUSH_TOKEN(DMNSN_T_LOCATION); +"look_at" PUSH_TOKEN(DMNSN_T_LOOK_AT); "light_source" PUSH_TOKEN(DMNSN_T_LIGHT_SOURCE); +"perspective" PUSH_TOKEN(DMNSN_T_PERSPECTIVE); "pigment" PUSH_TOKEN(DMNSN_T_PIGMENT); "red" PUSH_TOKEN(DMNSN_T_RED); "rgb" PUSH_TOKEN(DMNSN_T_RGB); "rgbf" PUSH_TOKEN(DMNSN_T_RGBF); "rgbft" PUSH_TOKEN(DMNSN_T_RGBFT); "rgbt" PUSH_TOKEN(DMNSN_T_RGBT); +"right" PUSH_TOKEN(DMNSN_T_RIGHT); "rotate" PUSH_TOKEN(DMNSN_T_ROTATE); "sphere" PUSH_TOKEN(DMNSN_T_SPHERE); +"sky" PUSH_TOKEN(DMNSN_T_SKY); "t" PUSH_TOKEN(DMNSN_T_T); "texture" PUSH_TOKEN(DMNSN_T_TEXTURE); "transmit" PUSH_TOKEN(DMNSN_T_TRANSMIT); "u" PUSH_TOKEN(DMNSN_T_U); +"up" PUSH_TOKEN(DMNSN_T_UP); "v" PUSH_TOKEN(DMNSN_T_V); "x" PUSH_TOKEN(DMNSN_T_X); "y" PUSH_TOKEN(DMNSN_T_Y); diff --git a/dimension/parse.h b/dimension/parse.h index f0bc994..d6c6b0e 100644 --- a/dimension/parse.h +++ b/dimension/parse.h @@ -29,6 +29,16 @@ typedef enum { DMNSN_AST_SCALE, DMNSN_AST_TRANSLATION, + DMNSN_AST_CAMERA, + DMNSN_AST_PERSPECTIVE, + DMNSN_AST_LOCATION, + DMNSN_AST_RIGHT, + DMNSN_AST_UP, + DMNSN_AST_SKY, + DMNSN_AST_ANGLE, + DMNSN_AST_LOOK_AT, + DMNSN_AST_DIRECTION, + DMNSN_AST_BACKGROUND, DMNSN_AST_BOX, diff --git a/dimension/realize.c b/dimension/realize.c index 8d811fc..4832fd2 100644 --- a/dimension/realize.c +++ b/dimension/realize.c @@ -401,6 +401,9 @@ dmnsn_realize(const dmnsn_array *astree) dmnsn_light *light; dmnsn_object *object; switch (astnode.type) { + case DMNSN_AST_CAMERA: + break; + case DMNSN_AST_BACKGROUND: dmnsn_array_get(astnode.children, 0, &astnode); scene->background = dmnsn_realize_color(astnode); |