diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-11-26 13:51:20 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-11-26 13:51:20 -0500 |
commit | c0a0ee5ae71b97b1400efddb4c374e1d13701fa3 (patch) | |
tree | 4a121e6b3069442444e54d83fcf3fa69f08cd30c /dimension | |
parent | 02c0213ab823a0c838d295017298cf8cd3493342 (diff) | |
download | dimension-c0a0ee5ae71b97b1400efddb4c374e1d13701fa3.tar.xz |
Implement background colors.
Diffstat (limited to 'dimension')
-rw-r--r-- | dimension/grammar.y | 21 | ||||
-rw-r--r-- | dimension/lexer.l | 1 | ||||
-rw-r--r-- | dimension/parse.h | 2 | ||||
-rw-r--r-- | dimension/realize.c | 9 |
4 files changed, 28 insertions, 5 deletions
diff --git a/dimension/grammar.y b/dimension/grammar.y index ddc7418..01e2c0f 100644 --- a/dimension/grammar.y +++ b/dimension/grammar.y @@ -270,7 +270,7 @@ yyerror(YYLTYPE *locp, dmnsn_array *astree, dmnsn_token_iterator *iterator, %token DMNSN_T_AUTOSTOP %token DMNSN_T_AVERAGE %token DMNSN_T_B_SPLINE -%token DMNSN_T_BACKGROUND +%token DMNSN_T_BACKGROUND "background" %token DMNSN_T_BEZIER_SPLINE %token DMNSN_T_BICUBIC_PATCH %token DMNSN_T_BLACK_HOLE @@ -703,6 +703,10 @@ yyerror(YYLTYPE *locp, dmnsn_array *astree, dmnsn_token_iterator *iterator, /* Transformations */ %type <astnode> TRANSFORMATION +/* Atmospheric effects */ +%type <astnode> ATMOSPHERIC_EFFECT +%type <astnode> BACKGROUND + /* Objects */ %type <astnode> OBJECT %type <astnode> FINITE_SOLID_OBJECT @@ -749,7 +753,8 @@ SCENE: /* empty */ { } } ; -SCENE_ITEM: OBJECT +SCENE_ITEM: ATMOSPHERIC_EFFECT + | OBJECT ; /* Transformations */ @@ -765,6 +770,16 @@ TRANSFORMATION: "rotate" VECTOR { } ; +/* Atmospheric effects */ + +ATMOSPHERIC_EFFECT: BACKGROUND +; + +BACKGROUND: "background" "{" COLOR "}" { + $$ = dmnsn_new_astnode1(DMNSN_AST_BACKGROUND, @$, $3); + } +; + /* Objects */ OBJECT: FINITE_SOLID_OBJECT @@ -1466,6 +1481,8 @@ 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_BACKGROUND, "background"); + dmnsn_astnode_map(DMNSN_AST_BOX, "box"); dmnsn_astnode_map(DMNSN_AST_SPHERE, "sphere"); dmnsn_astnode_map(DMNSN_AST_LIGHT_SOURCE, "light_source"); diff --git a/dimension/lexer.l b/dimension/lexer.l index 58bdc0e..d91855d 100644 --- a/dimension/lexer.l +++ b/dimension/lexer.l @@ -150,6 +150,7 @@ unsigned long wchar; } (?# Keywords) +"background" PUSH_TOKEN(DMNSN_T_BACKGROUND); "box" PUSH_TOKEN(DMNSN_T_BOX); "blue" PUSH_TOKEN(DMNSN_T_BLUE); "camera" PUSH_TOKEN(DMNSN_T_CAMERA); diff --git a/dimension/parse.h b/dimension/parse.h index 1bf4436..f0bc994 100644 --- a/dimension/parse.h +++ b/dimension/parse.h @@ -29,6 +29,8 @@ typedef enum { DMNSN_AST_SCALE, DMNSN_AST_TRANSLATION, + DMNSN_AST_BACKGROUND, + DMNSN_AST_BOX, DMNSN_AST_LIGHT_SOURCE, DMNSN_AST_SPHERE, diff --git a/dimension/realize.c b/dimension/realize.c index ac0231b..8d811fc 100644 --- a/dimension/realize.c +++ b/dimension/realize.c @@ -356,9 +356,7 @@ dmnsn_realize(const dmnsn_array *astree) scene->default_texture->finish->ambient = 0.1; /* Background color */ - dmnsn_sRGB background_sRGB = { .R = 0.0, .G = 0.0, .B = 0.1 }; - scene->background = dmnsn_color_from_sRGB(background_sRGB); - scene->background.filter = 0.1; + scene->background = dmnsn_black; /* Allocate a canvas */ scene->canvas = dmnsn_new_canvas(768, 480); @@ -403,6 +401,11 @@ dmnsn_realize(const dmnsn_array *astree) dmnsn_light *light; dmnsn_object *object; switch (astnode.type) { + case DMNSN_AST_BACKGROUND: + dmnsn_array_get(astnode.children, 0, &astnode); + scene->background = dmnsn_realize_color(astnode); + break; + case DMNSN_AST_BOX: object = dmnsn_realize_box(astnode); dmnsn_array_push(scene->objects, &object); |