converted shapes/Intersect::intersect() to using BoolIntersectionList
git-svn-id: svn://anubis/fart/trunk@152 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
2e6c62a032
commit
bcbec65a8f
@ -177,8 +177,8 @@ vector<Scene::ShapeDistance> Scene::getRayHits(const Ray & ray)
|
||||
i < num_results;
|
||||
i++)
|
||||
{
|
||||
refptr<Shape> shape = intersections[i].first;
|
||||
const Vector & isect_point = intersections[i].second;
|
||||
refptr<Shape> shape = intersections[i].shape;
|
||||
const Vector & isect_point = intersections[i].vector;
|
||||
Vector normal = shape->getNormalAt(isect_point);
|
||||
double dot = normal % ray.getDirection();
|
||||
double intersect_dist = (isect_point - ray.getOrigin()).mag();
|
||||
|
@ -11,7 +11,7 @@ Shape::IntersectionList Intersect::intersect(refptr<Shape> _this, const Ray & ra
|
||||
{
|
||||
IntersectionList res1 = m_shape1->intersect(m_shape1, ray);
|
||||
IntersectionList res2 = m_shape2->intersect(m_shape2, ray);
|
||||
IntersectionList merged = res1.merge(res2, ray.getOrigin());
|
||||
BoolIntersectionList merged(res1, res2, ray.getOrigin());
|
||||
|
||||
IntersectionList res;
|
||||
bool in1 = false, in2 = false;
|
||||
|
@ -15,45 +15,44 @@ Shape::~Shape()
|
||||
{
|
||||
}
|
||||
|
||||
class IntersectionComparator : public std::binary_function<Shape::Intersection,
|
||||
Shape::Intersection,
|
||||
class BoolIntersectionComparator
|
||||
: public std::binary_function<Shape::BoolIntersection,
|
||||
Shape::BoolIntersection,
|
||||
bool>
|
||||
{
|
||||
public:
|
||||
IntersectionComparator(const Vector & refPoint)
|
||||
BoolIntersectionComparator(const Vector & refPoint)
|
||||
{
|
||||
m_refPoint = refPoint;
|
||||
}
|
||||
bool operator()(const Shape::Intersection & i1,
|
||||
const Shape::Intersection & i2) const
|
||||
bool operator()(const Shape::BoolIntersection & i1,
|
||||
const Shape::BoolIntersection & i2) const
|
||||
{
|
||||
return (m_refPoint.dist_to(i1.second)
|
||||
< m_refPoint.dist_to(i2.second));
|
||||
return (m_refPoint.dist_to(i1.intersection.vector)
|
||||
< m_refPoint.dist_to(i2.intersection.vector));
|
||||
}
|
||||
protected:
|
||||
Vector m_refPoint;
|
||||
};
|
||||
|
||||
Shape::IntersectionList
|
||||
Shape::IntersectionList::merge(const IntersectionList & other,
|
||||
Shape::BoolIntersectionList::BoolIntersectionList(const IntersectionList & l1,
|
||||
const IntersectionList & l2,
|
||||
const Vector & startPoint)
|
||||
{
|
||||
Shape::IntersectionList result;
|
||||
|
||||
for (size_t i = 0, sz = m_intersections.size();
|
||||
for (size_t i = 0, sz = l1.size();
|
||||
i < sz;
|
||||
i++)
|
||||
{
|
||||
result.add(m_intersections[i]);
|
||||
m_intersections.push_back( BoolIntersection(l1[i], true) );
|
||||
}
|
||||
for (size_t i = 0, sz = other.m_intersections.size();
|
||||
for (size_t i = 0, sz = l2.size();
|
||||
i < sz;
|
||||
i++)
|
||||
{
|
||||
result.add(other.m_intersections[i]);
|
||||
m_intersections.push_back( BoolIntersection(l2[i], false) );
|
||||
}
|
||||
|
||||
sort(result.begin(), result.end(), IntersectionComparator(startPoint));
|
||||
|
||||
return result;
|
||||
sort(m_intersections.begin(),
|
||||
m_intersections.end(),
|
||||
BoolIntersectionComparator(startPoint));
|
||||
}
|
||||
|
@ -14,7 +14,30 @@
|
||||
class Shape
|
||||
{
|
||||
public:
|
||||
typedef std::pair< refptr<Shape> , Vector > Intersection;
|
||||
class Intersection
|
||||
{
|
||||
public:
|
||||
Intersection() {};
|
||||
Intersection(refptr<Shape> shape, const Vector & vector)
|
||||
{
|
||||
this->shape = shape;
|
||||
this->vector = vector;
|
||||
}
|
||||
refptr<Shape> shape;
|
||||
Vector vector;
|
||||
};
|
||||
class BoolIntersection
|
||||
{
|
||||
public:
|
||||
BoolIntersection() {};
|
||||
BoolIntersection(const Intersection & intersection, bool left)
|
||||
{
|
||||
this->intersection = intersection;
|
||||
this->left = left;
|
||||
}
|
||||
Intersection intersection;
|
||||
bool left;
|
||||
};
|
||||
class IntersectionList
|
||||
{
|
||||
public:
|
||||
@ -26,7 +49,11 @@ class Shape
|
||||
{
|
||||
return m_intersections[i];
|
||||
}
|
||||
size_t size() { return m_intersections.size(); }
|
||||
const Intersection & operator[](int i) const
|
||||
{
|
||||
return m_intersections[i];
|
||||
}
|
||||
size_t size() const { return m_intersections.size(); }
|
||||
std::vector<Intersection>::iterator begin()
|
||||
{
|
||||
return m_intersections.begin();
|
||||
@ -35,11 +62,36 @@ class Shape
|
||||
{
|
||||
return m_intersections.end();
|
||||
}
|
||||
IntersectionList merge(const IntersectionList & other,
|
||||
const Vector & startPoint);
|
||||
protected:
|
||||
std::vector< Intersection > m_intersections;
|
||||
};
|
||||
class BoolIntersectionList
|
||||
{
|
||||
public:
|
||||
BoolIntersectionList(const IntersectionList & l1,
|
||||
const IntersectionList & l2,
|
||||
const Vector & startPoint);
|
||||
BoolIntersection & operator[](int i)
|
||||
{
|
||||
return m_intersections[i];
|
||||
}
|
||||
const BoolIntersection & operator[](int i) const
|
||||
{
|
||||
return m_intersections[i];
|
||||
}
|
||||
size_t size() const { return m_intersections.size(); }
|
||||
std::vector<BoolIntersection>::iterator begin()
|
||||
{
|
||||
return m_intersections.begin();
|
||||
}
|
||||
std::vector<BoolIntersection>::iterator end()
|
||||
{
|
||||
return m_intersections.end();
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector< BoolIntersection > m_intersections;
|
||||
};
|
||||
|
||||
Shape();
|
||||
virtual ~Shape();
|
||||
|
Loading…
x
Reference in New Issue
Block a user