From bc797d4c8b5f8a7ac925ca8478dc5960907a81dd Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 17 Dec 2009 02:14:32 +0100 Subject: Moved Plane to MathUtil; some other tweaks --- src/BSPTree.cpp | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'src/BSPTree.cpp') diff --git a/src/BSPTree.cpp b/src/BSPTree.cpp index a94c77a..91efb6d 100644 --- a/src/BSPTree.cpp +++ b/src/BSPTree.cpp @@ -21,20 +21,15 @@ namespace Zoom { -vmml::vec3f BSPTree::Plane::intersection(const vmml::vec3f &p, const vmml::vec3f &dir) const { - float r = (d - p.dot(normal))/dir.dot(normal); - return p + r*dir; -} - -void BSPTree::Plane::partition(const TriangleRecord &t, std::list *front, std::list *back) const { +void BSPTree::partition(const TriangleRecord &t, std::list *front, std::list *back) const { for(int i = 0; i < 3; ++i) { - if(contains(t.triangle.getVertex(i))) { + if(plane.contains(t.triangle.getVertex(i))) { const vmml::vec3f *v[3] = {&t.triangle.getVertex(i), &t.triangle.getVertex((i+1)%3), &t.triangle.getVertex((i+2)%3)}; - vmml::vec3f is = intersection(*v[1], *v[2]-*v[1]); + vmml::vec3f is = plane.intersection(*v[1], *v[2]-*v[1]); - if(isInFront(*v[1])) { + if(plane.isInFront(*v[1])) { front->push_back(TriangleRecord(Triangle(*v[0], *v[1], is, t.triangle.getColor()), t.data)); back->push_back(TriangleRecord(Triangle(*v[0], is, *v[2], t.triangle.getColor()), t.data)); } @@ -50,12 +45,12 @@ void BSPTree::Plane::partition(const TriangleRecord &t, std::listpush_back(TriangleRecord(Triangle(*v[0], is1, is2, t.triangle.getColor()), t.data)); back->push_back(TriangleRecord(Triangle(is1, *v[1], is2, t.triangle.getColor()), t.data)); back->push_back(TriangleRecord(Triangle(*v[1], *v[2], is2, t.triangle.getColor()), t.data)); @@ -78,7 +73,7 @@ BSPTree::BSPTree(const std::list &triangles) : frontTree(0), bac if(!planeT) return; - plane = Plane(*planeT); + plane = MathUtil::Plane(*planeT); std::list front, back; @@ -99,7 +94,7 @@ BSPTree::BSPTree(const std::list &triangles) : frontTree(0), bac continue; } - plane.partition(*t, &front, &back); + partition(*t, &front, &back); } if(!front.empty()) -- cgit v1.2.3