From f7eb4cd4b92e54923bed8d79b419f8461274447e Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 24 Feb 2009 03:22:15 +0000 Subject: [PATCH] finished implementing shapes/Intersect::intersect() git-svn-id: svn://anubis/fart/trunk@154 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- shapes/Intersect.cc | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/shapes/Intersect.cc b/shapes/Intersect.cc index 3d58ba7..9ad50c8 100644 --- a/shapes/Intersect.cc +++ b/shapes/Intersect.cc @@ -1,5 +1,7 @@ #include "Intersect.h" +#include +using namespace std; Intersect::Intersect(refptr shape1, refptr shape2) { @@ -15,14 +17,51 @@ Shape::IntersectionList Intersect::intersect(refptr _this, const Ray & ra IntersectionList res; bool in1 = false, in2 = false; + bool in_bool = false; /* TODO: finish */ + for (int i = 0, sz = merged.size(); i < sz; i++) + { + Vector normal = merged[i].intersection.shape->getNormalAt( + merged[i].intersection.vector); + double dot = - (ray.getDirection() % normal); + bool front = dot > 0.0; + bool left = merged[i].left; + if (front) + { + if (left) + in1 = true; + else + in2 = true; + if (!in_bool && in1 && in2) + { + /* we found an intersection point with the boolean object */ + in_bool = true; + res.add( merged[i].intersection ); + } + } + else + { + if (in_bool && in1 && in2) + { + /* we found an intersection point with the boolean object */ + res.add( merged[i].intersection ); + } + if (left) + in1 = false; + else + in2 = false; + in_bool = false; + } + } return res; } Vector Intersect::getNormalAt(const Vector & pt) { - /* TODO: finish */ + /* this should not be called */ + cerr << __FILE__ << ": " << __LINE__ << + ": error: Intersect::getNormalAt() was called!" << endl; return Vector(0, 0, 0); }