From 83bb409ef97325b7f803bc52eb0e3eeb128f56e6 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 27 Jan 2009 18:48:04 +0000 Subject: [PATCH] added Shape::IntersectList for returning a list of intersection points instead of intersections distances; build currently broken; need to update Scene to take into effect this change git-svn-id: svn://anubis/fart/trunk@56 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- shapes/Shape.h | 5 ++++- shapes/Sphere.cc | 7 ++++--- shapes/Sphere.h | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) 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: