diff options
author | Constantin Riß <constantin.riss@dre.de> | 2009-12-03 22:15:45 +0100 |
---|---|---|
committer | Constantin Riß <constantin.riss@dre.de> | 2009-12-03 22:15:45 +0100 |
commit | bfa11fa56f513f68cfd9ec1da1443c5cf624c4dc (patch) | |
tree | 7e1e8963f255df7d92a0c4389ae98e006714ddb5 | |
parent | 9581542002a57f72afcbaebfe1ae6fc3b4021400 (diff) | |
download | c3d-bfa11fa56f513f68cfd9ec1da1443c5cf624c4dc.tar c3d-bfa11fa56f513f68cfd9ec1da1443c5cf624c4dc.zip |
Dateien zu adden wurde nachgeholt.
-rw-r--r-- | Cubehole.cpp | 206 | ||||
-rw-r--r-- | Cubehole.h | 53 | ||||
-rw-r--r-- | Trapezocube.cpp | 78 | ||||
-rw-r--r-- | Trapezocube.h | 55 |
4 files changed, 392 insertions, 0 deletions
diff --git a/Cubehole.cpp b/Cubehole.cpp new file mode 100644 index 0000000..e755e45 --- /dev/null +++ b/Cubehole.cpp @@ -0,0 +1,206 @@ +#include "Cubehole.h" +#include "gl.h" + +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); + } + + 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; +} diff --git a/Cubehole.h b/Cubehole.h new file mode 100644 index 0000000..3f8f689 --- /dev/null +++ b/Cubehole.h @@ -0,0 +1,53 @@ +#ifndef _CUBEHOLE_H_ +#define _CUBEHOLE_H_ + +#include "Triangle.h" +#include "Matrix.h" + +#include <list> + +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); + } + 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) + { + innerwidth = iw; + innerdepth = id; + } + 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 x, y, z, width, height, depth, innerwidth, innerdepth; + +}; + +#endif /*_CUBEHOLE_H_*/ diff --git a/Trapezocube.cpp b/Trapezocube.cpp new file mode 100644 index 0000000..e9877de --- /dev/null +++ b/Trapezocube.cpp @@ -0,0 +1,78 @@ +#include "Trapezocube.h" + +std::list<Triangle> Trapezocube::getTriangles(const Matrix &modelview) +{ + std::list<Triangle> triangles; + // width, height, depth + //glRotatef(rotate, 0.0, 1.0, 0.0); + // 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), + Vertex(x+widthfront/2, y+height/2, z+depth/2), + Vertex(x-widthfront/2, y-height/2, z+depth/2), c)); + + 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)); + + // 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)); + + 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)); + + // 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-widthfront /2, y-height/2, z+depth/2), + Vertex(x-widthback /2, y+height/2, z-depth/2), c)); + + 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)); + + // 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)); + + 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)); + + // 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)); + + 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)); + + // Bottom 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)); + + 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)); + + for(std::list<Triangle>::iterator t = triangles.begin(); t != triangles.end(); ++t) { + t->transform(modelview); + } + + return triangles; +} + diff --git a/Trapezocube.h b/Trapezocube.h new file mode 100644 index 0000000..b2cdd9a --- /dev/null +++ b/Trapezocube.h @@ -0,0 +1,55 @@ +#ifndef _TRAPEZOCUBE_H_ +#define _TRAPEZOCUBE_H_ + +#include "gl.h" +#include "Color.h" +#include "Triangle.h" +#include <list> + +class Trapezocube +{ + public: + Trapezocube(): widthfront(0), widthback(0), height(0), depth(0), x(0), y(0), z(0) {} + Trapezocube(float widthfront, float widthback, float height, float depth): x(0), y(0), z(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) { + setSize(widthfront, widthback, height, depth); + setPos(x, y, z); + setRotate(rotate); + } + float getHeight() {return height;} + float getWidthFront() {return widthfront;} + float getWidthBack() {return widthback;} + float getDepth() {return depth;} + float getPosX() {return x;} + float getPosY() {return y;} + float getPosZ() {return z;} + float getRotate() {return rotate;} + void setSize(float wf, float wb, float h, float d) + { + widthfront = wf; + widthback = wb; + height = h; + depth = d; + } + void setPos(float x, float y, float z) + { + this->x = x; + this->y = y; + this->z = z; + } + void setRotate(float r) {rotate = r;} + void setColor(Color col) {color = col;} + std::list<Triangle> getTriangles(const Matrix &modelview); + + private: + float x, y, z, widthfront, widthback, height, depth, rotate; + Color color; +}; + +#endif /*_TRAPEZOCUBE_H_ */ |