#include "Cubehole.h" #include "gl.h" std::list Cubehole::getTriangles(const Matrix &modelview) { std::list triangles; // width, height, depth // Front face Color c(0.0, 0.0, 1.0, 0.5); 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/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-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/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-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/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/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/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-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+innerdepth/2), c)); triangles.push_back(Triangle(Vertex(x+width/2, y+height/2, z+depth/2), Vertex(x+width/2, y+height/2, z+innerdepth/2), Vertex(x-width/2, y+height/2, z+innerdepth/2), 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-innerdepth/2), c)); triangles.push_back(Triangle(Vertex(x+width/2, y+height/2, z-depth/2), Vertex(x+width/2, y+height/2, z-innerdepth/2), Vertex(x-width/2, y+height/2, z-innerdepth/2), c)); triangles.push_back(Triangle(Vertex(x- width/2, y+height/2, z+innerdepth/2), Vertex(x-innerwidth/2, y+height/2, z+innerdepth/2), Vertex(x-innerwidth/2, y+height/2, z-innerdepth/2), c)); triangles.push_back(Triangle(Vertex(x- width/2, y+height/2, z+innerdepth/2), Vertex(x-innerwidth/2, y+height/2, z-innerdepth/2), Vertex(x- width/2, y+height/2, z-innerdepth/2), c)); triangles.push_back(Triangle(Vertex(x+ width/2, y+height/2, z+innerdepth/2), Vertex(x+innerwidth/2, y+height/2, z+innerdepth/2), Vertex(x+innerwidth/2, y+height/2, z-innerdepth/2), c)); triangles.push_back(Triangle(Vertex(x+ width/2, y+height/2, z+innerdepth/2), Vertex(x+innerwidth/2, y+height/2, z-innerdepth/2), Vertex(x+ width/2, y+height/2, z-innerdepth/2), c)); // Bottom face 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+innerdepth/2), c)); triangles.push_back(Triangle(Vertex(x+width/2, y-height/2, z+depth/2), Vertex(x+width/2, y-height/2, z+innerdepth/2), Vertex(x-width/2, y-height/2, z+innerdepth/2), 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-innerdepth/2), c)); triangles.push_back(Triangle(Vertex(x+width/2, y-height/2, z-depth/2), Vertex(x+width/2, y-height/2, z-innerdepth/2), Vertex(x-width/2, y-height/2, z-innerdepth/2), c)); triangles.push_back(Triangle(Vertex(x- width/2, y-height/2, z+innerdepth/2), Vertex(x-innerwidth/2, y-height/2, z+innerdepth/2), Vertex(x-innerwidth/2, y-height/2, z-innerdepth/2), c)); triangles.push_back(Triangle(Vertex(x- width/2, y-height/2, z+innerdepth/2), Vertex(x-innerwidth/2, y-height/2, z-innerdepth/2), Vertex(x- width/2, y-height/2, z-innerdepth/2), c)); triangles.push_back(Triangle(Vertex(x+ width/2, y-height/2, z+innerdepth/2), Vertex(x+innerwidth/2, y-height/2, z+innerdepth/2), Vertex(x+innerwidth/2, y-height/2, z-innerdepth/2), c)); triangles.push_back(Triangle(Vertex(x+ width/2, y-height/2, z+innerdepth/2), Vertex(x+innerwidth/2, y-height/2, z-innerdepth/2), Vertex(x+ width/2, y-height/2, z-innerdepth/2), c)); // FrontInner face c = Color(1.0, 1.0, 1.0, 0.5); triangles.push_back(Triangle(Vertex(x-innerwidth/2, y+height/2, z+innerdepth/2), Vertex(x+innerwidth/2, y+height/2, z+innerdepth/2), Vertex(x-innerwidth/2, y-height/2, z+innerdepth/2), c)); triangles.push_back(Triangle(Vertex(x-innerwidth/2, y-height/2, z+innerdepth/2), Vertex(x+innerwidth/2, y+height/2, z+innerdepth/2), Vertex(x+innerwidth/2, y-height/2, z+innerdepth/2), c)); // BackInner face c = Color(1.0, 0.5, 0.0, 0.5); triangles.push_back(Triangle(Vertex(x-innerwidth/2, y+height/2, z-innerdepth/2), Vertex(x-innerwidth/2, y-height/2, z-innerdepth/2), Vertex(x+innerwidth/2, y+height/2, z-innerdepth/2), c)); triangles.push_back(Triangle(Vertex(x-innerwidth/2, y-height/2, z-innerdepth/2), Vertex(x+innerwidth/2, y+height/2, z-innerdepth/2), Vertex(x+innerwidth/2, y-height/2, z-innerdepth/2), c)); // LeftInner face c = Color(0.0, 1.0, 0.0, 0.5); triangles.push_back(Triangle(Vertex(x-innerwidth/2, y+height/2, z+innerdepth/2), Vertex(x-innerwidth/2, y-height/2, z+innerdepth/2), Vertex(x-innerwidth/2, y+height/2, z-innerdepth/2), c)); triangles.push_back(Triangle(Vertex(x-innerwidth/2, y-height/2, z-innerdepth/2), Vertex(x-innerwidth/2, y+height/2, z-innerdepth/2), Vertex(x-innerwidth/2, y-height/2, z+innerdepth/2), c)); // RightInner face triangles.push_back(Triangle(Vertex(x+innerwidth/2, y+height/2, z+innerdepth/2), Vertex(x+innerwidth/2, y-height/2, z+innerdepth/2), Vertex(x+innerwidth/2, y+height/2, z-innerdepth/2), c)); triangles.push_back(Triangle(Vertex(x+innerwidth/2, y-height/2, z-innerdepth/2), Vertex(x+innerwidth/2, y+height/2, z-innerdepth/2), Vertex(x+innerwidth/2, y-height/2, z+innerdepth/2), c)); for(std::list::iterator t = triangles.begin(); t != triangles.end(); ++t) { t->transform(modelview); } return triangles; } float Cubehole::getHeight() { return height; } float Cubehole::getWidth() { return width; } float Cubehole::getDepth() { return depth; } float Cubehole::getPosX() { return x; } float Cubehole::getPosY() { return y; } float Cubehole::getPosZ() { return z; } void Cubehole::setSize(float w, float h, float d) { width = w; height = h; depth = d; } void Cubehole::setPos(float x, float y, float z) { this->x = x; this->y = y; this->z = z; }