diff --git a/shapes/Shape.h b/shapes/Shape.h index d869b81..1fb9a72 100644 --- a/shapes/Shape.h +++ b/shapes/Shape.h @@ -6,12 +6,15 @@ #include "util/Ray.h" #include "util/Vector.h" #include "util/Transform.h" +#include class Shape { public: + typedef std::vector IntersectList; + Shape(); - virtual Solver::Result intersect(const Ray & ray) = 0; + virtual IntersectList intersect(const Ray & ray) = 0; virtual Vector getNormalAt(const Vector & pt) = 0; void setTransform(Transform & t) diff --git a/shapes/Sphere.cc b/shapes/Sphere.cc index 32d60fb..f0f383e 100644 --- a/shapes/Sphere.cc +++ b/shapes/Sphere.cc @@ -11,11 +11,11 @@ Sphere::Sphere(double radius) m_radius2 = radius * radius; } -Solver::Result Sphere::intersect(const Ray & ray) +Shape::IntersectList Sphere::intersect(const Ray & ray) { Ray ray_inv = m_inverse.transform_ray(ray); - Solver::Result res; + IntersectList res; QuadraticSolver solver(1.0, 2 * ( ray_inv.getOrigin()[0] * ray_inv.getDirection()[0] + ray_inv.getOrigin()[1] * ray_inv.getDirection()[1] @@ -29,7 +29,8 @@ Solver::Result Sphere::intersect(const Ray & ray) { if (quadSolutions.results[i] >= 0.0) { - res.results[res.numResults++] = quadSolutions.results[i]; + res.push_back(m_transform.transform_point( + ray_inv[quadSolutions.results[i]])); } } return res; diff --git a/shapes/Sphere.h b/shapes/Sphere.h index 4824705..02f7111 100644 --- a/shapes/Sphere.h +++ b/shapes/Sphere.h @@ -8,7 +8,7 @@ class Sphere : public Shape { public: Sphere(double radius); - Solver::Result intersect(const Ray & ray); + IntersectList intersect(const Ray & ray); Vector getNormalAt(const Vector & pt); private: