finished implementing shapes/Intersect::intersect()

git-svn-id: svn://anubis/fart/trunk@154 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-02-24 03:22:15 +00:00
parent 527dc6f1dc
commit f7eb4cd4b9

View File

@ -1,5 +1,7 @@
#include "Intersect.h"
#include <iostream>
using namespace std;
Intersect::Intersect(refptr<Shape> shape1, refptr<Shape> shape2)
{
@ -15,14 +17,51 @@ Shape::IntersectionList Intersect::intersect(refptr<Shape> _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);
}