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 | |
parent | 02c0213ab823a0c838d295017298cf8cd3493342 (diff) | |
download | dimension-c0a0ee5ae71b97b1400efddb4c374e1d13701fa3.tar.xz |
Implement background colors.
-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 | ||||
-rw-r--r-- | tests/dimension/demo.pov | 10 | ||||
-rwxr-xr-x | tests/dimension/demo.sh | 31 |
6 files changed, 41 insertions, 33 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); diff --git a/tests/dimension/demo.pov b/tests/dimension/demo.pov index b6833bc..c6f99fb 100644 --- a/tests/dimension/demo.pov +++ b/tests/dimension/demo.pov @@ -19,21 +19,25 @@ // Render demo scene +background { + color rgbf <0, 0, 0.1, 0.1> +} + light_source { - <-15, 20, 10>, rgb <1, 1, 1> + <-15, 20, 10>, color rgb <1, 1, 1> } box { <-1, -1, -1>, <1, 1, 1> rotate <45, 0, 0> pigment { - rgbft <0, 0, 1, 0.25, 0.25> + color rgbft <0, 0, 1, 0.25, 0.25> } } sphere { <0, 0, 0>, 1.25 pigment { - rgb <0, 1, 0> + color rgb <0, 1, 0> } } diff --git a/tests/dimension/demo.sh b/tests/dimension/demo.sh index fbd6fc3..0d8da5a 100755 --- a/tests/dimension/demo.sh +++ b/tests/dimension/demo.sh @@ -19,30 +19,11 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # ######################################################################### -demo=$(${top_builddir}/dimension/dimension --tokenize --parse ${srcdir}/demo.pov) -demo_exp="$(echo -n \ -'(light_source { - < - (integer "15") , (integer "20") , (integer "10") > , - rgb < (integer "1") , (integer "1") , (integer "1") > - } - box { - < - (integer "1") , - (integer "1") , - (integer "1") > , - < (integer "1") , (integer "1") , (integer "1") > - rotate < (integer "45") , (integer "0") , (integer "0") > - pigment { - rgbft < (integer "0") , (integer "0") , (integer "1") , - (float "0.25") , (float "0.25") > - } - } - sphere { - < (integer "0") , (integer "0") , (integer "0") > , (float "1.25") - pigment { - rgb < (integer "0") , (integer "1") , (integer "0") > - } - })' \ -| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g') -$(echo -n \ -'((light_source +demo=$(${top_builddir}/dimension/dimension --parse ${srcdir}/demo.pov) +demo_exp=$(echo -n \ +'((background + (vector (integer 0) (integer 0) (float 0.1) (float 0.1) (integer 0))) + (light_source (vector (integer -15) (integer 20) (integer 10) (integer 0) (integer 0)) (vector (integer 1) (integer 1) (integer 1) (integer 0) (integer 0))) (box @@ -61,7 +42,7 @@ $(echo -n \ (texture (pigment (vector (integer 0) (integer 1) (integer 0) (integer 0) (integer 0)))))))' \ -| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g')" +| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g') if [ "$demo" != "$demo_exp" ]; then echo "demo.pov parsed as \"$demo\"" >&2 |