From 84f6b04cd736c72b84346b3148f46c4d9f18679a Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 2 Mar 2009 00:17:56 +0000 Subject: [PATCH] removed static const Material::white (had a problem with C++ since the order that the static const constructors were being called in was not correct according to the order that the code depended on them), made Shape constructor use a common default material instead of recreating one every time git-svn-id: svn://anubis/fart/trunk@174 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- main/Scene-load.cc | 7 +++---- shapes/Shape.cc | 10 +++++++++- util/Material.cc | 2 -- util/Material.h | 3 --- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/main/Scene-load.cc b/main/Scene-load.cc index 6b18a9d..5a70bc6 100644 --- a/main/Scene-load.cc +++ b/main/Scene-load.cc @@ -15,18 +15,17 @@ void Scene::load(const char * filename) refptr node = parse(filename); processNode(node); - Transform transform; - transform.translate(0, 2, 0); - +#if 0 refptr m = new Material(); refptr shape = new Sphere(0.5); - shape->setTransform(transform); + shape->setTransform(m_transforms.top()); shape->setMaterial(m); m_shapes.push_back(shape); refptr light = new PointLight(); light->setPosition(Vector(2, -1, 2)); m_lights.push_back(light); +#endif #if 0 Transform transform; diff --git a/shapes/Shape.cc b/shapes/Shape.cc index 5211c00..7f496de 100755 --- a/shapes/Shape.cc +++ b/shapes/Shape.cc @@ -5,10 +5,18 @@ #include using namespace std; +static refptr default_material; +static bool default_material_initialized = false; + Shape::Shape() { m_transparency = 0.0; - m_material = new Material(Material::white); + if (default_material_initialized == false) + { + default_material = new Material(); + default_material_initialized = true; + } + m_material = default_material; } Shape::~Shape() diff --git a/util/Material.cc b/util/Material.cc index c70d95c..f541fbe 100644 --- a/util/Material.cc +++ b/util/Material.cc @@ -1,8 +1,6 @@ #include "Material.h" -const Material Material::white = Material(); - Material::Material() { m_ambient_color = Color::white; diff --git a/util/Material.h b/util/Material.h index a5af021..63f2d73 100644 --- a/util/Material.h +++ b/util/Material.h @@ -7,9 +7,6 @@ class Material { public: - /* static members */ - static const Material white; - Material(); void setAmbientColor(const Color & ambient)