summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-12-10 11:29:16 +0100
committerMatthias Schiffer <matthias@gamezock.de>2009-12-10 11:29:16 +0100
commitf31beab9a7160e913da7ff30d946eaf2a721fdc8 (patch)
tree1239a46bbea9c8f4af295d2a66e0429d960550ff
parent4f2236f36446a5b097e28c0f76e4962ce7e115b1 (diff)
downloadc3d-f31beab9a7160e913da7ff30d946eaf2a721fdc8.tar
c3d-f31beab9a7160e913da7ff30d946eaf2a721fdc8.zip
BSPTree-Visiting-Reihenfolge korrigiert
-rw-r--r--BSPTree.h24
-rw-r--r--Cuboid.cpp32
-rw-r--r--DisplayClass.cpp26
-rw-r--r--DisplayClass.h6
-rw-r--r--Triangle.h1
-rw-r--r--main.cpp2
6 files changed, 46 insertions, 45 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..d993e3b 100644
--- a/DisplayClass.cpp
+++ b/DisplayClass.cpp
@@ -8,39 +8,41 @@ DisplayClass::TransparentRenderer DisplayClass::transparentRenderer;
DisplayClass::DisplayClass() {
- cubeing[0] = Trapezocube(11.0, 10.0, 10.0, 0.5, 0.0, 0.0, 1.75, 0);
+ /*cubeing[0] = Trapezocube(11.0, 10.0, 10.0, 0.5, 0.0, 0.0, 1.75, 0);
cubeing[1] = Trapezocube(10.0, 9.0, 9.0, 0.5, 0.0, 0.0, 2.25, 90);
cubeing[2] = Trapezocube(9.0, 8.0, 8.0, 0.5, 0.0, 0.0, 2.75, 180);
cubeing[3] = Trapezocube(8.0, 7.0, 7.0, 0.5, 0.0, 0.0, 3.25, 270);
cubeing[4] = Trapezocube(7.0, 6.0, 6.0, 0.5, 0.0, 0.0, 3.75, 0);
cubeing[5] = Trapezocube(6.0, 5.0, 5.0, 0.5, 0.0, 0.0, 4.25, 90);
cubeing[6] = Trapezocube(5.0, 4.0, 4.0, 0.5, 0.0, 0.0, 4.75, 180);
- cubeing[7] = Trapezocube(4.0, 3.0, 3.0, 0.5, 0.0, 0.0, 5.25, 270);
+ cubeing[7] = Trapezocube(4.0, 3.0, 3.0, 0.5, 0.0, 0.0, 5.25, 270);*/
+
+ cube = Cuboid(1, 1, 1, 0, 0, 0);
}
void DisplayClass::renderScene(unsigned long delta)
{
static float angle = 0.0;
- angle += delta*0.025;
+ angle += delta*0.015;
if(angle >= 360)
angle -= 360;
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
+ glTranslatef(0.0, 0.0, -5.0); // Then set up transformation
glRotatef(angle, 0.0, 1.0, 0.0);
glRotatef(angle*2, 1.0, 0.0, 0.0);
glRotatef(angle*3, 0.0, 0.0, 1.0);
glRotatef(-angle*5, 1.0, 1.0, 1.0);
- for(int i = 0; i < 8; ++i) {
+ std::list<Triangle> triangles = cube.getTriangles();
+
+ /*for(int i = 0; i < 8; ++i) {
std::list<Triangle> t = cubeing[i].getTriangles();
triangles.splice(triangles.end(), t);
- }
+ }*/
BSPTree tree(triangles);
@@ -48,12 +50,12 @@ 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(opaqueRenderer, viewPoint);
+ tree.visit(transparentRenderer, viewPoint);
glEnd();
glFlush();
diff --git a/DisplayClass.h b/DisplayClass.h
index 0341469..d1e56ba 100644
--- a/DisplayClass.h
+++ b/DisplayClass.h
@@ -1,7 +1,8 @@
#ifndef _DISPLAYCLASS_H_
#define _DISPLAYCLASS_H_
-#include "Trapezocube.h"
+//#include "Trapezocube.h"
+#include "Cuboid.h"
class DisplayClass
{
@@ -28,7 +29,8 @@ class DisplayClass
static OpaqueRenderer opaqueRenderer;
static TransparentRenderer transparentRenderer;
- Trapezocube cubeing[8];
+ //Trapezocube cubeing[8];
+ Cuboid cube;
};
#endif /*_DISPLAYCLASS_H_*/
diff --git a/Triangle.h b/Triangle.h
index dc48071..febcb3d 100644
--- a/Triangle.h
+++ b/Triangle.h
@@ -24,6 +24,7 @@ class Triangle
}
void render() const {
+ glColor4fv(c.array);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, c.array);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (c/2).array);
diff --git a/main.cpp b/main.cpp
index 58309f1..5fe8b84 100644
--- a/main.cpp
+++ b/main.cpp
@@ -18,7 +18,7 @@ void initGL(bool multisample);
void resize(int width, int height);
void initGL(bool multisample) {
- glClearColor(1.0, 0.85, 0.06, 1.0);
+ glClearColor(0, 0, 0, 1.0);
glClearDepth(1.0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);