From 56278a8337634f8bc7ac89bc90807b92e38bce37 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 23 Feb 2009 21:39:56 +0000 Subject: [PATCH] changed IntersectionList into a class so i could add merge() git-svn-id: svn://anubis/fart/trunk@148 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- shapes/Box.cc | 6 ++---- shapes/Cyl.cc | 18 ++++++------------ shapes/Plane.cc | 4 +--- shapes/Shape.cc | 6 ++++++ shapes/Shape.h | 26 +++++++++++++++++++++++++- shapes/Sphere.cc | 2 +- 6 files changed, 41 insertions(+), 21 deletions(-) diff --git a/shapes/Box.cc b/shapes/Box.cc index ae07812..2131020 100644 --- a/shapes/Box.cc +++ b/shapes/Box.cc @@ -45,10 +45,8 @@ Shape::IntersectionList Box::intersect(refptr _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)) ); } } diff --git a/shapes/Cyl.cc b/shapes/Cyl.cc index 833755e..daab4b8 100644 --- a/shapes/Cyl.cc +++ b/shapes/Cyl.cc @@ -36,10 +36,8 @@ Shape::IntersectionList Cyl::intersect(refptr _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 _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 _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))); } } } diff --git a/shapes/Plane.cc b/shapes/Plane.cc index e32cb8d..ff18e91 100644 --- a/shapes/Plane.cc +++ b/shapes/Plane.cc @@ -39,9 +39,7 @@ Shape::IntersectionList Plane::intersect(refptr _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; } diff --git a/shapes/Shape.cc b/shapes/Shape.cc index ce0a346..2fef45b 100755 --- a/shapes/Shape.cc +++ b/shapes/Shape.cc @@ -10,3 +10,9 @@ Shape::Shape() Shape::~Shape() { } + +Shape::IntersectionList +Shape::IntersectionList::merge(const IntersectionList & other, + const Vector & startPoint) +{ +} diff --git a/shapes/Shape.h b/shapes/Shape.h index 044c7e5..9157b97 100644 --- a/shapes/Shape.h +++ b/shapes/Shape.h @@ -15,7 +15,31 @@ class Shape { public: typedef std::pair< refptr , 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::const_iterator begin() + { + return m_intersections.begin(); + } + std::vector::const_iterator end() + { + return m_intersections.end(); + } + IntersectionList merge(const IntersectionList & other, + const Vector & startPoint); + protected: + std::vector< Intersection > m_intersections; + }; Shape(); virtual ~Shape(); diff --git a/shapes/Sphere.cc b/shapes/Sphere.cc index ff2fb90..3e53bd1 100644 --- a/shapes/Sphere.cc +++ b/shapes/Sphere.cc @@ -30,7 +30,7 @@ Shape::IntersectionList Sphere::intersect(refptr _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)) ); }