summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cubehole.cpp175
-rw-r--r--Cubehole.h67
-rw-r--r--DisplayClass.cpp32
-rw-r--r--Trapezocube.cpp41
-rw-r--r--Trapezocube.h13
5 files changed, 76 insertions, 252 deletions
diff --git a/Cubehole.cpp b/Cubehole.cpp
index e755e45..ed54e83 100644
--- a/Cubehole.cpp
+++ b/Cubehole.cpp
@@ -1,162 +1,19 @@
#include "Cubehole.h"
#include "gl.h"
-std::list<Triangle> Cubehole::getTriangles(const Matrix &modelview)
+std::list<Triangle> Cubehole::getTriangles(/*const Matrix &modelview*/)
{
std::list<Triangle> 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<Triangle>::iterator t = triangles.begin(); t != triangles.end(); ++t) {
- t->transform(modelview);
- }
+ std::list<Triangle> tf = front.getTriangles();
+ triangles.splice(triangles.end(), tf);
+ std::list<Triangle> tr = right.getTriangles();
+ triangles.splice(triangles.end(), tr);
+ std::list<Triangle> tb = back.getTriangles();
+ triangles.splice(triangles.end(), tb);
+ std::list<Triangle> tl = left.getTriangles();
+ triangles.splice(triangles.end(), tl);
return triangles;
}
@@ -190,17 +47,3 @@ 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;
-}
diff --git a/Cubehole.h b/Cubehole.h
index 3f8f689..83ef382 100644
--- a/Cubehole.h
+++ b/Cubehole.h
@@ -1,6 +1,7 @@
#ifndef _CUBEHOLE_H_
#define _CUBEHOLE_H_
+#include "Trapezocube.h"
#include "Triangle.h"
#include "Matrix.h"
@@ -9,44 +10,60 @@
class Cubehole
{
public:
- Cubehole(): width(0), height(0), depth(0), x(0), y(0), z(0), innerwidth(0), innerdepth(0) {}
- Cubehole(float width, float height, float depth): x(0), y(0), z(0), innerwidth(0), innerdepth(0){
- setSize(width, height, depth);
- }
- Cubehole(float width, float height, float depth, float x, float y, float z): innerwidth(0), innerdepth(0) {
- setSize(width, height, depth);
- setPos(x, y, z);
- }
- Cubehole(float width, float height, float depth, float x, float y, float z, float innerwidth, float innerdepth) {
- setSize(width, height, depth);
- setPos(x, y, z);
- setInnerSize(innerwidth, innerdepth);
+ Cubehole(): width(0), height(0), depth(0), x(0), y(0), z(0), innerwidth(0), innerdepth(0),
+ colorfront(0), colorback(0), colorleft(0), colorright(0) {
}
+ Cubehole(float width0, float height0, float depth0, float x0, float y0, float z0,
+ float innerwidth0, float innerdepth0,
+ Color colorfront0, Color colorright0, Color colorback0, Color colorleft0) {
+ setSize(width0, height0, depth0, innerwidth0, innerdepth0);
+ setPos(x0, y0, z0);
+ setColor(colorfront0, colorright0, colorback0, colorleft0);
+ front.setRotate(0);
+ right.setRotate(90);
+ back.setRotate(180);
+ left.setRotate(270);
+ }
float getHeight();
float getWidth();
float getDepth();
float getPosX();
float getPosY();
float getPosZ();
- float getInnerWidth()
- {
- return innerwidth;
- }
- float getInnerDepth()
- {
- return innerdepth;
- }
- void setInnerSize(float iw, float id)
- {
+ float getInnerWidth() {return innerwidth;}
+ float getInnerDepth() {return innerdepth;}
+ void setSize(float w, float h, float d, float iw, float id){
+ width = w;
+ height = h;
+ depth = d;
innerwidth = iw;
innerdepth = id;
+ front.setSize(width, innerwidth, height, (depth-innerdepth)/2);
+ right.setSize(width, innerdepth, height, (width-innerwidth)/2);
+ back.setSize(width, innerwidth, height, (depth-innerdepth)/2);
+ left.setSize(width, innerdepth, height, (width-innerwidth)/2);
+ }
+ void setPos(float x0, float y0, float z0) {
+ x = x0;
+ y = y0;
+ z = z0;
+ front.setPos(x, y, depth-(depth-innerdepth)/2);
+ right.setPos(x, y, width-(width-innerwidth)/2);
+ back.setPos(x, y, depth-(depth-innerdepth)/2);
+ left.setPos(x, y, width-(width-innerwidth)/2);
+ }
+ void setColor(Color cf, Color cr, Color cb, Color cl){
+ front.setColor(cf);
+ right.setColor(cr);
+ back.setColor(cb);
+ left.setColor(cl);
}
- void setSize(float w, float h, float d);
- void setPos(float x, float y, float z);
- std::list<Triangle> getTriangles(const Matrix &modelview);
+ std::list<Triangle> getTriangles(/*const Matrix &modelview*/);
private:
float x, y, z, width, height, depth, innerwidth, innerdepth;
+ Color colorfront, colorleft, colorback, colorright;
+ Trapezocube front, right, back, left;
};
diff --git a/DisplayClass.cpp b/DisplayClass.cpp
index cefa6ae..b0a4a8d 100644
--- a/DisplayClass.cpp
+++ b/DisplayClass.cpp
@@ -21,15 +21,7 @@ DisplayClass::DisplayClass() {
void DisplayClass::renderScene(unsigned long delta)
{
- //Cubehole cubeing(3.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.5);
- Trapezocube cubeing1(11.0, 10.0, 10.0, 0.5, 0.0, 0.0, 1.75, 0);
- Trapezocube cubeing2(10.0, 9.0, 9.0, 0.5, 0.0, 0.0, 2.25, 90);
- Trapezocube cubeing3(9.0, 8.0, 8.0, 0.5, 0.0, 0.0, 2.75, 180);
- Trapezocube cubeing4(8.0, 7.0, 7.0, 0.5, 0.0, 0.0, 3.25, 270);
- Trapezocube cubeing5(7.0, 6.0, 6.0, 0.5, 0.0, 0.0, 3.75, 0);
- Trapezocube cubeing6(6.0, 5.0, 5.0, 0.5, 0.0, 0.0, 4.25, 90);
- Trapezocube cubeing7(5.0, 4.0, 4.0, 0.5, 0.0, 0.0, 4.75, 180);
- Trapezocube cubeing8(4.0, 3.0, 3.0, 0.5, 0.0, 0.0, 5.25, 270);
+ Cubehole cubeing(3.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.5, Color(1.0, 0.0, 0.0), Color(0.0, 1.0, 0.0), Color(0.0, 0.0, 1.0), Color(1.0, 0.85, 0.06));
static float angle = 0.0;
angle += delta*0.025;
if(angle >= 360)
@@ -43,7 +35,7 @@ void DisplayClass::renderScene(unsigned long delta)
std::list<Triangle> triangles;
glLoadIdentity(); // Clean up matrix
- glTranslatef(0.0, 0.0, -30.0); // Then set up transformation
+ glTranslatef(0.0, 0.0, -10.0); // Then set up transformation
glRotatef(angle, 0.0, 1.0, 0.0);
glRotatef(angle*2, 1.0, 0.0, 0.0);
glRotatef(angle*3, 0.0, 0.0, 1.0);
@@ -59,25 +51,11 @@ void DisplayClass::renderScene(unsigned long delta)
}
}
}*/
- std::list<Triangle> ct1 = cubeing1.getTriangles();
- triangles.splice(triangles.end(), ct1);
- std::list<Triangle> ct2 = cubeing2.getTriangles();
- triangles.splice(triangles.end(), ct2);
- std::list<Triangle> ct3 = cubeing3.getTriangles();
- triangles.splice(triangles.end(), ct3);
- std::list<Triangle> ct4 = cubeing4.getTriangles();
- triangles.splice(triangles.end(), ct4);
- std::list<Triangle> ct5 = cubeing5.getTriangles();
- triangles.splice(triangles.end(), ct5);
- std::list<Triangle> ct6 = cubeing6.getTriangles();
- triangles.splice(triangles.end(), ct6);
- std::list<Triangle> ct7 = cubeing7.getTriangles();
- triangles.splice(triangles.end(), ct7);
- std::list<Triangle> ct8 = cubeing8.getTriangles();
- triangles.splice(triangles.end(), ct8);
-
//glLoadIdentity();
+ std::list<Triangle> ct = cubeing.getTriangles();
+ triangles.splice(triangles.end(), ct);
+
glBegin(GL_TRIANGLES);
for(std::list<Triangle>::reverse_iterator t = triangles.rbegin(); t != triangles.rend(); ++t) {
t->render();
diff --git a/Trapezocube.cpp b/Trapezocube.cpp
index 24bcfc3..20aa1c4 100644
--- a/Trapezocube.cpp
+++ b/Trapezocube.cpp
@@ -3,76 +3,67 @@
std::list<Triangle> Trapezocube::getTriangles(/*const Matrix &modelview*/)
{
std::list<Triangle> triangles;
- // width, height, depth
glPushMatrix();
glLoadIdentity();
glRotatef(rotate, 0.0, 1.0, 0.0);
Matrix rotation;
glPopMatrix();
- // Front face
- Color c(0.0, 0.0, 1.0, 0.5);
- triangles.push_back(Triangle(Vertex(x-widthfront/2, y+height/2, z+depth/2),
+ // Front face
+ triangles.push_back(Triangle(Vertex(x-widthfront/2, y+height/2, z+depth/2),
Vertex(x-widthfront/2, y-height/2, z+depth/2),
- Vertex(x+widthfront/2, y+height/2, z+depth/2), c));
+ Vertex(x+widthfront/2, y+height/2, z+depth/2), color));
triangles.push_back(Triangle(Vertex(x-widthfront/2, y-height/2, z+depth/2),
Vertex(x+widthfront/2, y-height/2, z+depth/2),
- Vertex(x+widthfront/2, y+height/2, z+depth/2), c));
+ Vertex(x+widthfront/2, y+height/2, z+depth/2), color));
// Back face
- c = Color(1.0, 1.0, 0.0, 0.5);
-
triangles.push_back(Triangle(Vertex(x-widthback/2, y+height/2, z-depth/2),
Vertex(x+widthback/2, y+height/2, z-depth/2),
- Vertex(x-widthback/2, y-height/2, z-depth/2), c));
+ Vertex(x-widthback/2, y-height/2, z-depth/2), color));
triangles.push_back(Triangle(Vertex(x-widthback/2, y-height/2, z-depth/2),
Vertex(x+widthback/2, y+height/2, z-depth/2),
- Vertex(x+widthback/2, y-height/2, z-depth/2), c));
+ Vertex(x+widthback/2, y-height/2, z-depth/2), color));
// Left face
- c = Color(0.0, 1.0, 0.0, 0.5);
-
triangles.push_back(Triangle(Vertex(x-widthfront/2, y+height/2, z+depth/2),
- Vertex(x-widthback /2, y+height/2, z-depth/2),
- Vertex(x-widthfront/2, y-height/2, z+depth/2), c));
+ Vertex(x-widthback /2, // width, height, depth
+ y+height/2, z-depth/2),
+ Vertex(x-widthfront/2, y-height/2, z+depth/2), color));
triangles.push_back(Triangle(Vertex(x-widthback /2, y-height/2, z-depth/2),
Vertex(x-widthfront/2, y-height/2, z+depth/2),
- Vertex(x-widthback /2, y+height/2, z-depth/2), c));
+ Vertex(x-widthback /2, y+height/2, z-depth/2), color));
// Right face
-
triangles.push_back(Triangle(Vertex(x+widthfront/2, y+height/2, z+depth/2),
Vertex(x+widthfront/2, y-height/2, z+depth/2),
- Vertex(x+widthback /2, y+height/2, z-depth/2), c));
+ Vertex(x+widthback /2, y+height/2, z-depth/2), color));
triangles.push_back(Triangle(Vertex(x+widthback /2, y-height/2, z-depth/2),
Vertex(x+widthback /2, y+height/2, z-depth/2),
- Vertex(x+widthfront/2, y-height/2, z+depth/2), c));
+ Vertex(x+widthfront/2, y-height/2, z+depth/2), color));
// Top face
- c = Color(1.0, 0.0, 0.0, 0.5);
-
triangles.push_back(Triangle(Vertex(x-widthfront/2, y+height/2, z+depth/2),
Vertex(x+widthfront/2, y+height/2, z+depth/2),
- Vertex(x-widthback /2, y+height/2, z-depth/2), c));
+ Vertex(x-widthback /2, y+height/2, z-depth/2), color));
triangles.push_back(Triangle(Vertex(x+widthfront/2, y+height/2, z+depth/2),
Vertex(x+widthback /2, y+height/2, z-depth/2),
- Vertex(x-widthback /2, y+height/2, z-depth/2), c));
+ Vertex(x-widthback /2, y+height/2, z-depth/2), color));
// Bottom face
-
triangles.push_back(Triangle(Vertex(x-widthfront/2, y-height/2, z+depth/2),
Vertex(x-widthback /2, y-height/2, z-depth/2),
- Vertex(x+widthfront/2, y-height/2, z+depth/2), c));
+ Vertex(x+widthfront/2, y-height/2, z+depth/2), color));
triangles.push_back(Triangle(Vertex(x+widthfront/2, y-height/2, z+depth/2),
Vertex(x-widthback /2, y-height/2, z-depth/2),
- Vertex(x+widthback /2, y-height/2, z-depth/2), c));
+ Vertex(x+widthback /2, y-height/2, z-depth/2), color));
for(std::list<Triangle>::iterator t = triangles.begin(); t != triangles.end(); ++t) {
t->transform(rotation);
diff --git a/Trapezocube.h b/Trapezocube.h
index 3d64eaa..533cbf8 100644
--- a/Trapezocube.h
+++ b/Trapezocube.h
@@ -9,18 +9,12 @@
class Trapezocube
{
public:
- Trapezocube(): widthfront(0), widthback(0), height(0), depth(0), x(0), y(0), z(0), rotate(0) {}
- Trapezocube(float widthfront, float widthback, float height, float depth): x(0), y(0), z(0), rotate(0){
- setSize(widthfront, widthback, height, depth);
- }
- Trapezocube(float widthfront, float widthback, float height, float depth, float x, float y, float z): rotate(0) {
- setSize(widthfront, widthback, height, depth);
- setPos(x, y, z);
- }
- Trapezocube(float widthfront, float widthback, float height, float depth, float x, float y, float z, float rotate) {
+ Trapezocube(): widthfront(0), widthback(0), height(0), depth(0), x(0), y(0), z(0), rotate(0), color(0) {}
+ Trapezocube(float widthfront, float widthback, float height, float depth, float x, float y, float z, float rotate, Color col) {
setSize(widthfront, widthback, height, depth);
setPos(x, y, z);
setRotate(rotate);
+ setColor(col);
}
float getHeight() {return height;}
float getWidthFront() {return widthfront;}
@@ -30,6 +24,7 @@ class Trapezocube
float getPosY() {return y;}
float getPosZ() {return z;}
float getRotate() {return rotate;}
+ Color getColor() {return color;}
void setSize(float wf, float wb, float h, float d)
{
widthfront = wf;