pmc/cube.cc
changeset 45 7197576fedcf
parent 43 cf8c1b5127b2
child 46 4b9e1ac40246
equal deleted inserted replaced
44:bb6586b1c547 45:7197576fedcf
     4  */
     4  */
     5 
     5 
     6 #include <cube.h>
     6 #include <cube.h>
     7 #include <cstdio>
     7 #include <cstdio>
     8 
     8 
       
     9 using namespace algebra;
       
    10 
     9 Cube::Cube (Surface * s)
    11 Cube::Cube (Surface * s)
    10 {
    12 {
       
    13     surface = s;
       
    14     name = "Cube";
       
    15     height = 25;
       
    16 
    11     P[0] = new Vector (0, 0);
    17     P[0] = new Vector (0, 0);
    12     P[1] = new Vector (100, 0);
    18     P[1] = new Vector (100, 0);
    13     P[2] = new Vector (100, 100);
    19     P[2] = new Vector (100, 100);
    14     P[3] = new Vector (0, 100);
    20     P[3] = new Vector (0, 100);
    15 
    21 
    16     P[4] = new Vector (25, 25);
    22     P[4] = new Vector (25, 25);
    17     P[5] = new Vector (125, 25);
    23     P[5] = new Vector (125, 25);
    18     P[6] = new Vector (125, 125);
    24     P[6] = new Vector (125, 125);
    19     P[7] = new Vector (25, 125);
    25     P[7] = new Vector (25, 125);
    20 
       
    21     surface = s;
       
    22     height = 25;
       
    23 }
    26 }
    24 
    27 
    25 Cube::Cube (Surface * s, Vector& p1, Vector& p2, Vector& p3, Vector& p4, int h)
    28 Cube::Cube (Surface * s, Vector & p1, Vector & p2, Vector & p3, Vector & p4, int h)
    26 {
    29 {
       
    30     surface = s;
       
    31     name = "Cube";
    27     height = h;
    32     height = h;
    28     surface = s;
    33 
    29     Vector location(h/2, h/2);
    34     Vector location (h / 4, h / 4);
    30 
    35 
    31     P[0] = new Vector (p1);
    36     P[0] = new Vector (p1);
    32     P[1] = new Vector (p2);
    37     P[1] = new Vector (p2);
    33     P[2] = new Vector (p3);
    38     P[2] = new Vector (p3);
    34     P[3] = new Vector (p4);
    39     P[3] = new Vector (p4);
    35 
    40 
    36     for (int i = 0; i < 4; i++) {
    41     for (int i = 0; i < 4; i++) {
       
    42         P[4 + i] = new Vector (*P[i]);
       
    43         *P[4 + i] = *P[i] + location;
       
    44     }
       
    45 }
       
    46 
       
    47 Cube::Cube (Surface * s, Vector p[4], int h)
       
    48 {
       
    49     surface = s;
       
    50     name = "Cube";
       
    51     height = h;
       
    52 
       
    53     Vector location (h / 4, h / 4);
       
    54 
       
    55     for (int i = 0; i < 4; i++) {
       
    56         P[i] = new Vector (p[i]);
    37         P[4 + i] = new Vector (*P[i]);
    57         P[4 + i] = new Vector (*P[i]);
    38         *P[4 + i] = *P[i] + location;
    58         *P[4 + i] = *P[i] + location;
    39     }
    59     }
    40 }
    60 }
    41 
    61 
    56     }
    76     }
    57 }
    77 }
    58 
    78 
    59 void Cube::show ()
    79 void Cube::show ()
    60 {
    80 {
    61 	/* Implement some Sanity Checks */
    81     /*
       
    82      * Implement some Sanity Checks
       
    83      */
    62     int height = surface->getHeight ();
    84     int height = surface->getHeight ();
    63 
    85 
    64     surface->drawLine (P[0]->X (), P[0]->Y (), P[1]->X (), P[1]->Y ());
    86     surface->drawLine (P[0]->X (), P[0]->Y (), P[1]->X (), P[1]->Y ());
    65     surface->drawLine (P[3]->X (), P[3]->Y (), P[2]->X (), P[2]->Y ());
    87     surface->drawLine (P[3]->X (), P[3]->Y (), P[2]->X (), P[2]->Y ());
    66     surface->drawLine (P[2]->X (), P[2]->Y (), P[1]->X (), P[1]->Y ());
    88     surface->drawLine (P[2]->X (), P[2]->Y (), P[1]->X (), P[1]->Y ());