fixed Lighting to ignore dot products less than 0 for diffuse coefficients; this broke shapes/Subtract again. fixed Material::white to be assigned to by Material() as evidently it was not calling the constructor properly otherwise. added initializer in Material::Material() to set ambient color to white. Scene constructing PointLight instead of a raw Light when loading from a file

git-svn-id: svn://anubis/fart/trunk@173 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-03-01 23:50:53 +00:00
parent adf7997417
commit 6a649ecac7
3 changed files with 17 additions and 7 deletions

View File

@ -28,7 +28,7 @@ Color Lighting::computePhong(const refptr<Material> material,
directionToLight.reflect(surfaceNormal); directionToLight.reflect(surfaceNormal);
/* calculate the diffuse term */ /* calculate the diffuse term */
double diffuse_coef = fabs(directionToLight % surfaceNormal); double diffuse_coef = directionToLight % surfaceNormal;
if (diffuse_coef > 0.0) if (diffuse_coef > 0.0)
{ {
result += diffuseColor result += diffuseColor

View File

@ -15,6 +15,19 @@ void Scene::load(const char * filename)
refptr<Node> node = parse(filename); refptr<Node> node = parse(filename);
processNode(node); processNode(node);
Transform transform;
transform.translate(0, 2, 0);
refptr<Material> m = new Material();
refptr<Shape> shape = new Sphere(0.5);
shape->setTransform(transform);
shape->setMaterial(m);
m_shapes.push_back(shape);
refptr<Light> light = new PointLight();
light->setPosition(Vector(2, -1, 2));
m_lights.push_back(light);
#if 0 #if 0
Transform transform; Transform transform;
@ -107,10 +120,6 @@ void Scene::load(const char * filename)
transform.rotate(-45, 1, 0, 0); transform.rotate(-45, 1, 0, 0);
transform.rotate(-45, 0, 0, 1); transform.rotate(-45, 0, 0, 1);
transform.translate(2.0, -5.0, -1.5); transform.translate(2.0, -5.0, -1.5);
refptr<Light> light = new PointLight();
light->setPosition(Vector(2, -1, 2));
m_lights.push_back(light);
#endif #endif
} }
@ -390,7 +399,7 @@ refptr<Shape> Scene::processCyl(refptr<Node> node)
refptr<Light> Scene::processLight(refptr<Node> node) refptr<Light> Scene::processLight(refptr<Node> node)
{ {
refptr<Light> light = new Light(); refptr<Light> light = new PointLight();
for (Node_Iterator it = node->getChildren().begin(); for (Node_Iterator it = node->getChildren().begin();
it != node->getChildren().end(); it != node->getChildren().end();

View File

@ -1,10 +1,11 @@
#include "Material.h" #include "Material.h"
const Material Material::white; const Material Material::white = Material();
Material::Material() Material::Material()
{ {
m_ambient_color = Color::white;
m_diffuse_color = Color::white; m_diffuse_color = Color::white;
m_specular_color = Color::white; m_specular_color = Color::white;
m_shininess = 50.0; m_shininess = 50.0;