diff options
-rw-r--r-- | Cuboid.cpp | 20 | ||||
-rw-r--r-- | Cuboid.h | 9 | ||||
-rw-r--r-- | DisplayClass.cpp | 47 |
3 files changed, 55 insertions, 21 deletions
@@ -5,10 +5,14 @@ //#include <stdlib.h> //#include <time.h> +Cuboid::Cuboid(float width, float height, float depth) { + setSize(width, height, depth); + setPos(0, 0, 0); +} -Cuboid::Cuboid(float height, float width, float depth, float x, float y, float z) +Cuboid::Cuboid(float width, float height, float depth, float x, float y, float z) { - setSize(height, width, depth); + setSize(width, height, depth); setPos(x, y, z); } @@ -42,10 +46,10 @@ float Cuboid::getPosZ() return z; } -void Cuboid::setSize(float h, float w, float d) +void Cuboid::setSize(float w, float h, float d) { - height = h; width = w; + height = h; depth = d; } @@ -62,7 +66,7 @@ std::list<Triangle> Cuboid::getTriangles(const Matrix &modelview) //srand(time(NULL)); // width, height, depth // Front face - Color c(0.0, 0.0, 1.0); + Color c(0.0, 0.0, 1.0, 0.5); triangles.push_back(Triangle(Vertex(x , y , z), Vertex(x+width, y , z), @@ -73,7 +77,7 @@ std::list<Triangle> Cuboid::getTriangles(const Matrix &modelview) Vertex(x+width, y-height, z), c)); // Back face - c = Color(1.0, 1.0, 0.0); + 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), @@ -84,7 +88,7 @@ std::list<Triangle> Cuboid::getTriangles(const Matrix &modelview) Vertex(x+width, y-height, z-depth), c)); // Left face - c = Color(0.0, 1.0, 0.0); + c = Color(0.0, 1.0, 0.0, 0.5); triangles.push_back(Triangle(Vertex(x, y , z ), Vertex(x, y-height, z ), @@ -105,7 +109,7 @@ std::list<Triangle> Cuboid::getTriangles(const Matrix &modelview) Vertex(x+width, y-height, z ), c)); // Top face - c = Color(1.0, 0.0, 0.0); + c = Color(1.0, 0.0, 0.0, 0.5); triangles.push_back(Triangle(Vertex(x , y, z ), Vertex(x+width, y, z ), @@ -9,20 +9,21 @@ class Cuboid
{
- public:
- Cuboid(float height, float width, float depth, float x, float y, float z);
+ public: + Cuboid(float width, float height, float depth);
+ Cuboid(float width, float height, float depth, float x, float y, float z);
float getHeight();
float getWidth();
float getDepth();
float getPosX();
float getPosY();
float getPosZ();
- void setSize(float h, float w, float d);
+ void setSize(float w, float h, float d);
void setPos(float x, float y, float z);
std::list<Triangle> getTriangles(const Matrix &modelview);
private: - float height, width, depth;
+ float width, height, depth;
float x, y, z;
};
#endif /*_CUBOID_H_*/ diff --git a/DisplayClass.cpp b/DisplayClass.cpp index 836988d..9cae95c 100644 --- a/DisplayClass.cpp +++ b/DisplayClass.cpp @@ -6,12 +6,34 @@ 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);
+{ + //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.5, -1.5, -0.5, 0.5, 1.5}; + static const float zs[5] = {-1.5, -0.5, 0.5, 1.5, 2.5}; + + 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], 1.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;
+ angle += delta*0.043;
if(angle >= 360)
angle -= 360;
@@ -28,17 +50,24 @@ void DisplayClass::renderScene(unsigned long delta) //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, 0.0, 0.0, 1.0); m.store(); // Save current transformation + + for(int i = 0; i < 5; ++i) { + for(int j = 0; j < 5; ++j) { + std::list<Triangle> ct = cubes[i][j].getTriangles(m);
+ triangles.splice(triangles.end(), ct); + } + } - std::list<Triangle> t1 = cube1.getTriangles(m);
+ /*std::list<Triangle> t1 = cube1.getTriangles(m);
triangles.splice(triangles.end(), t1);
glRotatef(angle*10, 0.0, 0.0, 1.0); m.store(); - std::list<Triangle> t2 = cube2.getTriangles(m); - triangles.splice(triangles.end(), t2);
+ t1 = cube2.getTriangles(m); + triangles.splice(triangles.end(), t1);*/
//std::sort(triangles.begin(), triangles.end(), Sorter(p)); |