summaryrefslogtreecommitdiffstats
path: root/src/BSPTree.cpp
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-12-17 02:14:32 +0100
committerMatthias Schiffer <matthias@gamezock.de>2009-12-17 02:14:32 +0100
commitbc797d4c8b5f8a7ac925ca8478dc5960907a81dd (patch)
treed38e89dd598833240462b6b6047ada7eebb321e6 /src/BSPTree.cpp
parentea08fea654b4702a77f623b74137fabc7d6800d8 (diff)
downloadzoom++-bc797d4c8b5f8a7ac925ca8478dc5960907a81dd.tar
zoom++-bc797d4c8b5f8a7ac925ca8478dc5960907a81dd.zip
Moved Plane to MathUtil; some other tweaks
Diffstat (limited to 'src/BSPTree.cpp')
-rw-r--r--src/BSPTree.cpp27
1 files changed, 11 insertions, 16 deletions
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<TriangleRecord> *front, std::list<TriangleRecord> *back) const {
+void BSPTree::partition(const TriangleRecord &t, std::list<TriangleRecord> *front, std::list<TriangleRecord> *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::list<TriangleRecord
for(int i = 0; i < 3; ++i) {
const vmml::vec3f *v[3] = {&t.triangle.getVertex(i), &t.triangle.getVertex((i+1)%3), &t.triangle.getVertex((i+2)%3)};
- if((isInFront(*v[0]) && isBehind(*v[1]) && isBehind(*v[2]))
- || (isBehind(*v[0]) && isInFront(*v[1]) && isInFront(*v[2]))) {
- vmml::vec3f is1 = intersection(*v[0], *v[1]-*v[0]);
- vmml::vec3f is2 = intersection(*v[0], *v[2]-*v[0]);
+ if((plane.isInFront(*v[0]) && plane.isBehind(*v[1]) && plane.isBehind(*v[2]))
+ || (plane.isBehind(*v[0]) && plane.isInFront(*v[1]) && plane.isInFront(*v[2]))) {
+ vmml::vec3f is1 = plane.intersection(*v[0], *v[1]-*v[0]);
+ vmml::vec3f is2 = plane.intersection(*v[0], *v[2]-*v[0]);
- if(isInFront(*v[0])) {
+ if(plane.isInFront(*v[0])) {
front->push_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<TriangleRecord> &triangles) : frontTree(0), bac
if(!planeT)
return;
- plane = Plane(*planeT);
+ plane = MathUtil::Plane(*planeT);
std::list<TriangleRecord> front, back;
@@ -99,7 +94,7 @@ BSPTree::BSPTree(const std::list<TriangleRecord> &triangles) : frontTree(0), bac
continue;
}
- plane.partition(*t, &front, &back);
+ partition(*t, &front, &back);
}
if(!front.empty())