summaryrefslogtreecommitdiffstats
path: root/Cuboid.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Cuboid.cpp')
-rw-r--r--Cuboid.cpp133
1 files changed, 133 insertions, 0 deletions
diff --git a/Cuboid.cpp b/Cuboid.cpp
new file mode 100644
index 0000000..5557e39
--- /dev/null
+++ b/Cuboid.cpp
@@ -0,0 +1,133 @@
+#include "Cuboid.h"
+#include "gl.h"
+
+#include <iostream>
+//#include <stdlib.h>
+//#include <time.h>
+
+
+Cuboid::Cuboid(float height, float width, float depth, float x, float y, float z)
+{
+ setSize(height, width, 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 h, float w, float d)
+{
+ height = h;
+ width = w;
+ depth = d;
+}
+
+void Cuboid::setPos(float x, float y, float z)
+{
+ this->x = x;
+ this->y = y;
+ this->z = z;
+}
+
+std::list<Triangle> Cuboid::getTriangles(const Matrix &modelview)
+{
+ std::list<Triangle> triangles;
+ //srand(time(NULL));
+ // width, height, depth
+ // Front face
+ Color c(0.0, 0.0, 1.0);
+
+ 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);
+
+ 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);
+
+ 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);
+
+ 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<Triangle>::iterator t = triangles.begin(); t != triangles.end(); ++t) {
+ t->transform(modelview);
+ }
+
+ return triangles;
+}