From 4b0f5065225060f597aa3795e88e6515f247bc10 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 17 Feb 2009 05:36:48 +0000 Subject: [PATCH] added Color::yellow, finished shapes/Box, added a couple boxes to sample scene git-svn-id: svn://anubis/fart/trunk@121 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- main/Scene.cc | 24 +++++++++++++++++++++++- shapes/Box.cc | 6 +++--- shapes/Shape.h | 1 + util/Color.cc | 1 + util/Color.h | 1 + 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/main/Scene.cc b/main/Scene.cc index a6350c1..6e3c9d7 100644 --- a/main/Scene.cc +++ b/main/Scene.cc @@ -79,7 +79,7 @@ void Scene::load(const char * filename) refptr plane = new Plane(0, 0, 1, -2); m_shapes.push_back(plane); - Material * m = new Material(); + refptr m = new Material(); m->setDiffuseColor(Color::red); m->setAmbientColor(Color::red); @@ -89,6 +89,28 @@ void Scene::load(const char * filename) shape->setMaterial(m); m_shapes.push_back(shape); + m = new Material(); + m->setDiffuseColor(Color::blue); + m->setAmbientColor(Color::blue); + + shape = new Box(new Vector(1.8, 1.8, 0.5)); + m_transform.translate(0, 0, -2.0); + shape->setTransform(m_transform); + shape->setMaterial(m); + m_shapes.push_back(shape); + + m = new Material(); + m->setDiffuseColor(Color::yellow); + m->setAmbientColor(Color::yellow); + + shape = new Box(new Vector(1, 1, 1)); + m_transform.translate(-3, 1, 0.5); + m_transform.rotate(45, 0, 0, 1); + m_transform.rotate(45, 1, 0, 0); + shape->setTransform(m_transform); + shape->setMaterial(m); + m_shapes.push_back(shape); + refptr light = new PointLight(); light->setPosition(Vector(2, -1, 2)); m_lights.push_back(light); diff --git a/shapes/Box.cc b/shapes/Box.cc index cdc7112..9cf2b58 100644 --- a/shapes/Box.cc +++ b/shapes/Box.cc @@ -10,9 +10,9 @@ using namespace std; Box::Box(refptr size) { m_size = *size; - m_size[0] = fabs(m_size[0]); - m_size[1] = fabs(m_size[1]); - m_size[2] = fabs(m_size[2]); + m_size[0] = fabs(m_size[0]) / 2.0; + m_size[1] = fabs(m_size[1]) / 2.0; + m_size[2] = fabs(m_size[2]) / 2.0; } Shape::IntersectList Box::intersect(const Ray & ray) diff --git a/shapes/Shape.h b/shapes/Shape.h index 7d4cf67..19ade8a 100644 --- a/shapes/Shape.h +++ b/shapes/Shape.h @@ -42,6 +42,7 @@ class Shape #include "Sphere.h" #include "Plane.h" +#include "Box.h" #endif diff --git a/util/Color.cc b/util/Color.cc index 8b5d328..22b56da 100644 --- a/util/Color.cc +++ b/util/Color.cc @@ -6,6 +6,7 @@ const Color Color::white = Color(1, 1, 1); const Color Color::red = Color(1, 0, 0); const Color Color::green = Color(0, 1, 0); const Color Color::blue = Color(0, 0, 1); +const Color Color::yellow = Color(1, 1, 0); Color::Color() { diff --git a/util/Color.h b/util/Color.h index aa0c3a6..4aad11b 100644 --- a/util/Color.h +++ b/util/Color.h @@ -25,6 +25,7 @@ class Color static const Color red; static const Color green; static const Color blue; + static const Color yellow; }; Color operator+(const Color & c1, const Color & c2);