From 6a649ecac753b3cc4fa7fd701dc8d17e724824cf Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 1 Mar 2009 23:50:53 +0000 Subject: [PATCH] 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 --- main/Lighting.cc | 2 +- main/Scene-load.cc | 19 ++++++++++++++----- util/Material.cc | 3 ++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/main/Lighting.cc b/main/Lighting.cc index 280b540..73cee51 100644 --- a/main/Lighting.cc +++ b/main/Lighting.cc @@ -28,7 +28,7 @@ Color Lighting::computePhong(const refptr material, directionToLight.reflect(surfaceNormal); /* calculate the diffuse term */ - double diffuse_coef = fabs(directionToLight % surfaceNormal); + double diffuse_coef = directionToLight % surfaceNormal; if (diffuse_coef > 0.0) { result += diffuseColor diff --git a/main/Scene-load.cc b/main/Scene-load.cc index 114f475..6b18a9d 100644 --- a/main/Scene-load.cc +++ b/main/Scene-load.cc @@ -15,6 +15,19 @@ void Scene::load(const char * filename) refptr node = parse(filename); processNode(node); + Transform transform; + transform.translate(0, 2, 0); + + refptr m = new Material(); + refptr shape = new Sphere(0.5); + shape->setTransform(transform); + shape->setMaterial(m); + m_shapes.push_back(shape); + + refptr light = new PointLight(); + light->setPosition(Vector(2, -1, 2)); + m_lights.push_back(light); + #if 0 Transform transform; @@ -107,10 +120,6 @@ void Scene::load(const char * filename) transform.rotate(-45, 1, 0, 0); transform.rotate(-45, 0, 0, 1); transform.translate(2.0, -5.0, -1.5); - - refptr light = new PointLight(); - light->setPosition(Vector(2, -1, 2)); - m_lights.push_back(light); #endif } @@ -390,7 +399,7 @@ refptr Scene::processCyl(refptr node) refptr Scene::processLight(refptr node) { - refptr light = new Light(); + refptr light = new PointLight(); for (Node_Iterator it = node->getChildren().begin(); it != node->getChildren().end(); diff --git a/util/Material.cc b/util/Material.cc index f280558..c70d95c 100644 --- a/util/Material.cc +++ b/util/Material.cc @@ -1,10 +1,11 @@ #include "Material.h" -const Material Material::white; +const Material Material::white = Material(); Material::Material() { + m_ambient_color = Color::white; m_diffuse_color = Color::white; m_specular_color = Color::white; m_shininess = 50.0;