pmc/cube.cc
changeset 42 83b8151b966d
parent 36 f52a9deddfc0
child 43 cf8c1b5127b2
equal deleted inserted replaced
41:574503cf7bb0 42:83b8151b966d
     2  * test/demos/pmc/cube.cc
     2  * test/demos/pmc/cube.cc
     3  * Copyright (C) 2008 Markus Broeker
     3  * Copyright (C) 2008 Markus Broeker
     4  */
     4  */
     5 
     5 
     6 #include <cube.h>
     6 #include <cube.h>
     7 #include "../sdl.cc"
     7 #include <cstdio>
     8 
     8 
     9 extern SDL_Surface *screen;
     9 Cube::Cube (Surface * s)
    10 extern unsigned long color;
    10 {
       
    11     P[0] = new Vector (0, 0);
       
    12     P[1] = new Vector (100, 0);
       
    13     P[2] = new Vector (100, 100);
       
    14     P[3] = new Vector (0, 100);
    11 
    15 
    12 Cube::Cube (Vector p1, Vector p2, Vector p3, Vector p4, int h)
    16     P[4] = new Vector (25, 25);
       
    17     P[5] = new Vector (125, 25);
       
    18     P[6] = new Vector (125, 125);
       
    19     P[7] = new Vector (25, 125);
       
    20 
       
    21     surface = s;
       
    22     height = 25;
       
    23 }
       
    24 
       
    25 Cube::Cube (Surface * s, Vector p1, Vector p2, Vector p3, Vector p4, int h)
    13 {
    26 {
       
    27     height = h;
       
    28     surface = s;
       
    29 
    14     P[0] = new Vector (p1);
    30     P[0] = new Vector (p1);
    15     P[1] = new Vector (p2);
    31     P[1] = new Vector (p2);
    16     P[2] = new Vector (p3);
    32     P[2] = new Vector (p3);
    17     P[3] = new Vector (p4);
    33     P[3] = new Vector (p4);
    18 
    34 
    19     P[4] = new Vector (p1.X (), p1.Y (), p1.Z () + h);
    35     for (int i = 0; i < 4; i++) {
    20     P[5] = new Vector (p2.X (), p2.Y (), p2.Z () + h);
    36         P[4 + i] = new Vector (*P[i]);
    21     P[6] = new Vector (p3.X (), p3.Y (), p3.Z () + h);
    37         *P[4 + i] = *P[i] + Vector (h / 2, h / 2);
    22     P[7] = new Vector (p4.X (), p4.Y (), p4.Z () + h);
    38     }
    23 
       
    24     height = h;
       
    25 }
    39 }
    26 
    40 
    27 Cube::~Cube ()
    41 Cube::~Cube ()
    28 {
    42 {
    29     for (int i = 0; i < 8; i++)
    43     for (int i = 0; i < 6; i++) {
       
    44 #ifdef DEBUG
       
    45         fprintf (stderr, "Removing P[%d]: ", i);
       
    46 #endif
    30         delete P[i];
    47         delete P[i];
       
    48     }
    31 }
    49 }
    32 
    50 
    33 void Cube::move (Vector location)
    51 void Cube::move (Vector location)
    34 {
    52 {
    35     for (int i = 0; i < 8; i++) {
    53     for (int i = 0; i < 8; i++) {
    37     }
    55     }
    38 }
    56 }
    39 
    57 
    40 void Cube::show ()
    58 void Cube::show ()
    41 {
    59 {
    42     P[0]->vector ();
    60 	/* Implement some Sanity Checks */
    43     std::cout << ", ";
    61     int height = surface->getHeight ();
    44     P[1]->vector ();
       
    45     std::cout << std::endl;
       
    46     P[2]->vector ();
       
    47     std::cout << ", ";
       
    48     P[3]->vector ();
       
    49     std::cout << std::endl;
       
    50 
    62 
    51     P[4]->vector ();
    63     surface->drawLine (P[0]->X (), P[0]->Y (), P[1]->X (), P[1]->Y ());
    52     std::cout << ", ";
    64     surface->drawLine (P[3]->X (), P[3]->Y (), P[2]->X (), P[2]->Y ());
    53     P[5]->vector ();
    65     surface->drawLine (P[2]->X (), P[2]->Y (), P[1]->X (), P[1]->Y ());
    54     std::cout << std::endl;
    66     surface->drawLine (P[3]->X (), P[3]->Y (), P[0]->X (), P[0]->Y ());
    55     P[6]->vector ();
       
    56     std::cout << ", ";
       
    57     P[7]->vector ();
       
    58     std::cout << std::endl;
       
    59 
    67 
    60     drawLine (screen, P[0]->X (), P[0]->Y (), P[1]->X (), P[1]->Y (), color);
    68     surface->drawLine (P[4]->X (), P[4]->Y (), P[5]->X (), P[5]->Y ());
    61     drawLine (screen, P[2]->X (), P[2]->Y (), P[3]->X (), P[3]->Y (), color);
    69     surface->drawLine (P[7]->X (), P[7]->Y (), P[6]->X (), P[6]->Y ());
    62     drawLine (screen, P[0]->X (), P[0]->Y (), P[2]->X (), P[2]->Y (), color);
    70     surface->drawLine (P[7]->X (), P[7]->Y (), P[4]->X (), P[4]->Y ());
    63     drawLine (screen, P[1]->X (), P[1]->Y (), P[3]->X (), P[3]->Y (), color);
    71     surface->drawLine (P[6]->X (), P[6]->Y (), P[5]->X (), P[5]->Y ());
    64 
    72 
    65     drawLine (screen, (int)(height / 2.0) + P[4]->X (),
    73     surface->drawLine (P[0]->X (), P[0]->Y (), P[4]->X (), P[4]->Y ());
    66               (int)(height / 2.0) + P[4]->Y (),
    74     surface->drawLine (P[1]->X (), P[1]->Y (), P[5]->X (), P[5]->Y ());
    67               (int)(height / 2.0) + P[5]->X (), (int)(height / 2.0) + P[5]->Y (), color);
       
    68 
    75 
    69     drawLine (screen, (int)(height / 2.0) + P[6]->X (),
    76     surface->drawLine (P[2]->X (), P[2]->Y (), P[6]->X (), P[6]->Y ());
    70               (int)(height / 2.0) + P[6]->Y (),
    77     surface->drawLine (P[3]->X (), P[3]->Y (), P[7]->X (), P[7]->Y ());
    71               (int)(height / 2.0) + P[7]->X (), (int)(height / 2.0) + P[7]->Y (), color);
       
    72 
       
    73     drawLine (screen, (int)(height / 2.0) + P[4]->X (),
       
    74               (int)(height / 2.0) + P[4]->Y (),
       
    75               (int)(height / 2.0) + P[6]->X (), (int)(height / 2.0) + P[6]->Y (), color);
       
    76 
       
    77     drawLine (screen, (int)(height / 2.0) + P[5]->X (),
       
    78               (int)(height / 2.0) + P[5]->Y (),
       
    79               (int)(height / 2.0) + P[7]->X (), (int)(height / 2.0) + P[7]->Y (), color);
       
    80 
       
    81     drawLine (screen, P[0]->X (), P[0]->Y (),
       
    82               (int)(height / 2.0) + P[4]->X (), (int)(height / 2.0) + P[4]->Y (), color);
       
    83 
       
    84     drawLine (screen, P[2]->X (), P[2]->Y (),
       
    85               (int)(height / 2.0) + P[6]->X (), (int)(height / 2.0) + P[6]->Y (), color);
       
    86 
       
    87     drawLine (screen, P[1]->X (), P[1]->Y (),
       
    88               (int)(height / 2.0) + P[5]->X (), (int)(height / 2.0) + P[5]->Y (), color);
       
    89 
       
    90     drawLine (screen, P[3]->X (), P[3]->Y (),
       
    91               (int)(height / 2.0) + P[7]->X (), (int)(height / 2.0) + P[7]->Y (), color);
       
    92 }
    78 }