pmc/cube.cc
changeset 42 83b8151b966d
parent 36 f52a9deddfc0
child 43 cf8c1b5127b2
--- a/pmc/cube.cc
+++ b/pmc/cube.cc
@@ -4,30 +4,48 @@
  */
 
 #include <cube.h>
-#include "../sdl.cc"
+#include <cstdio>
+
+Cube::Cube (Surface * s)
+{
+    P[0] = new Vector (0, 0);
+    P[1] = new Vector (100, 0);
+    P[2] = new Vector (100, 100);
+    P[3] = new Vector (0, 100);
 
-extern SDL_Surface *screen;
-extern unsigned long color;
+    P[4] = new Vector (25, 25);
+    P[5] = new Vector (125, 25);
+    P[6] = new Vector (125, 125);
+    P[7] = new Vector (25, 125);
 
-Cube::Cube (Vector p1, Vector p2, Vector p3, Vector p4, int h)
+    surface = s;
+    height = 25;
+}
+
+Cube::Cube (Surface * s, Vector p1, Vector p2, Vector p3, Vector p4, int h)
 {
+    height = h;
+    surface = s;
+
     P[0] = new Vector (p1);
     P[1] = new Vector (p2);
     P[2] = new Vector (p3);
     P[3] = new Vector (p4);
 
-    P[4] = new Vector (p1.X (), p1.Y (), p1.Z () + h);
-    P[5] = new Vector (p2.X (), p2.Y (), p2.Z () + h);
-    P[6] = new Vector (p3.X (), p3.Y (), p3.Z () + h);
-    P[7] = new Vector (p4.X (), p4.Y (), p4.Z () + h);
-
-    height = h;
+    for (int i = 0; i < 4; i++) {
+        P[4 + i] = new Vector (*P[i]);
+        *P[4 + i] = *P[i] + Vector (h / 2, h / 2);
+    }
 }
 
 Cube::~Cube ()
 {
-    for (int i = 0; i < 8; i++)
+    for (int i = 0; i < 6; i++) {
+#ifdef DEBUG
+        fprintf (stderr, "Removing P[%d]: ", i);
+#endif
         delete P[i];
+    }
 }
 
 void Cube::move (Vector location)
@@ -39,54 +57,22 @@
 
 void Cube::show ()
 {
-    P[0]->vector ();
-    std::cout << ", ";
-    P[1]->vector ();
-    std::cout << std::endl;
-    P[2]->vector ();
-    std::cout << ", ";
-    P[3]->vector ();
-    std::cout << std::endl;
+	/* Implement some Sanity Checks */
+    int height = surface->getHeight ();
 
-    P[4]->vector ();
-    std::cout << ", ";
-    P[5]->vector ();
-    std::cout << std::endl;
-    P[6]->vector ();
-    std::cout << ", ";
-    P[7]->vector ();
-    std::cout << std::endl;
-
-    drawLine (screen, P[0]->X (), P[0]->Y (), P[1]->X (), P[1]->Y (), color);
-    drawLine (screen, P[2]->X (), P[2]->Y (), P[3]->X (), P[3]->Y (), color);
-    drawLine (screen, P[0]->X (), P[0]->Y (), P[2]->X (), P[2]->Y (), color);
-    drawLine (screen, P[1]->X (), P[1]->Y (), P[3]->X (), P[3]->Y (), color);
+    surface->drawLine (P[0]->X (), P[0]->Y (), P[1]->X (), P[1]->Y ());
+    surface->drawLine (P[3]->X (), P[3]->Y (), P[2]->X (), P[2]->Y ());
+    surface->drawLine (P[2]->X (), P[2]->Y (), P[1]->X (), P[1]->Y ());
+    surface->drawLine (P[3]->X (), P[3]->Y (), P[0]->X (), P[0]->Y ());
 
-    drawLine (screen, (int)(height / 2.0) + P[4]->X (),
-              (int)(height / 2.0) + P[4]->Y (),
-              (int)(height / 2.0) + P[5]->X (), (int)(height / 2.0) + P[5]->Y (), color);
-
-    drawLine (screen, (int)(height / 2.0) + P[6]->X (),
-              (int)(height / 2.0) + P[6]->Y (),
-              (int)(height / 2.0) + P[7]->X (), (int)(height / 2.0) + P[7]->Y (), color);
-
-    drawLine (screen, (int)(height / 2.0) + P[4]->X (),
-              (int)(height / 2.0) + P[4]->Y (),
-              (int)(height / 2.0) + P[6]->X (), (int)(height / 2.0) + P[6]->Y (), color);
+    surface->drawLine (P[4]->X (), P[4]->Y (), P[5]->X (), P[5]->Y ());
+    surface->drawLine (P[7]->X (), P[7]->Y (), P[6]->X (), P[6]->Y ());
+    surface->drawLine (P[7]->X (), P[7]->Y (), P[4]->X (), P[4]->Y ());
+    surface->drawLine (P[6]->X (), P[6]->Y (), P[5]->X (), P[5]->Y ());
 
-    drawLine (screen, (int)(height / 2.0) + P[5]->X (),
-              (int)(height / 2.0) + P[5]->Y (),
-              (int)(height / 2.0) + P[7]->X (), (int)(height / 2.0) + P[7]->Y (), color);
-
-    drawLine (screen, P[0]->X (), P[0]->Y (),
-              (int)(height / 2.0) + P[4]->X (), (int)(height / 2.0) + P[4]->Y (), color);
+    surface->drawLine (P[0]->X (), P[0]->Y (), P[4]->X (), P[4]->Y ());
+    surface->drawLine (P[1]->X (), P[1]->Y (), P[5]->X (), P[5]->Y ());
 
-    drawLine (screen, P[2]->X (), P[2]->Y (),
-              (int)(height / 2.0) + P[6]->X (), (int)(height / 2.0) + P[6]->Y (), color);
-
-    drawLine (screen, P[1]->X (), P[1]->Y (),
-              (int)(height / 2.0) + P[5]->X (), (int)(height / 2.0) + P[5]->Y (), color);
-
-    drawLine (screen, P[3]->X (), P[3]->Y (),
-              (int)(height / 2.0) + P[7]->X (), (int)(height / 2.0) + P[7]->Y (), color);
+    surface->drawLine (P[2]->X (), P[2]->Y (), P[6]->X (), P[6]->Y ());
+    surface->drawLine (P[3]->X (), P[3]->Y (), P[7]->X (), P[7]->Y ());
 }