pmc/cube.cc
changeset 4 236f8f747073
child 9 c3fecc82ade6
equal deleted inserted replaced
3:820ed7fb9314 4:236f8f747073
       
     1 /***
       
     2  *
       
     3  * $Id: cube.cc,v 1.1.1.1 2008-04-28 17:33:22 mbroeker Exp $
       
     4  * $Source: /development/cpp/pmc/cube.cc,v $
       
     5  *
       
     6  */
       
     7 
       
     8 #include <cube.h>
       
     9 #include "../sdl.cc"
       
    10 
       
    11 extern SDL_Surface *screen;
       
    12 extern unsigned long color;
       
    13 
       
    14 Cube::Cube (Vector p1, Vector p2, Vector p3, Vector p4, int h)
       
    15 {
       
    16     P[0] = new Vector (p1);
       
    17     P[1] = new Vector (p2);
       
    18     P[2] = new Vector (p3);
       
    19     P[3] = new Vector (p4);
       
    20 
       
    21     P[4] = new Vector (p1.X (), p1.Y (), p1.Z () + h);
       
    22     P[5] = new Vector (p2.X (), p2.Y (), p2.Z () + h);
       
    23     P[6] = new Vector (p3.X (), p3.Y (), p3.Z () + h);
       
    24     P[7] = new Vector (p4.X (), p4.Y (), p4.Z () + h);
       
    25 
       
    26     height = h;
       
    27 }
       
    28 
       
    29 Cube::~Cube ()
       
    30 {
       
    31     for (int i = 0; i < 8; i++)
       
    32         delete P[i];
       
    33 }
       
    34 
       
    35 void Cube::move (Vector location)
       
    36 {
       
    37     for (int i = 0; i < 8; i++) {
       
    38         P[i] = new Vector (*P[i] + location);
       
    39     }
       
    40 }
       
    41 
       
    42 void Cube::show ()
       
    43 {
       
    44     P[0]->vector ();
       
    45     std::cout << ", ";
       
    46     P[1]->vector ();
       
    47     std::cout << std::endl;
       
    48     P[2]->vector ();
       
    49     std::cout << ", ";
       
    50     P[3]->vector ();
       
    51     std::cout << std::endl;
       
    52 
       
    53     P[4]->vector ();
       
    54     std::cout << ", ";
       
    55     P[5]->vector ();
       
    56     std::cout << std::endl;
       
    57     P[6]->vector ();
       
    58     std::cout << ", ";
       
    59     P[7]->vector ();
       
    60     std::cout << std::endl;
       
    61 
       
    62     drawLine (screen, P[0]->X (), P[0]->Y (), P[1]->X (), P[1]->Y (), color);
       
    63     drawLine (screen, P[2]->X (), P[2]->Y (), P[3]->X (), P[3]->Y (), color);
       
    64     drawLine (screen, P[0]->X (), P[0]->Y (), P[2]->X (), P[2]->Y (), color);
       
    65     drawLine (screen, P[1]->X (), P[1]->Y (), P[3]->X (), P[3]->Y (), color);
       
    66 
       
    67     drawLine (screen, (int)(height / 2.0) + P[4]->X (),
       
    68               (int)(height / 2.0) + P[4]->Y (),
       
    69               (int)(height / 2.0) + P[5]->X (), (int)(height / 2.0) + P[5]->Y (), color);
       
    70 
       
    71     drawLine (screen, (int)(height / 2.0) + P[6]->X (),
       
    72               (int)(height / 2.0) + P[6]->Y (),
       
    73               (int)(height / 2.0) + P[7]->X (), (int)(height / 2.0) + P[7]->Y (), color);
       
    74 
       
    75     drawLine (screen, (int)(height / 2.0) + P[4]->X (),
       
    76               (int)(height / 2.0) + P[4]->Y (),
       
    77               (int)(height / 2.0) + P[6]->X (), (int)(height / 2.0) + P[6]->Y (), color);
       
    78 
       
    79     drawLine (screen, (int)(height / 2.0) + P[5]->X (),
       
    80               (int)(height / 2.0) + P[5]->Y (),
       
    81               (int)(height / 2.0) + P[7]->X (), (int)(height / 2.0) + P[7]->Y (), color);
       
    82 
       
    83     drawLine (screen, P[0]->X (), P[0]->Y (),
       
    84               (int)(height / 2.0) + P[4]->X (), (int)(height / 2.0) + P[4]->Y (), color);
       
    85 
       
    86     drawLine (screen, P[2]->X (), P[2]->Y (),
       
    87               (int)(height / 2.0) + P[6]->X (), (int)(height / 2.0) + P[6]->Y (), color);
       
    88 
       
    89     drawLine (screen, P[1]->X (), P[1]->Y (),
       
    90               (int)(height / 2.0) + P[5]->X (), (int)(height / 2.0) + P[5]->Y (), color);
       
    91 
       
    92     drawLine (screen, P[3]->X (), P[3]->Y (),
       
    93               (int)(height / 2.0) + P[7]->X (), (int)(height / 2.0) + P[7]->Y (), color);
       
    94 }