diff options
Diffstat (limited to 'BSPTree.cpp')
-rw-r--r-- | BSPTree.cpp | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/BSPTree.cpp b/BSPTree.cpp index 3254446..ff43274 100644 --- a/BSPTree.cpp +++ b/BSPTree.cpp @@ -54,11 +54,11 @@ void BSPTree::Plane::partition(const Triangle &t, std::list<Triangle> *front, st BSPTree::BSPTree(const std::list<Triangle> &triangles) : frontTree(0), backTree(0) { - if(triangles.empty()) - return; - const Triangle *planeT = findNearestTriangle(triangles, findCenter(triangles)); + if(!planeT) + return; + plane = Plane(*planeT); std::list<Triangle> front, back; @@ -93,6 +93,28 @@ BSPTree::BSPTree(const std::list<Triangle> &triangles) : frontTree(0), backTree( backTree = new BSPTree(back); } +BSPTree& BSPTree::operator=(const BSPTree &tree) { + if(frontTree) { + delete frontTree; + frontTree = 0; + } + + if(backTree) { + delete backTree; + backTree = 0; + } + + plane = tree.plane; + triangles = tree.triangles; + + if(tree.frontTree) + frontTree = new BSPTree(*tree.frontTree); + + if(tree.backTree) + backTree = new BSPTree(*tree.backTree); + + return *this; +} vmml::vec3f BSPTree::findCenter(const std::list<Triangle> &triangles) { vmml::vec3f v; |