From 2afc9be712c69a66833de75683cdbaa3886379f1 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 9 Mar 2010 00:14:42 -0500 Subject: Implement unit vectors. --- dimension/common.rules | 6 ++++++ dimension/parse.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ dimension/parse.h | 3 +++ tests/dimension/demo.pov | 4 ++-- 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/dimension/common.rules b/dimension/common.rules index 72480c0..c03eee8 100644 --- a/dimension/common.rules +++ b/dimension/common.rules @@ -397,6 +397,12 @@ ARITH_EXPR: FLOAT_LITERAL } | "(" ARITH_EXPR ")" { $$ = $2; } | IDENTIFIER + | "x" { $$ = dmnsn_new_ast_ivector(1, 0, 0, 0, 0); } + | "u" { $$ = dmnsn_new_ast_ivector(1, 0, 0, 0, 0); } + | "y" { $$ = dmnsn_new_ast_ivector(0, 1, 0, 0, 0); } + | "v" { $$ = dmnsn_new_ast_ivector(0, 1, 0, 0, 0); } + | "z" { $$ = dmnsn_new_ast_ivector(0, 0, 1, 0, 0); } + | "t" { $$ = dmnsn_new_ast_ivector(0, 0, 0, 1, 0); } ; /* Colors */ diff --git a/dimension/parse.c b/dimension/parse.c index a4a4c43..5756659 100644 --- a/dimension/parse.c +++ b/dimension/parse.c @@ -75,6 +75,58 @@ dmnsn_new_ast_float(double value) return astnode; } +dmnsn_astnode +dmnsn_new_ast_ivector(long x, long y, long z, long f, long t) +{ + dmnsn_astnode astnode = dmnsn_new_astnode(DMNSN_AST_VECTOR); + astnode.children = dmnsn_new_array(sizeof(dmnsn_astnode)); + + dmnsn_astnode comp; + + comp = dmnsn_new_ast_integer(x); + dmnsn_array_push(astnode.children, &comp); + + comp = dmnsn_new_ast_integer(y); + dmnsn_array_push(astnode.children, &comp); + + comp = dmnsn_new_ast_integer(z); + dmnsn_array_push(astnode.children, &comp); + + comp = dmnsn_new_ast_integer(f); + dmnsn_array_push(astnode.children, &comp); + + comp = dmnsn_new_ast_integer(t); + dmnsn_array_push(astnode.children, &comp); + + return astnode; +} + +dmnsn_astnode +dmnsn_new_ast_vector(double x, double y, double z, double f, double t) +{ + dmnsn_astnode astnode = dmnsn_new_astnode(DMNSN_AST_VECTOR); + astnode.children = dmnsn_new_array(sizeof(dmnsn_astnode)); + + dmnsn_astnode comp; + + comp = dmnsn_new_ast_float(x); + dmnsn_array_push(astnode.children, &comp); + + comp = dmnsn_new_ast_float(y); + dmnsn_array_push(astnode.children, &comp); + + comp = dmnsn_new_ast_float(z); + dmnsn_array_push(astnode.children, &comp); + + comp = dmnsn_new_ast_float(f); + dmnsn_array_push(astnode.children, &comp); + + comp = dmnsn_new_ast_float(t); + dmnsn_array_push(astnode.children, &comp); + + return astnode; +} + dmnsn_astnode dmnsn_new_ast_string(const char *value) { diff --git a/dimension/parse.h b/dimension/parse.h index 8a5bb93..2d946b6 100644 --- a/dimension/parse.h +++ b/dimension/parse.h @@ -125,6 +125,9 @@ typedef dmnsn_array dmnsn_astree; dmnsn_astnode dmnsn_new_ast_array(); dmnsn_astnode dmnsn_new_ast_integer(long value); dmnsn_astnode dmnsn_new_ast_float(double value); +dmnsn_astnode dmnsn_new_ast_ivector(long x, long y, long z, long f, long t); +dmnsn_astnode dmnsn_new_ast_vector(double x, double y, double z, + double f, double t); dmnsn_astnode dmnsn_new_ast_string(const char *value); void dmnsn_delete_astnode(dmnsn_astnode astnode); diff --git a/tests/dimension/demo.pov b/tests/dimension/demo.pov index 1419e35..3ecc36f 100644 --- a/tests/dimension/demo.pov +++ b/tests/dimension/demo.pov @@ -25,7 +25,7 @@ camera { right <1.6, 0, 0> look_at <0, 0, 0> - rotate <0, 53, 0> + rotate 53*y } background { @@ -39,7 +39,7 @@ light_source { box { <-1, -1, -1>, <1, 1, 1> - rotate <45, 0, 0> + rotate 45*x texture { pigment { -- cgit v1.2.3