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:
parent
5f18370846
commit
56278a8337
@ -45,10 +45,8 @@ Shape::IntersectionList Box::intersect(refptr<Shape> _this, const Ray & ray)
|
||||
&& (dim == 1 || fabs(isect_point[1]) <= m_size[1])
|
||||
&& (dim == 2 || fabs(isect_point[2]) <= m_size[2]) )
|
||||
{
|
||||
res.push_back(
|
||||
Intersection(_this,
|
||||
m_transform.transform_point(
|
||||
isect_point))
|
||||
res.add(Intersection(_this,
|
||||
m_transform.transform_point(isect_point))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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]
|
||||
< m_bottom_radius_2)
|
||||
{
|
||||
res.push_back(
|
||||
Intersection(_this,
|
||||
m_transform.transform_point(isect_point))
|
||||
);
|
||||
res.add(Intersection(_this,
|
||||
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]
|
||||
< m_top_radius_2)
|
||||
{
|
||||
res.push_back(
|
||||
Intersection(_this,
|
||||
m_transform.transform_point(isect_point))
|
||||
);
|
||||
res.add(Intersection(_this,
|
||||
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]];
|
||||
if (isect_point[2] >= 0.0 && isect_point[2] <= m_height)
|
||||
{
|
||||
res.push_back(
|
||||
Intersection(_this,
|
||||
m_transform.transform_point(isect_point))
|
||||
);
|
||||
res.add(Intersection(_this,
|
||||
m_transform.transform_point(isect_point)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,9 +39,7 @@ Shape::IntersectionList Plane::intersect(refptr<Shape> _this, const Ray & ray)
|
||||
if (solutions.numResults > 0)
|
||||
{
|
||||
Vector isect_point = ray_inv[solutions.results[0]];
|
||||
res.push_back(
|
||||
Intersection(_this, m_transform.transform_point(isect_point))
|
||||
);
|
||||
res.add(Intersection(_this, m_transform.transform_point(isect_point)));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -10,3 +10,9 @@ Shape::Shape()
|
||||
Shape::~Shape()
|
||||
{
|
||||
}
|
||||
|
||||
Shape::IntersectionList
|
||||
Shape::IntersectionList::merge(const IntersectionList & other,
|
||||
const Vector & startPoint)
|
||||
{
|
||||
}
|
||||
|
@ -15,7 +15,31 @@ class Shape
|
||||
{
|
||||
public:
|
||||
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();
|
||||
virtual ~Shape();
|
||||
|
@ -30,7 +30,7 @@ Shape::IntersectionList Sphere::intersect(refptr<Shape> _this, const Ray & ray)
|
||||
if (quadSolutions.results[i] >= 0.0)
|
||||
{
|
||||
Vector isect_point = ray_inv[quadSolutions.results[i]];
|
||||
res.push_back(
|
||||
res.add(
|
||||
Intersection(_this, m_transform.transform_point(isect_point))
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user