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
This commit is contained in:
parent
c136bda827
commit
6f2851f279
@ -2,10 +2,10 @@
|
|||||||
#include "Light.h"
|
#include "Light.h"
|
||||||
#include "util/Vector.h"
|
#include "util/Vector.h"
|
||||||
|
|
||||||
Light::Light(const Vector & position)
|
Light::Light()
|
||||||
: m_diffuse_color(Color::white),
|
|
||||||
m_specular_color(Color::white)
|
|
||||||
{
|
{
|
||||||
m_position = position;
|
m_position = Vector(0, 0, 0);
|
||||||
|
m_diffuse_color = Color::white;
|
||||||
|
m_specular_color = Color::white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,9 @@
|
|||||||
class Light
|
class Light
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Light(const Vector & position);
|
Light();
|
||||||
|
|
||||||
|
void setPosition(const Vector & position) { m_position = position; }
|
||||||
const Vector & getPosition() const { return m_position; }
|
const Vector & getPosition() const { return m_position; }
|
||||||
|
|
||||||
void setDiffuseColor(const Color & diffuse)
|
void setDiffuseColor(const Color & diffuse)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
#include "PointLight.h"
|
#include "PointLight.h"
|
||||||
|
|
||||||
PointLight::PointLight(const Vector & position)
|
PointLight::PointLight()
|
||||||
: Light(position)
|
: Light()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
class PointLight : public Light
|
class PointLight : public Light
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PointLight(const Vector & position);
|
PointLight();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
};
|
};
|
||||||
|
@ -89,7 +89,8 @@ void Scene::load(const char * filename)
|
|||||||
shape->setMaterial(m);
|
shape->setMaterial(m);
|
||||||
m_shapes.push_back(shape);
|
m_shapes.push_back(shape);
|
||||||
|
|
||||||
refptr<Light> light = new PointLight(Vector(2, -1, 2));
|
refptr<Light> light = new PointLight();
|
||||||
|
light->setPosition(Vector(2, -1, 2));
|
||||||
m_lights.push_back(light);
|
m_lights.push_back(light);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,8 @@ class Scene
|
|||||||
void setAmbientLight(const Color & al) { m_ambient_light = al; }
|
void setAmbientLight(const Color & al) { m_ambient_light = al; }
|
||||||
Transform & getTransform() { return m_transform; }
|
Transform & getTransform() { return m_transform; }
|
||||||
|
|
||||||
|
friend int yyparse();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/* private methods */
|
/* private methods */
|
||||||
void load(const char * filename);
|
void load(const char * filename);
|
||||||
|
@ -38,6 +38,7 @@ camera return CAMERA;
|
|||||||
diffuse return DIFFUSE;
|
diffuse return DIFFUSE;
|
||||||
height return HEIGHT;
|
height return HEIGHT;
|
||||||
intersect return INTERSECT;
|
intersect return INTERSECT;
|
||||||
|
light return LIGHT;
|
||||||
look_at return LOOKAT;
|
look_at return LOOKAT;
|
||||||
material return MATERIAL;
|
material return MATERIAL;
|
||||||
multisample return MULTISAMPLE;
|
multisample return MULTISAMPLE;
|
||||||
|
@ -45,11 +45,14 @@ enum Node_Type
|
|||||||
{
|
{
|
||||||
Node_Shape = 0x42001, /* don't clash with bison token namespace */
|
Node_Shape = 0x42001, /* don't clash with bison token namespace */
|
||||||
Node_Camera,
|
Node_Camera,
|
||||||
Node_Options
|
Node_Options,
|
||||||
|
Node_Light
|
||||||
};
|
};
|
||||||
|
|
||||||
#define YYSTYPE refptr<Node>
|
#define YYSTYPE refptr<Node>
|
||||||
|
|
||||||
|
static Scene * g_scene;
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%token PLUS;
|
%token PLUS;
|
||||||
@ -85,6 +88,7 @@ enum Node_Type
|
|||||||
%token DIFFUSE;
|
%token DIFFUSE;
|
||||||
%token HEIGHT;
|
%token HEIGHT;
|
||||||
%token INTERSECT;
|
%token INTERSECT;
|
||||||
|
%token LIGHT;
|
||||||
%token LOOKAT;
|
%token LOOKAT;
|
||||||
%token MATERIAL;
|
%token MATERIAL;
|
||||||
%token MULTISAMPLE;
|
%token MULTISAMPLE;
|
||||||
@ -111,6 +115,18 @@ scene: SCENE LCURLY scene_items RCURLY {
|
|||||||
{
|
{
|
||||||
/* process this scene item */
|
/* process this scene item */
|
||||||
refptr<Node> thisNode = node->the_Node;
|
refptr<Node> 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;
|
node = node->the_tail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,6 +188,47 @@ camera_item: POSITION vector {
|
|||||||
intersect: INTERSECT LCURLY boolean_items RCURLY
|
intersect: INTERSECT LCURLY boolean_items RCURLY
|
||||||
;
|
;
|
||||||
|
|
||||||
|
light: LIGHT LCURLY light_items RCURLY {
|
||||||
|
$$ = new Node();
|
||||||
|
refptr<Light> light = new Light();
|
||||||
|
refptr<Node> 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 {
|
material: MATERIAL LCURLY material_items RCURLY {
|
||||||
$$ = new Node();
|
$$ = new Node();
|
||||||
refptr<Material> material = new Material();
|
refptr<Material> material = new Material();
|
||||||
@ -302,6 +359,7 @@ scene_items: /* empty */
|
|||||||
scene_item: camera { $$ = $1; $$->type = Node_Camera; }
|
scene_item: camera { $$ = $1; $$->type = Node_Camera; }
|
||||||
| shape { $$ = $1; $$->type = Node_Shape; }
|
| shape { $$ = $1; $$->type = Node_Shape; }
|
||||||
| options { $$ = $1; $$->type = Node_Options; }
|
| options { $$ = $1; $$->type = Node_Options; }
|
||||||
|
| light { $$ = $1; $$->type = Node_Light; }
|
||||||
;
|
;
|
||||||
|
|
||||||
shape: plane { $$ = $1; }
|
shape: plane { $$ = $1; }
|
||||||
@ -346,6 +404,7 @@ vector: LESS number COMMA number COMMA number GREATER {
|
|||||||
|
|
||||||
int Scene::parse(const char * fileName)
|
int Scene::parse(const char * fileName)
|
||||||
{
|
{
|
||||||
|
g_scene = this;
|
||||||
yyin = fopen(fileName, "r");
|
yyin = fopen(fileName, "r");
|
||||||
if (yyin == NULL)
|
if (yyin == NULL)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user