summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-12-10 11:39:42 +0100
committerMatthias Schiffer <matthias@gamezock.de>2009-12-10 11:39:42 +0100
commite34b6f19888ab063201c7b4f2706b200fa93cd35 (patch)
treecb68a536ea8280734a60d590fd765bc06dc92957
parent4f2236f36446a5b097e28c0f76e4962ce7e115b1 (diff)
parentf31beab9a7160e913da7ff30d946eaf2a721fdc8 (diff)
downloadc3d-e34b6f19888ab063201c7b4f2706b200fa93cd35.tar
c3d-e34b6f19888ab063201c7b4f2706b200fa93cd35.zip
Korrigierte BSPTree-Render-Reihenfolge gemerged
-rw-r--r--BSPTree.h24
-rw-r--r--Cuboid.cpp32
-rw-r--r--DisplayClass.cpp14
-rw-r--r--DisplayClass.h15
4 files changed, 35 insertions, 50 deletions
diff --git a/BSPTree.h b/BSPTree.h
index a03327b..0b13b6b 100644
--- a/BSPTree.h
+++ b/BSPTree.h
@@ -78,54 +78,54 @@ class BSPTree {
}
template<typename T>
- void visit(const T& visitor, const vmml::vec3f &v) {
- if(plane.getNormal().dot(v) > 0) {
+ void visit(const T& visitor, const vmml::vec3f &p) {
+ if(plane.isBehind(p)) {
if(frontTree)
- frontTree->visit(visitor, v);
+ frontTree->visit(visitor, p);
for(std::list<Triangle>::iterator t = triangles.begin(); t != triangles.end(); ++t) {
visitor(*t);
}
if(backTree)
- backTree->visit(visitor, v);
+ backTree->visit(visitor, p);
}
else {
if(backTree)
- backTree->visit(visitor, v);
+ backTree->visit(visitor, p);
for(std::list<Triangle>::iterator t = triangles.begin(); t != triangles.end(); ++t) {
visitor(*t);
}
if(frontTree)
- frontTree->visit(visitor, v);
+ frontTree->visit(visitor, p);
}
}
template<typename T>
- void visit(T& visitor, const vmml::vec3f &v) {
- if(plane.getNormal().dot(v) > 0) {
+ void visit(T& visitor, const vmml::vec3f &p) {
+ if(plane.isBehind(p)) {
if(frontTree)
- frontTree->visit(visitor, v);
+ frontTree->visit(visitor, p);
for(std::list<Triangle>::iterator t = triangles.begin(); t != triangles.end(); ++t) {
visitor(*t);
}
if(backTree)
- backTree->visit(visitor, v);
+ backTree->visit(visitor, p);
}
else {
if(backTree)
- backTree->visit(visitor, v);
+ backTree->visit(visitor, p);
for(std::list<Triangle>::iterator t = triangles.begin(); t != triangles.end(); ++t) {
visitor(*t);
}
if(frontTree)
- frontTree->visit(visitor, v);
+ frontTree->visit(visitor, p);
}
}
diff --git a/Cuboid.cpp b/Cuboid.cpp
index ed0de5d..5b1af49 100644
--- a/Cuboid.cpp
+++ b/Cuboid.cpp
@@ -68,19 +68,19 @@ std::list<Triangle> Cuboid::getTriangles(/*const Matrix &modelview*/)
vmml::vec4f c(0.0, 0.0, 1.0, 0.5);
triangles.push_back(Triangle(vmml::vec3f(x-width/2, y+height/2, z+depth/2),
- vmml::vec3f(x+width/2, y+height/2, z+depth/2),
- vmml::vec3f(x-width/2, y-height/2, z+depth/2), c));
+ vmml::vec3f(x-width/2, y-height/2, z+depth/2),
+ vmml::vec3f(x+width/2, y+height/2, z+depth/2), c));
triangles.push_back(Triangle(vmml::vec3f(x-width/2, y-height/2, z+depth/2),
- vmml::vec3f(x+width/2, y+height/2, z+depth/2),
- vmml::vec3f(x+width/2, y-height/2, z+depth/2), c));
+ vmml::vec3f(x+width/2, y-height/2, z+depth/2),
+ vmml::vec3f(x+width/2, y+height/2, z+depth/2), c));
// Back face
c = vmml::vec4f(1.0, 1.0, 0.0, 0.5);
triangles.push_back(Triangle(vmml::vec3f(x-width/2, y+height/2, z-depth/2),
- vmml::vec3f(x-width/2, y-height/2, z-depth/2),
- vmml::vec3f(x+width/2, y+height/2, z-depth/2), c));
+ vmml::vec3f(x+width/2, y+height/2, z-depth/2),
+ vmml::vec3f(x-width/2, y-height/2, z-depth/2), c));
triangles.push_back(Triangle(vmml::vec3f(x-width/2, y-height/2, z-depth/2),
vmml::vec3f(x+width/2, y+height/2, z-depth/2),
@@ -90,12 +90,12 @@ std::list<Triangle> Cuboid::getTriangles(/*const Matrix &modelview*/)
c = vmml::vec4f(0.0, 1.0, 0.0, 0.5);
triangles.push_back(Triangle(vmml::vec3f(x-width/2, y+height/2, z+depth/2),
- vmml::vec3f(x-width/2, y-height/2, z+depth/2),
- vmml::vec3f(x-width/2, y+height/2, z-depth/2), c));
-
- triangles.push_back(Triangle(vmml::vec3f(x-width/2, y-height/2, z-depth/2),
vmml::vec3f(x-width/2, y+height/2, z-depth/2),
vmml::vec3f(x-width/2, y-height/2, z+depth/2), c));
+
+ triangles.push_back(Triangle(vmml::vec3f(x-width/2, y-height/2, z-depth/2),
+ vmml::vec3f(x-width/2, y-height/2, z+depth/2),
+ vmml::vec3f(x-width/2, y+height/2, z-depth/2), c));
// Right face
@@ -121,16 +121,12 @@ std::list<Triangle> Cuboid::getTriangles(/*const Matrix &modelview*/)
// Bottom face
triangles.push_back(Triangle(vmml::vec3f(x-width/2, y-height/2, z+depth/2),
- vmml::vec3f(x+width/2, y-height/2, z+depth/2),
- vmml::vec3f(x-width/2, y-height/2, z-depth/2), c));
+ vmml::vec3f(x-width/2, y-height/2, z-depth/2),
+ vmml::vec3f(x+width/2, y-height/2, z+depth/2), c));
triangles.push_back(Triangle(vmml::vec3f(x+width/2, y-height/2, z+depth/2),
- vmml::vec3f(x+width/2, y-height/2, z-depth/2),
- vmml::vec3f(x-width/2, y-height/2, z-depth/2), c));
-
- /*for(std::list<Triangle>::iterator t = triangles.begin(); t != triangles.end(); ++t) {
- t->transform(modelview);
- }*/
+ vmml::vec3f(x-width/2, y-height/2, z-depth/2),
+ vmml::vec3f(x+width/2, y-height/2, z-depth/2), c));
return triangles;
}
diff --git a/DisplayClass.cpp b/DisplayClass.cpp
index 69c4c17..cf7a0f9 100644
--- a/DisplayClass.cpp
+++ b/DisplayClass.cpp
@@ -3,8 +3,7 @@
#include "BSPTree.h"
-DisplayClass::OpaqueRenderer DisplayClass::opaqueRenderer;
-DisplayClass::TransparentRenderer DisplayClass::transparentRenderer;
+DisplayClass::Renderer DisplayClass::renderer;
DisplayClass::DisplayClass() {
@@ -27,8 +26,6 @@ void DisplayClass::renderScene(unsigned long delta)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- std::list<Triangle> triangles;
-
glLoadIdentity(); // Clean up matrix
glTranslatef(0.0, 0.0, -30.0); // Then set up transformation
glRotatef(angle, 0.0, 1.0, 0.0);
@@ -37,6 +34,8 @@ void DisplayClass::renderScene(unsigned long delta)
glRotatef(-angle*5, 1.0, 1.0, 1.0);
+ std::list<Triangle> triangles;
+
for(int i = 0; i < 8; ++i) {
std::list<Triangle> t = cubeing[i].getTriangles();
triangles.splice(triangles.end(), t);
@@ -48,12 +47,11 @@ void DisplayClass::renderScene(unsigned long delta)
glGetFloatv(GL_MODELVIEW_MATRIX, transform.array);
transform.inverse(inverseTransform);
- inverseTransform.set_translation(vmml::vec3f());
- vmml::vec3f viewVector = inverseTransform*vmml::vec3f(0, 0, -1);
+
+ vmml::vec3f viewPoint = inverseTransform*vmml::vec3f(0, 0, 0);
glBegin(GL_TRIANGLES);
- tree.visit(opaqueRenderer, -viewVector);
- tree.visit(transparentRenderer, viewVector);
+ tree.visit(renderer, viewPoint);
glEnd();
glFlush();
diff --git a/DisplayClass.h b/DisplayClass.h
index 0341469..0b24dc6 100644
--- a/DisplayClass.h
+++ b/DisplayClass.h
@@ -11,22 +11,13 @@ class DisplayClass
void renderScene(unsigned long delta);
private:
- struct OpaqueRenderer {
+ struct Renderer {
void operator() (const Triangle &t) const {
- if(t.getColor().a() == 1.0)
- t.render();
+ t.render();
}
};
- struct TransparentRenderer {
- void operator() (const Triangle &t) const {
- if(t.getColor().a() != 1.0)
- t.render();
- }
- };
-
- static OpaqueRenderer opaqueRenderer;
- static TransparentRenderer transparentRenderer;
+ static Renderer renderer;
Trapezocube cubeing[8];
};