#include "Cuboid.h" #include "gl.h" #include //#include //#include Cuboid::Cuboid(float width, float height, float depth) { setSize(width, height, depth); setPos(0, 0, 0); } Cuboid::Cuboid(float width, float height, float depth, float x, float y, float z) { setSize(width, height, depth); setPos(x, y, z); } float Cuboid::getHeight() { return height; } float Cuboid::getWidth() { return width; } float Cuboid::getDepth() { return depth; } float Cuboid::getPosX() { return x; } float Cuboid::getPosY() { return y; } float Cuboid::getPosZ() { return z; } void Cuboid::setSize(float w, float h, float d) { width = w; height = h; depth = d; } void Cuboid::setPos(float x, float y, float z) { this->x = x; this->y = y; this->z = z; } std::list Cuboid::getTriangles(const Matrix &modelview) { std::list triangles; //srand(time(NULL)); // width, height, depth // 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 , y-height, z), Vertex(x+width, y , z), Vertex(x+width, y-height, z), 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 , y-height, z-depth), Vertex(x+width, y , z-depth), Vertex(x+width, y-height, z-depth), 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, y-height, z-depth), Vertex(x, y , z-depth), Vertex(x, y-height, z ), 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, y-height, z-depth), Vertex(x+width, y , z-depth), Vertex(x+width, y-height, z ), 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, y, z ), Vertex(x+width, y, z-depth), Vertex(x , y, z-depth), 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, y-height, z ), Vertex(x+width, y-height, z-depth), Vertex(x , y-height, z-depth), c)); for(std::list::iterator t = triangles.begin(); t != triangles.end(); ++t) { t->transform(modelview); } return triangles; }