summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dimension/grammar.y85
-rw-r--r--dimension/lexer.l8
-rw-r--r--dimension/parse.h10
-rw-r--r--dimension/realize.c3
-rw-r--r--tests/dimension/demo.pov8
-rwxr-xr-xtests/dimension/demo.sh11
6 files changed, 116 insertions, 9 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);
diff --git a/tests/dimension/demo.pov b/tests/dimension/demo.pov
index c6f99fb..67113cf 100644
--- a/tests/dimension/demo.pov
+++ b/tests/dimension/demo.pov
@@ -19,6 +19,14 @@
// Render demo scene
+camera {
+ perspective
+ location <0, 0, -4>
+ right <768/480, 0, 0>
+ rotate <0, 53, 0>
+ look_at <0, 0, 0>
+}
+
background {
color rgbf <0, 0, 0.1, 0.1>
}
diff --git a/tests/dimension/demo.sh b/tests/dimension/demo.sh
index 0d8da5a..31bb3ce 100755
--- a/tests/dimension/demo.sh
+++ b/tests/dimension/demo.sh
@@ -21,7 +21,16 @@
demo=$(${top_builddir}/dimension/dimension --parse ${srcdir}/demo.pov)
demo_exp=$(echo -n \
-'((background
+'((camera
+ perspective
+ (location (vector (integer 0) (integer 0) (integer -4)
+ (integer 0) (integer 0)))
+ (right (vector (float 1.6) (integer 0) (integer 0) (integer 0) (integer 0)))
+ (rotate (vector (integer 0) (integer 53) (integer 0)
+ (integer 0) (integer 0)))
+ (look_at (vector (integer 0) (integer 0) (integer 0)
+ (integer 0) (integer 0))))
+ (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))