changed IntersectionList into a class so i could add merge()

git-svn-id: svn://anubis/fart/trunk@148 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-02-23 21:39:56 +00:00
parent 5f18370846
commit 56278a8337
6 changed files with 41 additions and 21 deletions

View File

@ -45,10 +45,8 @@ Shape::IntersectionList Box::intersect(refptr<Shape> _this, const Ray & ray)
&& (dim == 1 || fabs(isect_point[1]) <= m_size[1]) && (dim == 1 || fabs(isect_point[1]) <= m_size[1])
&& (dim == 2 || fabs(isect_point[2]) <= m_size[2]) ) && (dim == 2 || fabs(isect_point[2]) <= m_size[2]) )
{ {
res.push_back( res.add(Intersection(_this,
Intersection(_this, m_transform.transform_point(isect_point))
m_transform.transform_point(
isect_point))
); );
} }
} }

View File

@ -36,10 +36,8 @@ Shape::IntersectionList Cyl::intersect(refptr<Shape> _this, const Ray & ray)
if (isect_point[0]*isect_point[0] + isect_point[1]*isect_point[1] if (isect_point[0]*isect_point[0] + isect_point[1]*isect_point[1]
< m_bottom_radius_2) < m_bottom_radius_2)
{ {
res.push_back( res.add(Intersection(_this,
Intersection(_this, m_transform.transform_point(isect_point)));
m_transform.transform_point(isect_point))
);
} }
} }
} }
@ -56,10 +54,8 @@ Shape::IntersectionList Cyl::intersect(refptr<Shape> _this, const Ray & ray)
if (isect_point[0]*isect_point[0] + isect_point[1]*isect_point[1] if (isect_point[0]*isect_point[0] + isect_point[1]*isect_point[1]
< m_top_radius_2) < m_top_radius_2)
{ {
res.push_back( res.add(Intersection(_this,
Intersection(_this, m_transform.transform_point(isect_point)));
m_transform.transform_point(isect_point))
);
} }
} }
} }
@ -103,10 +99,8 @@ Shape::IntersectionList Cyl::intersect(refptr<Shape> _this, const Ray & ray)
Vector isect_point = ray_inv[solutions.results[i]]; Vector isect_point = ray_inv[solutions.results[i]];
if (isect_point[2] >= 0.0 && isect_point[2] <= m_height) if (isect_point[2] >= 0.0 && isect_point[2] <= m_height)
{ {
res.push_back( res.add(Intersection(_this,
Intersection(_this, m_transform.transform_point(isect_point)));
m_transform.transform_point(isect_point))
);
} }
} }
} }

View File

@ -39,9 +39,7 @@ Shape::IntersectionList Plane::intersect(refptr<Shape> _this, const Ray & ray)
if (solutions.numResults > 0) if (solutions.numResults > 0)
{ {
Vector isect_point = ray_inv[solutions.results[0]]; Vector isect_point = ray_inv[solutions.results[0]];
res.push_back( res.add(Intersection(_this, m_transform.transform_point(isect_point)));
Intersection(_this, m_transform.transform_point(isect_point))
);
} }
return res; return res;
} }

View File

@ -10,3 +10,9 @@ Shape::Shape()
Shape::~Shape() Shape::~Shape()
{ {
} }
Shape::IntersectionList
Shape::IntersectionList::merge(const IntersectionList & other,
const Vector & startPoint)
{
}

View File

@ -15,7 +15,31 @@ class Shape
{ {
public: public:
typedef std::pair< refptr<Shape> , Vector > Intersection; typedef std::pair< refptr<Shape> , Vector > Intersection;
typedef std::vector< Intersection > IntersectionList; class IntersectionList
{
public:
void add(const Intersection & i)
{
m_intersections.push_back(i);
}
Intersection & operator[](int i)
{
return m_intersections[i];
}
size_t size() { return m_intersections.size(); }
std::vector<Intersection>::const_iterator begin()
{
return m_intersections.begin();
}
std::vector<Intersection>::const_iterator end()
{
return m_intersections.end();
}
IntersectionList merge(const IntersectionList & other,
const Vector & startPoint);
protected:
std::vector< Intersection > m_intersections;
};
Shape(); Shape();
virtual ~Shape(); virtual ~Shape();

View File

@ -30,7 +30,7 @@ Shape::IntersectionList Sphere::intersect(refptr<Shape> _this, const Ray & ray)
if (quadSolutions.results[i] >= 0.0) if (quadSolutions.results[i] >= 0.0)
{ {
Vector isect_point = ray_inv[quadSolutions.results[i]]; Vector isect_point = ray_inv[quadSolutions.results[i]];
res.push_back( res.add(
Intersection(_this, m_transform.transform_point(isect_point)) Intersection(_this, m_transform.transform_point(isect_point))
); );
} }