diff options
Diffstat (limited to 'src/BSPTree.h')
-rw-r--r-- | src/BSPTree.h | 66 |
1 files changed, 5 insertions, 61 deletions
diff --git a/src/BSPTree.h b/src/BSPTree.h index 1944ef1..e5015d0 100644 --- a/src/BSPTree.h +++ b/src/BSPTree.h @@ -21,6 +21,8 @@ #define ZOOM_BSPTREE_H_ #include "Triangle.h" +#include "MathUtil.h" + #include <list> #include <cmath> @@ -50,66 +52,6 @@ class BSPTree { boost::shared_ptr<TriangleData> data; }; - private: - class Plane { - public: - Plane() : d(0) {} - Plane(const vmml::vec3f &n, float d0) : normal(n), d(d0) {} - Plane(const Triangle &t) : normal(t.computeNormal()), d(t.getVertex(0).dot(normal)) {} - - bool contains(const vmml::vec3f &v) const { - return (fabsf(normal.dot(v) - d) < 1E-6); - } - - bool isBehind(const vmml::vec3f &v) const { - return (normal.dot(v) - d) < 0; - } - - bool isInFront(const vmml::vec3f &v) const { - return (normal.dot(v) - d) > 0; - } - - - bool contains(const Triangle &t) const { - for(int i = 0; i < 3; ++i) { - if(!contains(t.getVertex(i))) - return false; - } - - return true; - } - - bool isBehind(const Triangle &t) const { - for(int i = 0; i < 3; ++i) { - if(!isBehind(t.getVertex(i)) && !contains(t.getVertex(i))) - return false; - } - - return true; - } - - bool isInFront(const Triangle &t) const { - for(int i = 0; i < 3; ++i) { - if(!isInFront(t.getVertex(i)) && !contains(t.getVertex(i))) - return false; - } - - return true; - } - - - const vmml::vec3f& getNormal() const { - return normal; - } - - vmml::vec3f intersection(const vmml::vec3f &p, const vmml::vec3f &dir) const; - void partition(const TriangleRecord &t, std::list<TriangleRecord> *front, std::list<TriangleRecord> *back) const; - - private: - vmml::vec3f normal; - float d; - }; - public: BSPTree(const std::list<TriangleRecord> &triangles); @@ -138,7 +80,7 @@ class BSPTree { } private: - Plane plane; + MathUtil::Plane plane; std::list<TriangleRecord> triangles; BSPTree *frontTree, *backTree; @@ -168,6 +110,8 @@ class BSPTree { } } + void partition(const TriangleRecord &t, std::list<TriangleRecord> *front, std::list<TriangleRecord> *back) const; + static vmml::vec3f findCenter(const std::list<TriangleRecord> &triangles); static const Triangle* findNearestTriangle(const std::list<TriangleRecord> &triangles, const vmml::vec3f &v); }; |