From d493571a6cd6a3adfce5a572ab451dd7c95197ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Constantin=20Ri=C3=9F?= Date: Wed, 13 Jan 2010 21:07:04 +0100 Subject: =?UTF-8?q?Das=20Programm=20l=C3=A4uft=20jetzt=20und=20die=20Cubeh?= =?UTF-8?q?oles=20wurden=20verbessert.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cubehole.cpp | 5 +++++ Cubehole.h | 8 ++++---- DisplayClass.cpp | 2 +- Temparray.cpp | 43 +++++++++++++++++++++++++++---------------- Temparray.h | 32 +++++++++++++++++++------------- main.cpp | 2 +- 6 files changed, 57 insertions(+), 35 deletions(-) diff --git a/Cubehole.cpp b/Cubehole.cpp index 03ddc28..0fc32ae 100644 --- a/Cubehole.cpp +++ b/Cubehole.cpp @@ -3,6 +3,11 @@ std::list Cubehole::getTriangles() { + front.setPos(x, y, z+(depth/2-(depth-innerdepth)/4)); + right.setPos(-z, y, x-(width/2-(width-innerwidth)/4)); + back.setPos(-x, y, -z+(depth/2-(depth-innerdepth)/4)); + left.setPos(z, y, -x-(width/2-(width-innerwidth)/4)); + std::list triangles; // width, height, depth diff --git a/Cubehole.h b/Cubehole.h index ae31052..c4710d1 100644 --- a/Cubehole.h +++ b/Cubehole.h @@ -11,6 +11,10 @@ class Cubehole public: Cubehole(): width(0), height(0), depth(0), x(0), y(0), z(0), innerwidth(0), innerdepth(0) { setColor(vmml::vec4f::ONE, vmml::vec4f::ONE, vmml::vec4f::ONE, vmml::vec4f::ONE); + front.setRotate(0); + right.setRotate(90); + back.setRotate(180); + left.setRotate(270); } Cubehole(float width0, float height0, float depth0, float x0, float y0, float z0, float innerwidth0, float innerdepth0, @@ -50,10 +54,6 @@ class Cubehole x = x0; y = y0; z = z0; - front.setPos(x, y, z+(depth/2-(depth-innerdepth)/4)); - right.setPos(x, y, z-(width/2-(width-innerwidth)/4)); - back.setPos(x, y, z+(depth/2-(depth-innerdepth)/4)); - left.setPos(x, y, z-(width/2-(width-innerwidth)/4)); } void setColor(const vmml::vec4f &cf, const vmml::vec4f &cr, const vmml::vec4f &cb, const vmml::vec4f &cl) { front.setColor(cf); diff --git a/DisplayClass.cpp b/DisplayClass.cpp index 647cbf6..0a833c9 100644 --- a/DisplayClass.cpp +++ b/DisplayClass.cpp @@ -48,7 +48,7 @@ DisplayClass::DisplayClass() : angle(0) { std::list t5 = cubehole5.getTriangles(); triangles.splice(triangles.end(), t5);*/ - Temparray temp(20, 2, 2, 2); + Temparray temp(20, 5, 5, 5); std::list triangles=temp.getTriangles(); tree = new BSPTree(triangles); diff --git a/Temparray.cpp b/Temparray.cpp index bb3596a..af46f8d 100644 --- a/Temparray.cpp +++ b/Temparray.cpp @@ -1,25 +1,35 @@ #include "Temparray.h" Temparray::Temparray(float initialtemp, int x0, int y0, int z0){ - float *temperature = new float[x0*y0*z0*6*4 + y0*z0*6*4 + z0*6*4 + 6*4 + 4]; - Cubehole *cubearray = new Cubehole[x0*y0*z0*6 + y0*z0*64 + z0*6 + 6]; + temparray = new float[x0*y0*z0*6*4]; + cubearray = new Cubehole[x0*y0*z0*6]; + + sx = x0; + sy = y0; + sz = z0; + tempInit(initialtemp, x0, y0, z0); - size[0] = x0; size[1] = y0; size[2] = z0; // static const float pos[5] = {-2.0, -1.0, 0.0, 1.0, 2.0}; - float x1, y1, z1; for(int i = 0; i < x0; ++i) { for(int j = 0; j < y0; ++j) { for(int k = 0; k < z0; ++k) { for(int l = 0; l < 6; ++l) { - cubearray[i*y0*z0*6 + j*z0*6 + k*6 + l].setSize((6-l)/6, (6-l)/6, (6-l)/6, (5-l)/6, (5-l)/6); - if(x0 % 2 == 0) x1 = -(x0/2)+i+0.5; - else if(x0 % 2 == 1) x1 = -(x0-1)/2+i; - if(y0 % 2 == 0) y1 = -(y0/2)+i+0.5; - else if(y0 % 2 == 1) y1 = -(y0-1)/2+i; - if(z0 % 2 == 0) z1 = -(z0/2)+i+0.5; - else if(z0 % 2 == 1) z1 = -(z0-1)/2+i; - cubearray[i*y0*z0*6 + j*z0*6 + k*6 + l].setPos(x1, y1, z1); + cubehole(i, j, k, l).setSize((6-l)/6*0.9, 3, (6-l)/6*0.9, (5-l)/6*0.9, (5-l)/6*0.9); + + float x, y, z; + if(x0 % 2 == 0) x = -(x0/2)+i+0.5; + else if(x0 % 2 == 1) x = -(x0-1)/2+i; + if(y0 % 2 == 0) y = -(y0/2)+j+0.5; + else if(y0 % 2 == 1) y = -(y0-1)/2+j; + if(z0 % 2 == 0) z = -(z0/2)+k+0.5; + else if(z0 % 2 == 1) z = -(z0-1)/2+k; + cubehole(i, j, k, l).setPos(x, y, z); + + cubehole(i, j, k, l).setColor(vmml::vec4f(1.0, 0.5, 1.0, 1.0), + vmml::vec4f(0.5, 0.5, 1.0, 1.0), + vmml::vec4f(1.0, 0.5, 0.0, 1.0), + vmml::vec4f(0.0, 0.5, 0.0, 1.0)); } } } @@ -29,15 +39,16 @@ Temparray::Temparray(float initialtemp, int x0, int y0, int z0){ std::list Temparray::getTriangles(){ std::list triangles; - for(int i = 0; i < size[0]; ++i) { - for(int j = 0; j < size[1]; ++j) { - for(int k = 0; k < size[2]; ++k) { + for(int i = 0; i < sx; ++i) { + for(int j = 0; j < sy; ++j) { + for(int k = 0; k < sz; ++k) { for(int l = 0; l < 6; ++l) { - std::list t = cubearray[i*size[1]*size[2]*6 + j*size[2]*6 + k*6 + l].getTriangles(); + std::list t = cubehole(i, j, k, l).getTriangles(); triangles.splice(triangles.end(), t); } } } } + return triangles; } diff --git a/Temparray.h b/Temparray.h index e15ea22..1274cfb 100644 --- a/Temparray.h +++ b/Temparray.h @@ -10,12 +10,11 @@ class Temparray public: Temparray(float initialtemp, int x0, int y0, int z0); ~Temparray(){ - delete[] temperature; - delete[] cubearray; - } + } void setTemp(float temp, int x, int y, int z, int line, int pos){ - temperature[x*size[1]*size[2]*6*4 + y*size[2]*6*4 + z*6*4 + line*4 + pos] = temp; + temperature(x, y, z, line, pos) = temp; + calcAverage(); } void deactivateCube(int x, int y, int z){ @@ -26,16 +25,23 @@ class Temparray } } std::list getTriangles(); - void calcTemp(); private: - float *temperature; + float *temparray; Cubehole *cubearray; - int size[3]; + int sx, sy, sz; float averagetemp; - void setColor(int x, int y, int z, int line){ + float& temperature(int x, int y, int z, int line, int pos) { + return temparray[x*sy*sz*6*4 + y*sz*6*4 + z*6*4 + line*4 + pos]; } + + Cubehole& cubehole(int x, int y, int z, int line) { + return cubearray[x*sy*sz*6 + y*sz*6 + z*6 + line]; + } + +// void setColor(int x, int y, int z, int line){ +// } void tempInit(float temp0, int x0, int y0, int z0){ for(int i=0; i