From 21736d4fee7e61b08227982a8402584887abda1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Constantin=20Ri=C3=9F?= Date: Wed, 2 Dec 2009 17:19:57 +0100 Subject: Positionsangabe (Quader) auf Mitte verlagert. --- Cuboid.cpp | 72 ++++++++++++++++++++++++++++---------------------------- DisplayClass.cpp | 8 +++---- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Cuboid.cpp b/Cuboid.cpp index 6569e31..6b58294 100644 --- a/Cuboid.cpp +++ b/Cuboid.cpp @@ -68,66 +68,66 @@ std::list Cuboid::getTriangles(const Matrix &modelview) // Front face Color c(0.0, 0.0, 1.0, 0.5); - triangles.push_back(Triangle(Vertex(x , y , z), - Vertex(x+width, y , z), - Vertex(x , y-height, z), c)); + triangles.push_back(Triangle(Vertex(x-width/2, y+height/2, z+depth/2), + Vertex(x+width/2, y+height/2, z+depth/2), + Vertex(x-width/2, y-height/2, z+depth/2), c)); - triangles.push_back(Triangle(Vertex(x , y-height, z), - Vertex(x+width, y , z), - Vertex(x+width, y-height, z), c)); + triangles.push_back(Triangle(Vertex(x-width/2, y-height/2, z+depth/2), + Vertex(x+width/2, y+height/2, z+depth/2), + Vertex(x+width/2, y-height/2, z+depth/2), c)); // Back face c = Color(1.0, 1.0, 0.0, 0.5); - triangles.push_back(Triangle(Vertex(x , y , z-depth), - Vertex(x , y-height, z-depth), - Vertex(x+width, y , z-depth), c)); + triangles.push_back(Triangle(Vertex(x-width/2, y+height/2, z-depth/2), + Vertex(x-width/2, y-height/2, z-depth/2), + Vertex(x+width/2, y+height/2, z-depth/2), c)); - triangles.push_back(Triangle(Vertex(x , y-height, z-depth), - Vertex(x+width, y , z-depth), - Vertex(x+width, y-height, z-depth), c)); + triangles.push_back(Triangle(Vertex(x-width/2, y-height/2, z-depth/2), + Vertex(x+width/2, y+height/2, z-depth/2), + Vertex(x+width/2, y-height/2, z-depth/2), c)); // Left face c = Color(0.0, 1.0, 0.0, 0.5); - triangles.push_back(Triangle(Vertex(x, y , z ), - Vertex(x, y-height, z ), - Vertex(x, y , z-depth), c)); + triangles.push_back(Triangle(Vertex(x-width/2, y+height/2, z+depth/2), + Vertex(x-width/2, y-height/2, z+depth/2), + Vertex(x-width/2, y+height/2, z-depth/2), c)); - triangles.push_back(Triangle(Vertex(x, y-height, z-depth), - Vertex(x, y , z-depth), - Vertex(x, y-height, z ), c)); + triangles.push_back(Triangle(Vertex(x-width/2, y-height/2, z-depth/2), + Vertex(x-width/2, y+height/2, z-depth/2), + Vertex(x-width/2, y-height/2, z+depth/2), c)); // Right face - triangles.push_back(Triangle(Vertex(x+width, y , z ), - Vertex(x+width, y-height, z ), - Vertex(x+width, y , z-depth), c)); + triangles.push_back(Triangle(Vertex(x+width/2, y+height/2, z+depth/2), + Vertex(x+width/2, y-height/2, z+depth/2), + Vertex(x+width/2, y+height/2, z-depth/2), c)); - triangles.push_back(Triangle(Vertex(x+width, y-height, z-depth), - Vertex(x+width, y , z-depth), - Vertex(x+width, y-height, z ), c)); + triangles.push_back(Triangle(Vertex(x+width/2, y-height/2, z-depth/2), + Vertex(x+width/2, y+height/2, z-depth/2), + Vertex(x+width/2, y-height/2, z+depth/2), c)); // Top face c = Color(1.0, 0.0, 0.0, 0.5); - triangles.push_back(Triangle(Vertex(x , y, z ), - Vertex(x+width, y, z ), - Vertex(x , y, z-depth), c)); + triangles.push_back(Triangle(Vertex(x-width/2, y+height/2, z+depth/2), + Vertex(x+width/2, y+height/2, z+depth/2), + Vertex(x-width/2, y+height/2, z-depth/2), c)); - triangles.push_back(Triangle(Vertex(x+width, y, z ), - Vertex(x+width, y, z-depth), - Vertex(x , y, z-depth), c)); + triangles.push_back(Triangle(Vertex(x+width/2, y+height/2, z+depth/2), + Vertex(x+width/2, y+height/2, z-depth/2), + Vertex(x-width/2, y+height/2, z-depth/2), c)); // Bottom face - triangles.push_back(Triangle(Vertex(x , y-height, z ), - Vertex(x+width, y-height, z ), - Vertex(x , y-height, z-depth), c)); + triangles.push_back(Triangle(Vertex(x-width/2, y-height/2, z+depth/2), + Vertex(x+width/2, y-height/2, z+depth/2), + Vertex(x-width/2, y-height/2, z-depth/2), c)); - triangles.push_back(Triangle(Vertex(x+width, y-height, z ), - Vertex(x+width, y-height, z-depth), - Vertex(x , y-height, z-depth), c)); + triangles.push_back(Triangle(Vertex(x+width/2, y-height/2, z+depth/2), + Vertex(x+width/2, y-height/2, z-depth/2), + Vertex(x-width/2, y-height/2, z-depth/2), c)); for(std::list::iterator t = triangles.begin(); t != triangles.end(); ++t) { t->transform(modelview); diff --git a/DisplayClass.cpp b/DisplayClass.cpp index 9cae95c..30abdcb 100644 --- a/DisplayClass.cpp +++ b/DisplayClass.cpp @@ -11,8 +11,8 @@ void DisplayClass::renderScene(unsigned long delta) //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.5, -1.5, -0.5, 0.5, 1.5}; - static const float zs[5] = {-1.5, -0.5, 0.5, 1.5, 2.5}; + 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}, @@ -24,7 +24,7 @@ void DisplayClass::renderScene(unsigned long delta) for(int i = 0; i < 5; ++i) { for(int j = 0; j < 5; ++j) { - cubes[i][j].setPos(xs[j], 1.0, zs[i]); + 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)}, @@ -33,7 +33,7 @@ void DisplayClass::renderScene(unsigned long delta) {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.043; + angle += delta*0.05; if(angle >= 360) angle -= 360; -- cgit v1.2.3