fart/shapes/Shape.cc
Josh Holtrop bcbec65a8f converted shapes/Intersect::intersect() to using BoolIntersectionList
git-svn-id: svn://anubis/fart/trunk@152 7f9b0f55-74a9-4bce-be96-3c2cd072584d
2009-02-24 03:04:26 +00:00

59 lines
1.5 KiB
C++
Executable File

#include "Shape.h"
#include <algorithm> /* sort() */
#include <functional> /* binary_function */
#include <utility>
using namespace std;
Shape::Shape()
{
m_transparency = 0.0;
m_material = new Material(Material::white);
}
Shape::~Shape()
{
}
class BoolIntersectionComparator
: public std::binary_function<Shape::BoolIntersection,
Shape::BoolIntersection,
bool>
{
public:
BoolIntersectionComparator(const Vector & refPoint)
{
m_refPoint = refPoint;
}
bool operator()(const Shape::BoolIntersection & i1,
const Shape::BoolIntersection & i2) const
{
return (m_refPoint.dist_to(i1.intersection.vector)
< m_refPoint.dist_to(i2.intersection.vector));
}
protected:
Vector m_refPoint;
};
Shape::BoolIntersectionList::BoolIntersectionList(const IntersectionList & l1,
const IntersectionList & l2,
const Vector & startPoint)
{
for (size_t i = 0, sz = l1.size();
i < sz;
i++)
{
m_intersections.push_back( BoolIntersection(l1[i], true) );
}
for (size_t i = 0, sz = l2.size();
i < sz;
i++)
{
m_intersections.push_back( BoolIntersection(l2[i], false) );
}
sort(m_intersections.begin(),
m_intersections.end(),
BoolIntersectionComparator(startPoint));
}