Fixed boolean objects to determine if rays start inside or outside the boolean; changed constructors to accept a list of shapes instead of just two shapes; changed parser to accept any number of top-level shapes inside of a boolean shape block; changed scenes/die.fart to reflect this change (a drastic simplification)

git-svn-id: svn://anubis/fart/trunk@215 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop committed 2009-03-15 19:51:21 +00:00
1 parent f103b71ed6
commit 5590c533ce
12 files changed
+203 -173

No files matched your search

-10
View File
@@ -1,16 +1,6 @@
#include "BoolShape.h"
BoolShape::BoolShape(refptr<Shape> shape1, refptr<Shape> shape2)
{
m_shape1 = shape1;
m_shape2 = shape2;
}
BoolShape::~BoolShape()
{
}
void BoolShape::setMaterial(refptr<Material> material)
{
m_material = material;
-2
View File
@@ -7,8 +7,6 @@
class BoolShape : public Shape
{
public:
BoolShape(refptr<Shape> shape1, refptr<Shape> shape2);
~BoolShape();
virtual IntersectionList intersect(refptr<Shape> _this, const Ray & ray) = 0;
virtual void setMaterial(refptr<Material> material);
+47 -3
View File
@@ -3,9 +3,30 @@
#include <iostream>
using namespace std;
Intersect::Intersect(refptr<Shape> shape1, refptr<Shape> shape2)
: BoolShape(shape1, shape2)
Intersect::Intersect(const vector< refptr<Shape> > & shapes)
{
int num_shapes = shapes.size();
if (num_shapes > 2)
{
m_shape2 = shapes[num_shapes - 1];
vector< refptr<Shape> > rest = shapes;
rest.pop_back();
m_shape1 = new Intersect(rest);
}
else if (num_shapes == 2)
{
m_shape1 = shapes[0];
m_shape2 = shapes[1];
}
else
{
cerr << __FILE__ << ": " << __LINE__
<< ": error: Intersect::Intersect() called with only "
<< num_shapes
<< " sub-shapes!"
<< endl;
exit(4);
}
}
Shape::IntersectionList Intersect::intersect(refptr<Shape> _this, const Ray & ray)
@@ -16,8 +37,31 @@ Shape::IntersectionList Intersect::intersect(refptr<Shape> _this, const Ray & ra
IntersectionList res;
bool in1 = false, in2 = false;
bool in_bool = false;
/* initially go through the merged intersections to see whether
* the ray started inside one of the sub-objects */
for (int i = 0, sz = merged.size(), saw1 = 0, saw2 = 0;
i < sz && (!saw1 || !saw2);
i++)
{
Vector normal = merged[i].intersection.normal;
double dot = - (ray.getDirection() % normal);
bool back = dot < 0.0;
bool left = merged[i].left;
if (back)
{
if (left && !saw1)
in1 = true;
else if (!left && !saw2)
in2 = true;
}
if (left)
saw1 = 1;
else
saw2 = 1;
}
bool in_bool = in1 && in2;
for (int i = 0, sz = merged.size(); i < sz; i++)
{
Vector normal = merged[i].intersection.normal;
+2 -1
View File
@@ -3,11 +3,12 @@
#define INTERSECT_H INTERSECT_H
#include "BoolShape.h"
#include <vector>
class Intersect : public BoolShape
{
public:
Intersect(refptr<Shape> shape1, refptr<Shape> shape2);
Intersect(const std::vector< refptr<Shape> > & shapes);
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
};
+47 -3
View File
@@ -3,9 +3,30 @@
#include <iostream>
using namespace std;
Subtract::Subtract(refptr<Shape> shape1, refptr<Shape> shape2)
: BoolShape(shape1, shape2)
Subtract::Subtract(const vector< refptr<Shape> > & shapes)
{
int num_shapes = shapes.size();
if (num_shapes > 2)
{
m_shape2 = shapes[num_shapes - 1];
vector< refptr<Shape> > rest = shapes;
rest.pop_back();
m_shape1 = new Subtract(rest);
}
else if (num_shapes == 2)
{
m_shape1 = shapes[0];
m_shape2 = shapes[1];
}
else
{
cerr << __FILE__ << ": " << __LINE__
<< ": error: Subtract::Subtract() called with only "
<< num_shapes
<< " sub-shapes!"
<< endl;
exit(4);
}
}
Shape::IntersectionList Subtract::intersect(refptr<Shape> _this, const Ray & ray)
@@ -16,8 +37,31 @@ Shape::IntersectionList Subtract::intersect(refptr<Shape> _this, const Ray & ray
IntersectionList res;
bool in1 = false, in2 = false;
bool in_bool = false;
/* initially go through the merged intersections to see whether
* the ray started inside one of the sub-objects */
for (int i = 0, sz = merged.size(), saw1 = 0, saw2 = 0;
i < sz && (!saw1 || !saw2);
i++)
{
Vector normal = merged[i].intersection.normal;
double dot = - (ray.getDirection() % normal);
bool back = dot < 0.0;
bool left = merged[i].left;
if (back)
{
if (left && !saw1)
in1 = true;
else if (!left && !saw2)
in2 = true;
}
if (left)
saw1 = 1;
else
saw2 = 1;
}
bool in_bool = in1 && !in2;
for (int i = 0, sz = merged.size(); i < sz; i++)
{
Vector normal = merged[i].intersection.normal;
+2 -1
View File
@@ -3,11 +3,12 @@
#define SUBTRACT_H SUBTRACT_H
#include "BoolShape.h"
#include <vector>
class Subtract : public BoolShape
{
public:
Subtract(refptr<Shape> shape1, refptr<Shape> shape2);
Subtract(const std::vector< refptr<Shape> > & shapes);
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
};
+48 -3
View File
@@ -1,11 +1,33 @@
#include "Union.h"
#include <iostream>
#include <vector>
using namespace std;
Union::Union(refptr<Shape> shape1, refptr<Shape> shape2)
: BoolShape(shape1, shape2)
Union::Union(const vector< refptr<Shape> > & shapes)
{
int num_shapes = shapes.size();
if (num_shapes > 2)
{
m_shape2 = shapes[num_shapes - 1];
vector< refptr<Shape> > rest = shapes;
rest.pop_back();
m_shape1 = new Union(rest);
}
else if (num_shapes == 2)
{
m_shape1 = shapes[0];
m_shape2 = shapes[1];
}
else
{
cerr << __FILE__ << ": " << __LINE__
<< ": error: Union::Union() called with only "
<< num_shapes
<< " sub-shapes!"
<< endl;
exit(4);
}
}
Shape::IntersectionList Union::intersect(refptr<Shape> _this, const Ray & ray)
@@ -16,8 +38,31 @@ Shape::IntersectionList Union::intersect(refptr<Shape> _this, const Ray & ray)
IntersectionList res;
bool in1 = false, in2 = false;
bool in_bool = false;
/* initially go through the merged intersections to see whether
* the ray started inside one of the sub-objects */
for (int i = 0, sz = merged.size(), saw1 = 0, saw2 = 0;
i < sz && (!saw1 || !saw2);
i++)
{
Vector normal = merged[i].intersection.normal;
double dot = - (ray.getDirection() % normal);
bool back = dot < 0.0;
bool left = merged[i].left;
if (back)
{
if (left && !saw1)
in1 = true;
else if (!left && !saw2)
in2 = true;
}
if (left)
saw1 = 1;
else
saw2 = 1;
}
bool in_bool = in1 || in2;
for (int i = 0, sz = merged.size(); i < sz; i++)
{
Vector normal = merged[i].intersection.normal;
+2 -1
View File
@@ -3,11 +3,12 @@
#define UNION_H UNION_H
#include "BoolShape.h"
#include <vector>
class Union : public BoolShape
{
public:
Union(refptr<Shape> shape1, refptr<Shape> shape2);
Union(const std::vector< refptr<Shape> > & shapes);
IntersectionList intersect(refptr<Shape> _this, const Ray & ray);
};