added the_Color to Node, material gathering AMBIENT, DIFFUSE, SPECULAR color values

git-svn-id: svn://anubis/fart/trunk@103 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-02-12 03:07:22 +00:00
parent 8a112009a6
commit c136bda827
6 changed files with 83 additions and 10 deletions

View File

@ -7,5 +7,6 @@ Material::Material()
{ {
m_diffuse_color = Color::white; m_diffuse_color = Color::white;
m_specular_color = Color::white; m_specular_color = Color::white;
m_shininess = 50; m_shininess = 50.0;
m_reflectance = 0.0;
} }

View File

@ -33,11 +33,15 @@ class Material
void setShininess(double shininess) { m_shininess = shininess; } void setShininess(double shininess) { m_shininess = shininess; }
double getShininess() const { return m_shininess; } double getShininess() const { return m_shininess; }
void setReflectance(double reflectance) { m_reflectance = reflectance; }
double getReflectance() const { return m_reflectance; }
protected: protected:
Color m_ambient_color; Color m_ambient_color;
Color m_diffuse_color; Color m_diffuse_color;
Color m_specular_color; Color m_specular_color;
double m_shininess; double m_shininess;
double m_reflectance;
}; };
#endif #endif

View File

@ -32,9 +32,10 @@
-?[0-9]+ return DEC_NUMBER; -?[0-9]+ return DEC_NUMBER;
-?[0-9]*\.[0-9]+ return REAL_NUMBER; -?[0-9]*\.[0-9]+ return REAL_NUMBER;
ambient return AMBIENT;
box return BOX; box return BOX;
camera return CAMERA; camera return CAMERA;
color return COLOR; diffuse return DIFFUSE;
height return HEIGHT; height return HEIGHT;
intersect return INTERSECT; intersect return INTERSECT;
look_at return LOOKAT; look_at return LOOKAT;
@ -47,6 +48,7 @@ reflectance return REFLECTANCE;
scene return SCENE; scene return SCENE;
shininess return SHININESS; shininess return SHININESS;
size return SIZE; size return SIZE;
specular return SPECULAR;
sphere return SPHERE; sphere return SPHERE;
subtract return SUBTRACT; subtract return SUBTRACT;
union return UNION; union return UNION;

View File

@ -33,11 +33,12 @@ class Node
Node(); Node();
int type; int type;
refptr<double> the_double; refptr<double> the_double;
refptr<Material> the_Material;
refptr<Node> the_Node; refptr<Node> the_Node;
refptr<Node> the_tail; refptr<Node> the_tail;
refptr<Material> the_Material;
refptr<Shape> the_Shape; refptr<Shape> the_Shape;
refptr<Vector> the_Vector; refptr<Vector> the_Vector;
refptr<Color> the_Color;
}; };
enum Node_Type enum Node_Type
@ -78,9 +79,10 @@ enum Node_Type
%token DEC_NUMBER; %token DEC_NUMBER;
%token REAL_NUMBER; %token REAL_NUMBER;
%token AMBIENT;
%token BOX; %token BOX;
%token CAMERA; %token CAMERA;
%token COLOR; %token DIFFUSE;
%token HEIGHT; %token HEIGHT;
%token INTERSECT; %token INTERSECT;
%token LOOKAT; %token LOOKAT;
@ -93,6 +95,7 @@ enum Node_Type
%token SCENE; %token SCENE;
%token SHININESS; %token SHININESS;
%token SIZE; %token SIZE;
%token SPECULAR;
%token SPHERE; %token SPHERE;
%token SUBTRACT; %token SUBTRACT;
%token UNION; %token UNION;
@ -103,10 +106,24 @@ enum Node_Type
%% %%
scene: SCENE LCURLY scene_items RCURLY { scene: SCENE LCURLY scene_items RCURLY {
refptr<Node> node = $3;
while ( ! node.isNull() )
{
/* process this scene item */
refptr<Node> thisNode = node->the_Node;
node = node->the_tail;
}
} }
; ;
boolean_items: shape shape boolean_items_more boolean_items: shape shape boolean_items_more {
$$ = new Node();
$$->the_Node = $1;
$$->the_tail = new Node();
$$->the_tail->the_Node = $2;
$$->the_tail->the_tail = new Node();
$$->the_tail->the_tail->the_Node = $3;
}
; ;
boolean_items_more: /* empty */ boolean_items_more: /* empty */
@ -155,17 +172,57 @@ camera_item: POSITION vector {
intersect: INTERSECT LCURLY boolean_items RCURLY intersect: INTERSECT LCURLY boolean_items RCURLY
; ;
material: MATERIAL LCURLY material_items RCURLY material: MATERIAL LCURLY material_items RCURLY {
$$ = new Node();
refptr<Material> material = new Material();
refptr<Node> node = $3;
while ( ! node.isNull() )
{
switch (node->type)
{
case AMBIENT:
material->setAmbientColor(*node->the_Color);
break;
case DIFFUSE:
material->setDiffuseColor(* node->the_Color);
break;
case SPECULAR:
material->setSpecularColor(* node->the_Color);
break;
case SHININESS:
material->setShininess(* node->the_double);
break;
case REFLECTANCE:
material->setReflectance(* node->the_double);
break;
}
node = node->the_Node;
}
}
; ;
material_items: /* empty */ material_items: /* empty */
| material_item material_items | material_item material_items {
$$ = new Node();
$$->the_Node = $1;
$$->the_tail = $2;
}
; ;
material_item: COLOR vector { material_item: AMBIENT vector {
$$ = new Node(); $$ = new Node();
$$->type = COLOR; $$->type = AMBIENT;
$$->the_Vector = $2->the_Vector; $$->the_Color = new Color(* $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);
} }
| REFLECTANCE number { | REFLECTANCE number {
$$ = new Node(); $$ = new Node();

View File

@ -19,6 +19,13 @@ Color::Color(double r, double g, double b)
this->b = b; this->b = b;
} }
Color::Color(const Vector & v)
{
r = v[0];
g = v[1];
b = v[2];
}
Color Color::operator*(const Color & other) const Color Color::operator*(const Color & other) const
{ {
Color result; Color result;

View File

@ -3,6 +3,7 @@
#define COLOR_H COLOR_H #define COLOR_H COLOR_H
#include <iostream> #include <iostream>
#include "util/Vector.h"
class Color class Color
{ {
@ -11,6 +12,7 @@ class Color
Color(); Color();
Color(double r, double g, double b); Color(double r, double g, double b);
Color(const Vector & v);
Color operator*(const Color & other) const; Color operator*(const Color & other) const;
Color operator*(double scale) const; Color operator*(double scale) const;