From 6f2851f2799c061bcce842821ff27081ac38fad0 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 12 Feb 2009 03:56:09 +0000 Subject: [PATCH] yyparse() now a friend function to Scene, light constructors not taking position arguments any more git-svn-id: svn://anubis/fart/trunk@104 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- main/Light.cc | 8 +++--- main/Light.h | 4 ++- main/PointLight.cc | 4 +-- main/PointLight.h | 2 +- main/Scene.cc | 3 ++- main/Scene.h | 2 ++ parser/parser.lex | 1 + parser/parser.yy | 61 +++++++++++++++++++++++++++++++++++++++++++++- 8 files changed, 75 insertions(+), 10 deletions(-) diff --git a/main/Light.cc b/main/Light.cc index 95543b5..4012c75 100644 --- a/main/Light.cc +++ b/main/Light.cc @@ -2,10 +2,10 @@ #include "Light.h" #include "util/Vector.h" -Light::Light(const Vector & position) - : m_diffuse_color(Color::white), - m_specular_color(Color::white) +Light::Light() { - m_position = position; + m_position = Vector(0, 0, 0); + m_diffuse_color = Color::white; + m_specular_color = Color::white; } diff --git a/main/Light.h b/main/Light.h index 9a37068..26cd0ec 100644 --- a/main/Light.h +++ b/main/Light.h @@ -8,7 +8,9 @@ class Light { public: - Light(const Vector & position); + Light(); + + void setPosition(const Vector & position) { m_position = position; } const Vector & getPosition() const { return m_position; } void setDiffuseColor(const Color & diffuse) diff --git a/main/PointLight.cc b/main/PointLight.cc index 448b277..5b8d06b 100755 --- a/main/PointLight.cc +++ b/main/PointLight.cc @@ -1,7 +1,7 @@ #include "PointLight.h" -PointLight::PointLight(const Vector & position) - : Light(position) +PointLight::PointLight() + : Light() { } diff --git a/main/PointLight.h b/main/PointLight.h index 04825a5..69bbed5 100644 --- a/main/PointLight.h +++ b/main/PointLight.h @@ -8,7 +8,7 @@ class PointLight : public Light { public: - PointLight(const Vector & position); + PointLight(); protected: }; diff --git a/main/Scene.cc b/main/Scene.cc index b397565..a6350c1 100644 --- a/main/Scene.cc +++ b/main/Scene.cc @@ -89,7 +89,8 @@ void Scene::load(const char * filename) shape->setMaterial(m); m_shapes.push_back(shape); - refptr light = new PointLight(Vector(2, -1, 2)); + refptr light = new PointLight(); + light->setPosition(Vector(2, -1, 2)); m_lights.push_back(light); } diff --git a/main/Scene.h b/main/Scene.h index 99e3c34..a0aa43d 100644 --- a/main/Scene.h +++ b/main/Scene.h @@ -39,6 +39,8 @@ class Scene void setAmbientLight(const Color & al) { m_ambient_light = al; } Transform & getTransform() { return m_transform; } + friend int yyparse(); + protected: /* private methods */ void load(const char * filename); diff --git a/parser/parser.lex b/parser/parser.lex index 78d138e..d69d8f8 100644 --- a/parser/parser.lex +++ b/parser/parser.lex @@ -38,6 +38,7 @@ camera return CAMERA; diffuse return DIFFUSE; height return HEIGHT; intersect return INTERSECT; +light return LIGHT; look_at return LOOKAT; material return MATERIAL; multisample return MULTISAMPLE; diff --git a/parser/parser.yy b/parser/parser.yy index 825da1b..4a73c2e 100644 --- a/parser/parser.yy +++ b/parser/parser.yy @@ -45,11 +45,14 @@ enum Node_Type { Node_Shape = 0x42001, /* don't clash with bison token namespace */ Node_Camera, - Node_Options + Node_Options, + Node_Light }; #define YYSTYPE refptr +static Scene * g_scene; + %} %token PLUS; @@ -85,6 +88,7 @@ enum Node_Type %token DIFFUSE; %token HEIGHT; %token INTERSECT; +%token LIGHT; %token LOOKAT; %token MATERIAL; %token MULTISAMPLE; @@ -111,6 +115,18 @@ scene: SCENE LCURLY scene_items RCURLY { { /* process this scene item */ refptr thisNode = node->the_Node; + switch (thisNode->type) + { + case Node_Shape: + g_scene->m_shapes.push_back(thisNode->the_Shape); + break; + case Node_Camera: + break; + case Node_Light: + break; + case Node_Options: + break; + } node = node->the_tail; } } @@ -172,6 +188,47 @@ camera_item: POSITION vector { intersect: INTERSECT LCURLY boolean_items RCURLY ; +light: LIGHT LCURLY light_items RCURLY { + $$ = new Node(); + refptr light = new Light(); + refptr node = $3; + while ( ! node.isNull() ) + { + switch (node->type) + { + case POSITION: + break; + } + node = node->the_tail; + } + } + ; + +light_items: /* empty */ + | light_item light_items { + $$ = new Node(); + $$->the_Node = $1; + $$->the_tail = $2; + } + ; + +light_item: POSITION vector { + $$ = new Node(); + $$->type = POSITION; + $$->the_Vector = $2->the_Vector; + } + | DIFFUSE vector { + $$ = new Node(); + $$->type = DIFFUSE; + $$->the_Color = new Color(* $2->the_Vector); + } + | SPECULAR vector { + $$ = new Node(); + $$->type = SPECULAR; + $$->the_Color = new Color(* $2->the_Vector); + } + ; + material: MATERIAL LCURLY material_items RCURLY { $$ = new Node(); refptr material = new Material(); @@ -302,6 +359,7 @@ scene_items: /* empty */ scene_item: camera { $$ = $1; $$->type = Node_Camera; } | shape { $$ = $1; $$->type = Node_Shape; } | options { $$ = $1; $$->type = Node_Options; } + | light { $$ = $1; $$->type = Node_Light; } ; shape: plane { $$ = $1; } @@ -346,6 +404,7 @@ vector: LESS number COMMA number COMMA number GREATER { int Scene::parse(const char * fileName) { + g_scene = this; yyin = fopen(fileName, "r"); if (yyin == NULL) {