summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-12-10 23:33:01 +0100
committerMatthias Schiffer <matthias@gamezock.de>2009-12-10 23:33:01 +0100
commit0d976c387f1cb6b3f6c2cff3a577236ec101d4e0 (patch)
treee2995bef714799bd7653a697abda48ab990ad5a1
parent74d4f23ef8e05180ea764a3b50aadb3dfa5292bd (diff)
downloadc3d-0d976c387f1cb6b3f6c2cff3a577236ec101d4e0.tar
c3d-0d976c387f1cb6b3f6c2cff3a577236ec101d4e0.zip
BSPTree kann jetzt mit degenerierten Dreiecken umgehen
-rw-r--r--BSPTree.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/BSPTree.cpp b/BSPTree.cpp
index 00e916b..3254446 100644
--- a/BSPTree.cpp
+++ b/BSPTree.cpp
@@ -64,6 +64,9 @@ BSPTree::BSPTree(const std::list<Triangle> &triangles) : frontTree(0), backTree(
std::list<Triangle> front, back;
for(std::list<Triangle>::const_iterator t = triangles.begin(); t != triangles.end(); ++t) {
+ if(t->getNormal().squared_length() == 0)
+ continue;
+
if(plane.contains(*t)) {
this->triangles.push_back(*t);
continue;
@@ -102,18 +105,16 @@ vmml::vec3f BSPTree::findCenter(const std::list<Triangle> &triangles) {
}
const Triangle* BSPTree::findNearestTriangle(const std::list<Triangle> &triangles, const vmml::vec3f &v) {
- if(triangles.empty())
- return 0;
+ const Triangle *current = 0;
+ float distanceSq;
- std::list<Triangle>::const_iterator t = triangles.begin();
-
- const Triangle *current = &*t;
- float distanceSq = current->getCenter().squared_distance(v);
+ for(std::list<Triangle>::const_iterator t = triangles.begin(); t != triangles.end(); ++t) {
+ if(t->getNormal().squared_length() == 0)
+ continue;
- for(++t; t != triangles.end(); ++t) {
float d = t->getCenter().squared_distance(v);
- if(d < distanceSq) {
+ if(!current || d < distanceSq) {
current = &*t;
distanceSq = d;
}