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 < num_results;
|
||||||
i++)
|
i++)
|
||||||
{
|
{
|
||||||
refptr<Shape> shape = intersections[i].first;
|
refptr<Shape> shape = intersections[i].shape;
|
||||||
const Vector & isect_point = intersections[i].second;
|
const Vector & isect_point = intersections[i].vector;
|
||||||
Vector normal = shape->getNormalAt(isect_point);
|
Vector normal = shape->getNormalAt(isect_point);
|
||||||
double dot = normal % ray.getDirection();
|
double dot = normal % ray.getDirection();
|
||||||
double intersect_dist = (isect_point - ray.getOrigin()).mag();
|
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 res1 = m_shape1->intersect(m_shape1, ray);
|
||||||
IntersectionList res2 = m_shape2->intersect(m_shape2, ray);
|
IntersectionList res2 = m_shape2->intersect(m_shape2, ray);
|
||||||
IntersectionList merged = res1.merge(res2, ray.getOrigin());
|
BoolIntersectionList merged(res1, res2, ray.getOrigin());
|
||||||
|
|
||||||
IntersectionList res;
|
IntersectionList res;
|
||||||
bool in1 = false, in2 = false;
|
bool in1 = false, in2 = false;
|
||||||
|
@ -15,45 +15,44 @@ Shape::~Shape()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class IntersectionComparator : public std::binary_function<Shape::Intersection,
|
class BoolIntersectionComparator
|
||||||
Shape::Intersection,
|
: public std::binary_function<Shape::BoolIntersection,
|
||||||
bool>
|
Shape::BoolIntersection,
|
||||||
|
bool>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IntersectionComparator(const Vector & refPoint)
|
BoolIntersectionComparator(const Vector & refPoint)
|
||||||
{
|
{
|
||||||
m_refPoint = refPoint;
|
m_refPoint = refPoint;
|
||||||
}
|
}
|
||||||
bool operator()(const Shape::Intersection & i1,
|
bool operator()(const Shape::BoolIntersection & i1,
|
||||||
const Shape::Intersection & i2) const
|
const Shape::BoolIntersection & i2) const
|
||||||
{
|
{
|
||||||
return (m_refPoint.dist_to(i1.second)
|
return (m_refPoint.dist_to(i1.intersection.vector)
|
||||||
< m_refPoint.dist_to(i2.second));
|
< m_refPoint.dist_to(i2.intersection.vector));
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
Vector m_refPoint;
|
Vector m_refPoint;
|
||||||
};
|
};
|
||||||
|
|
||||||
Shape::IntersectionList
|
Shape::BoolIntersectionList::BoolIntersectionList(const IntersectionList & l1,
|
||||||
Shape::IntersectionList::merge(const IntersectionList & other,
|
const IntersectionList & l2,
|
||||||
const Vector & startPoint)
|
const Vector & startPoint)
|
||||||
{
|
{
|
||||||
Shape::IntersectionList result;
|
for (size_t i = 0, sz = l1.size();
|
||||||
|
|
||||||
for (size_t i = 0, sz = m_intersections.size();
|
|
||||||
i < sz;
|
i < sz;
|
||||||
i++)
|
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 < sz;
|
||||||
i++)
|
i++)
|
||||||
{
|
{
|
||||||
result.add(other.m_intersections[i]);
|
m_intersections.push_back( BoolIntersection(l2[i], false) );
|
||||||
}
|
}
|
||||||
|
|
||||||
sort(result.begin(), result.end(), IntersectionComparator(startPoint));
|
sort(m_intersections.begin(),
|
||||||
|
m_intersections.end(),
|
||||||
return result;
|
BoolIntersectionComparator(startPoint));
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,30 @@
|
|||||||
class Shape
|
class Shape
|
||||||
{
|
{
|
||||||
public:
|
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
|
class IntersectionList
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -26,7 +49,11 @@ class Shape
|
|||||||
{
|
{
|
||||||
return m_intersections[i];
|
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()
|
std::vector<Intersection>::iterator begin()
|
||||||
{
|
{
|
||||||
return m_intersections.begin();
|
return m_intersections.begin();
|
||||||
@ -35,11 +62,36 @@ class Shape
|
|||||||
{
|
{
|
||||||
return m_intersections.end();
|
return m_intersections.end();
|
||||||
}
|
}
|
||||||
IntersectionList merge(const IntersectionList & other,
|
|
||||||
const Vector & startPoint);
|
|
||||||
protected:
|
protected:
|
||||||
std::vector< Intersection > m_intersections;
|
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();
|
Shape();
|
||||||
virtual ~Shape();
|
virtual ~Shape();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user