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:
parent
8a112009a6
commit
c136bda827
@ -7,5 +7,6 @@ Material::Material()
|
||||
{
|
||||
m_diffuse_color = Color::white;
|
||||
m_specular_color = Color::white;
|
||||
m_shininess = 50;
|
||||
m_shininess = 50.0;
|
||||
m_reflectance = 0.0;
|
||||
}
|
||||
|
@ -33,11 +33,15 @@ class Material
|
||||
void setShininess(double shininess) { m_shininess = shininess; }
|
||||
double getShininess() const { return m_shininess; }
|
||||
|
||||
void setReflectance(double reflectance) { m_reflectance = reflectance; }
|
||||
double getReflectance() const { return m_reflectance; }
|
||||
|
||||
protected:
|
||||
Color m_ambient_color;
|
||||
Color m_diffuse_color;
|
||||
Color m_specular_color;
|
||||
double m_shininess;
|
||||
double m_reflectance;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -32,9 +32,10 @@
|
||||
-?[0-9]+ return DEC_NUMBER;
|
||||
-?[0-9]*\.[0-9]+ return REAL_NUMBER;
|
||||
|
||||
ambient return AMBIENT;
|
||||
box return BOX;
|
||||
camera return CAMERA;
|
||||
color return COLOR;
|
||||
diffuse return DIFFUSE;
|
||||
height return HEIGHT;
|
||||
intersect return INTERSECT;
|
||||
look_at return LOOKAT;
|
||||
@ -47,6 +48,7 @@ reflectance return REFLECTANCE;
|
||||
scene return SCENE;
|
||||
shininess return SHININESS;
|
||||
size return SIZE;
|
||||
specular return SPECULAR;
|
||||
sphere return SPHERE;
|
||||
subtract return SUBTRACT;
|
||||
union return UNION;
|
||||
|
@ -33,11 +33,12 @@ class Node
|
||||
Node();
|
||||
int type;
|
||||
refptr<double> the_double;
|
||||
refptr<Material> the_Material;
|
||||
refptr<Node> the_Node;
|
||||
refptr<Node> the_tail;
|
||||
refptr<Material> the_Material;
|
||||
refptr<Shape> the_Shape;
|
||||
refptr<Vector> the_Vector;
|
||||
refptr<Color> the_Color;
|
||||
};
|
||||
|
||||
enum Node_Type
|
||||
@ -78,9 +79,10 @@ enum Node_Type
|
||||
%token DEC_NUMBER;
|
||||
%token REAL_NUMBER;
|
||||
|
||||
%token AMBIENT;
|
||||
%token BOX;
|
||||
%token CAMERA;
|
||||
%token COLOR;
|
||||
%token DIFFUSE;
|
||||
%token HEIGHT;
|
||||
%token INTERSECT;
|
||||
%token LOOKAT;
|
||||
@ -93,6 +95,7 @@ enum Node_Type
|
||||
%token SCENE;
|
||||
%token SHININESS;
|
||||
%token SIZE;
|
||||
%token SPECULAR;
|
||||
%token SPHERE;
|
||||
%token SUBTRACT;
|
||||
%token UNION;
|
||||
@ -103,10 +106,24 @@ enum Node_Type
|
||||
%%
|
||||
|
||||
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 */
|
||||
@ -155,17 +172,57 @@ camera_item: POSITION vector {
|
||||
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_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();
|
||||
$$->type = COLOR;
|
||||
$$->the_Vector = $2->the_Vector;
|
||||
$$->type = AMBIENT;
|
||||
$$->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 {
|
||||
$$ = new Node();
|
||||
|
@ -19,6 +19,13 @@ Color::Color(double r, double g, double 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 result;
|
||||
|
@ -3,6 +3,7 @@
|
||||
#define COLOR_H COLOR_H
|
||||
|
||||
#include <iostream>
|
||||
#include "util/Vector.h"
|
||||
|
||||
class Color
|
||||
{
|
||||
@ -11,6 +12,7 @@ class Color
|
||||
|
||||
Color();
|
||||
Color(double r, double g, double b);
|
||||
Color(const Vector & v);
|
||||
|
||||
Color operator*(const Color & other) const;
|
||||
Color operator*(double scale) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user