From 8c8948a6fc78aa769ac4ceeb0a1e6d0471376ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Constantin=20Ri=C3=9F?= Date: Wed, 2 Dec 2009 18:21:53 +0100 Subject: Mehr Quader([5][5][5]), Quader nur einmal erzeugen --- Cuboid.h | 1 + DisplayClass.cpp | 68 +++++++++++++++++++------------------------------------- DisplayClass.h | 12 ++++++++-- 3 files changed, 34 insertions(+), 47 deletions(-) diff --git a/Cuboid.h b/Cuboid.h index d54e5d2..05580e1 100644 --- a/Cuboid.h +++ b/Cuboid.h @@ -10,6 +10,7 @@ class Cuboid { public: + Cuboid() : width(0), height(0), depth(0), x(0), y(0), z(0) {} Cuboid(float width, float height, float depth); Cuboid(float width, float height, float depth, float x, float y, float z); float getHeight(); diff --git a/DisplayClass.cpp b/DisplayClass.cpp index 30abdcb..3a43569 100644 --- a/DisplayClass.cpp +++ b/DisplayClass.cpp @@ -1,37 +1,24 @@ -#include "Cuboid.h" #include "DisplayClass.h" #include "Matrix.h" #include "gl.h" #include - + + +DisplayClass::DisplayClass() { + static const float pos[5] = {0.0, 1.0, 3.0, 6.0, 10.0}; + + for(int i = 0; i < 5; ++i) { + for(int j = 0; j < 5; ++j) { + for(int k = 0; k < 5; ++k) { + cubes[i][j][k].setSize(0.5, 0.5, 0.5); + cubes[i][j][k].setPos(pos[k], pos[j], pos[i]); + } + } + } +} void DisplayClass::renderScene(unsigned long delta) { - //Cuboid cube1(2, 2, 1, -1, 1, 0.5); - //Cuboid cube2(1, 1, 2, -0.5, 0.5, -1.5); - - static const Cuboid dc(0.8, 2, 0.8); - static const float xs[5] = {-2.0, -1.0, 0.0, 1.0, 2.0}; - static const float zs[5] = {-2.0, -1.0, 0.0, 1.0, 2.0}; - - Cuboid cubes[5][5] = { - {dc, dc, dc, dc, dc}, - {dc, dc, dc, dc, dc}, - {dc, dc, dc, dc, dc}, - {dc, dc, dc, dc, dc}, - {dc, dc, dc, dc, dc}, - }; - - for(int i = 0; i < 5; ++i) { - for(int j = 0; j < 5; ++j) { - cubes[i][j].setPos(xs[j], 0.0, zs[i]); - } - } -/* {Cuboid(2, 1, 1, -2.5, 1.0, -1.5), Cuboid(2, 1, 1, -1.5, 1.0, -1.5), Cuboid(2, 1, 1, -0.5, 1.0, -1.5), Cuboid(2, 1, 1, 0.5, 1.0, -1.5), Cuboid(2, 1, 1, 1.5, 1.0, -1.5)}, - {Cuboid(2, 1, 1, -2.5, 1.0, -0.5), Cuboid(2, 1, 1, -1.5, 1.0, -1.5), Cuboid(2, 1, 1, -0.5, 1.0, -1.5), Cuboid(2, 1, 1, 0.5, 1.0, -0.5), Cuboid(2, 1, 1, 1.5, 1.0, -0.5)}, - {Cuboid(2, 1, 1, -2.5, 1.0, 0.5), Cuboid(2, 1, 1, -1.5, 1.0, -1.5), Cuboid(2, 1, 1, -0.5, 1.0, -1.5), Cuboid(2, 1, 1, 0.5, 1.0, -1.5), Cuboid(2, 1, 1, 1.5, 1.0, 0.5)}, - {Cuboid(2, 1, 1, -2.5, 1.0, 1.5), Cuboid(2, 1, 1, -1.5, 1.0, -1.5), Cuboid(2, 1, 1, -0.5, 1.0, -1.5), Cuboid(2, 1, 1, 0.5, 1.0, -1.5), Cuboid(2, 1, 1, 1.5, 1.0, 1.5)}, - {Cuboid(2, 1, 1, -2.5, 1.0, 2.5), Cuboid(2, 1, 1, -1.5, 1.0, 2.5), Cuboid(2, 1, 1, -0.5, 1.0, 2.5), Cuboid(2, 1, 1, 0.5, 1.0, 2.5), Cuboid(2, 1, 1, 1.5, 1.0, 2.5)}};*/ static float angle = 0.0; angle += delta*0.05; if(angle >= 360) @@ -45,32 +32,23 @@ void DisplayClass::renderScene(unsigned long delta) std::list triangles; glLoadIdentity(); // Clean up matrix - glTranslatef(0.0, 0.0, -10.0); // Then set up transformation + glTranslatef(0.0, 0.0, -40.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*2, 1.0, 0.0, 0.0); + glRotatef(angle*3, 0.0, 0.0, 1.0); - //glRotatef(-angle*5, 0.0, 0.0, 1.0); + glRotatef(-angle*5, 1.0, 1.0, 1.0); m.store(); // Save current transformation for(int i = 0; i < 5; ++i) { - for(int j = 0; j < 5; ++j) { - std::list ct = cubes[i][j].getTriangles(m); - triangles.splice(triangles.end(), ct); + for(int j = 0; j < 5; ++j) { + for(int k = 0; k < 5; ++k) { + std::list ct = cubes[i][j][k].getTriangles(m); + triangles.splice(triangles.end(), ct); + } } } - /*std::list t1 = cube1.getTriangles(m); - triangles.splice(triangles.end(), t1); - - glRotatef(angle*10, 0.0, 0.0, 1.0); - m.store(); - - t1 = cube2.getTriangles(m); - triangles.splice(triangles.end(), t1);*/ - - //std::sort(triangles.begin(), triangles.end(), Sorter(p)); - glLoadIdentity(); glBegin(GL_TRIANGLES); diff --git a/DisplayClass.h b/DisplayClass.h index adb2422..367e51a 100644 --- a/DisplayClass.h +++ b/DisplayClass.h @@ -1,10 +1,18 @@ #ifndef _DISPLAYCLASS_H_ #define _DISPLAYCLASS_H_ +#include "Cuboid.h" + + class DisplayClass { - public: - void renderScene(unsigned long delta); + public: + DisplayClass(); + + void renderScene(unsigned long delta); + + private: + Cuboid cubes[5][5][5]; }; #endif /*_DISPLAYCLASS_H_*/ -- cgit v1.2.3