diff options
-rw-r--r-- | BSPTree.h | 24 | ||||
-rw-r--r-- | Cuboid.cpp | 32 | ||||
-rw-r--r-- | DisplayClass.cpp | 14 | ||||
-rw-r--r-- | DisplayClass.h | 15 |
4 files changed, 35 insertions, 50 deletions
@@ -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); } } @@ -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];
};
|