From 91e490b65a1d48b147a581629668d59256c24874 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 12 Mar 2009 02:59:35 +0000 Subject: [PATCH] added shapes/shapes.h, shapes/BoolShape, made Intersect, Union, and Subtract derive from BoolShape, made BoolShape::setMaterial() call setMaterial() on sub-shapes so that materials applied to boolean objects will be applied to all sub-objects git-svn-id: svn://anubis/fart/trunk@212 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- .todo | 1 - main/Scene.h | 2 +- shapes/BoolShape.cc | 19 +++++++++++++++++++ shapes/BoolShape.h | 20 ++++++++++++++++++++ shapes/Intersect.cc | 3 +-- shapes/Intersect.h | 8 ++------ shapes/Shape.cc | 5 +++++ shapes/Shape.h | 9 +-------- shapes/Subtract.cc | 3 +-- shapes/Subtract.h | 8 ++------ shapes/Union.cc | 3 +-- shapes/Union.h | 8 ++------ shapes/shapes.h | 9 +++++++++ 13 files changed, 64 insertions(+), 34 deletions(-) create mode 100644 shapes/BoolShape.cc create mode 100644 shapes/BoolShape.h create mode 100644 shapes/shapes.h diff --git a/.todo b/.todo index bddca63..dd7ca1d 100644 --- a/.todo +++ b/.todo @@ -10,7 +10,6 @@ FART To-Do List - Scene file pre-parser to allow includes, macros, and comments - Vim syntax file - Add jitter parameter to lights to effect soft shadow edges - - Do something with materials applied to boolean objects Low Priority: - Refraction diff --git a/main/Scene.h b/main/Scene.h index 9eeeb06..c14dccf 100644 --- a/main/Scene.h +++ b/main/Scene.h @@ -11,7 +11,7 @@ #include "util/Ray.h" #include "util/Color.h" #include "util/Material.h" -#include "shapes/Shape.h" +#include "shapes/shapes.h" #include "Light.h" #include "parser/parser.h" diff --git a/shapes/BoolShape.cc b/shapes/BoolShape.cc new file mode 100644 index 0000000..bf3a3f4 --- /dev/null +++ b/shapes/BoolShape.cc @@ -0,0 +1,19 @@ + +#include "BoolShape.h" + +BoolShape::BoolShape(refptr shape1, refptr shape2) +{ + m_shape1 = shape1; + m_shape2 = shape2; +} + +BoolShape::~BoolShape() +{ +} + +void BoolShape::setMaterial(refptr material) +{ + m_material = material; + m_shape1->setMaterial(material); + m_shape2->setMaterial(material); +} diff --git a/shapes/BoolShape.h b/shapes/BoolShape.h new file mode 100644 index 0000000..dd2f909 --- /dev/null +++ b/shapes/BoolShape.h @@ -0,0 +1,20 @@ + +#ifndef BOOLSHAPE_H +#define BOOLSHAPE_H BOOLSHAPE_H + +#include "Shape.h" + +class BoolShape : public Shape +{ + public: + BoolShape(refptr shape1, refptr shape2); + ~BoolShape(); + virtual IntersectionList intersect(refptr _this, const Ray & ray) = 0; + virtual void setMaterial(refptr material); + + protected: + refptr m_shape1; + refptr m_shape2; +}; + +#endif diff --git a/shapes/Intersect.cc b/shapes/Intersect.cc index c94a749..666f6aa 100644 --- a/shapes/Intersect.cc +++ b/shapes/Intersect.cc @@ -4,9 +4,8 @@ using namespace std; Intersect::Intersect(refptr shape1, refptr shape2) + : BoolShape(shape1, shape2) { - m_shape1 = shape1; - m_shape2 = shape2; } Shape::IntersectionList Intersect::intersect(refptr _this, const Ray & ray) diff --git a/shapes/Intersect.h b/shapes/Intersect.h index 35a9f1c..751333b 100644 --- a/shapes/Intersect.h +++ b/shapes/Intersect.h @@ -2,17 +2,13 @@ #ifndef INTERSECT_H #define INTERSECT_H INTERSECT_H -#include "Shape.h" +#include "BoolShape.h" -class Intersect : public Shape +class Intersect : public BoolShape { public: Intersect(refptr shape1, refptr shape2); IntersectionList intersect(refptr _this, const Ray & ray); - - protected: - refptr m_shape1; - refptr m_shape2; }; #endif diff --git a/shapes/Shape.cc b/shapes/Shape.cc index 6da0670..e9bdf7e 100755 --- a/shapes/Shape.cc +++ b/shapes/Shape.cc @@ -22,6 +22,11 @@ Shape::~Shape() { } +void Shape::setMaterial(refptr material) +{ + m_material = material; +} + class BoolIntersectionComparator : public std::binary_function material) { m_material = material; } + virtual void setMaterial(refptr material); refptr getMaterial() const { return m_material; } protected: @@ -118,13 +118,6 @@ class Shape refptr m_material; }; -#include "Box.h" -#include "Cyl.h" -#include "Intersect.h" -#include "Plane.h" -#include "Sphere.h" -#include "Subtract.h" -#include "Union.h" #endif diff --git a/shapes/Subtract.cc b/shapes/Subtract.cc index 2115f96..c847cba 100644 --- a/shapes/Subtract.cc +++ b/shapes/Subtract.cc @@ -4,9 +4,8 @@ using namespace std; Subtract::Subtract(refptr shape1, refptr shape2) + : BoolShape(shape1, shape2) { - m_shape1 = shape1; - m_shape2 = shape2; } Shape::IntersectionList Subtract::intersect(refptr _this, const Ray & ray) diff --git a/shapes/Subtract.h b/shapes/Subtract.h index 5d27b49..4a6f3a5 100644 --- a/shapes/Subtract.h +++ b/shapes/Subtract.h @@ -2,17 +2,13 @@ #ifndef SUBTRACT_H #define SUBTRACT_H SUBTRACT_H -#include "Shape.h" +#include "BoolShape.h" -class Subtract : public Shape +class Subtract : public BoolShape { public: Subtract(refptr shape1, refptr shape2); IntersectionList intersect(refptr _this, const Ray & ray); - - protected: - refptr m_shape1; - refptr m_shape2; }; #endif diff --git a/shapes/Union.cc b/shapes/Union.cc index 30dea21..e22f4d8 100644 --- a/shapes/Union.cc +++ b/shapes/Union.cc @@ -4,9 +4,8 @@ using namespace std; Union::Union(refptr shape1, refptr shape2) + : BoolShape(shape1, shape2) { - m_shape1 = shape1; - m_shape2 = shape2; } Shape::IntersectionList Union::intersect(refptr _this, const Ray & ray) diff --git a/shapes/Union.h b/shapes/Union.h index 1bd6130..ddd3306 100644 --- a/shapes/Union.h +++ b/shapes/Union.h @@ -2,17 +2,13 @@ #ifndef UNION_H #define UNION_H UNION_H -#include "Shape.h" +#include "BoolShape.h" -class Union : public Shape +class Union : public BoolShape { public: Union(refptr shape1, refptr shape2); IntersectionList intersect(refptr _this, const Ray & ray); - - protected: - refptr m_shape1; - refptr m_shape2; }; #endif diff --git a/shapes/shapes.h b/shapes/shapes.h new file mode 100644 index 0000000..7cbcb5c --- /dev/null +++ b/shapes/shapes.h @@ -0,0 +1,9 @@ + +#include "BoolShape.h" +#include "Box.h" +#include "Cyl.h" +#include "Intersect.h" +#include "Plane.h" +#include "Sphere.h" +#include "Subtract.h" +#include "Union.h"