pmc/cube.cc
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:49:12 +0200
changeset 43 cf8c1b5127b2
parent 42 83b8151b966d
child 45 7197576fedcf
permissions -rw-r--r--
vector.cc Testcase -> Eine Referenz ist günstiger bei Vektoren -> move ist ohne Referenz flexibler -> Es werden weniger Objekte erzeugt und dementsprechend auch wieder zerstört. committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9
c3fecc82ade6 standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 4
diff changeset
     1
/**
c3fecc82ade6 standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 4
diff changeset
     2
 * test/demos/pmc/cube.cc
c3fecc82ade6 standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 4
diff changeset
     3
 * Copyright (C) 2008 Markus Broeker
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
 */
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
#include <cube.h>
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
     7
#include <cstdio>
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
     8
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
     9
Cube::Cube (Surface * s)
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    10
{
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    11
    P[0] = new Vector (0, 0);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    12
    P[1] = new Vector (100, 0);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    13
    P[2] = new Vector (100, 100);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    14
    P[3] = new Vector (0, 100);
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    16
    P[4] = new Vector (25, 25);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    17
    P[5] = new Vector (125, 25);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    18
    P[6] = new Vector (125, 125);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    19
    P[7] = new Vector (25, 125);
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    21
    surface = s;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    22
    height = 25;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    23
}
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    24
43
cf8c1b5127b2 vector.cc Testcase
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
    25
Cube::Cube (Surface * s, Vector& p1, Vector& p2, Vector& p3, Vector& p4, int h)
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
{
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    27
    height = h;
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    28
    surface = s;
43
cf8c1b5127b2 vector.cc Testcase
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
    29
    Vector location(h/2, h/2);
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    30
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
    P[0] = new Vector (p1);
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    32
    P[1] = new Vector (p2);
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    33
    P[2] = new Vector (p3);
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    34
    P[3] = new Vector (p4);
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    36
    for (int i = 0; i < 4; i++) {
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    37
        P[4 + i] = new Vector (*P[i]);
43
cf8c1b5127b2 vector.cc Testcase
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
    38
        *P[4 + i] = *P[i] + location;
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    39
    }
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    40
}
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    41
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    42
Cube::~Cube ()
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    43
{
43
cf8c1b5127b2 vector.cc Testcase
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 42
diff changeset
    44
    for (int i = 0; i < 8; i++) {
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    45
#ifdef DEBUG
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    46
        fprintf (stderr, "Removing P[%d]: ", i);
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    47
#endif
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    48
        delete P[i];
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    49
    }
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    50
}
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    51
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    52
void Cube::move (Vector location)
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    53
{
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    54
    for (int i = 0; i < 8; i++) {
36
f52a9deddfc0 cube.cc:
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 35
diff changeset
    55
        *P[i] = *P[i] + location;
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    56
    }
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    57
}
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    58
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    59
void Cube::show ()
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    60
{
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    61
	/* Implement some Sanity Checks */
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    62
    int height = surface->getHeight ();
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    63
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    64
    surface->drawLine (P[0]->X (), P[0]->Y (), P[1]->X (), P[1]->Y ());
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    65
    surface->drawLine (P[3]->X (), P[3]->Y (), P[2]->X (), P[2]->Y ());
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    66
    surface->drawLine (P[2]->X (), P[2]->Y (), P[1]->X (), P[1]->Y ());
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    67
    surface->drawLine (P[3]->X (), P[3]->Y (), P[0]->X (), P[0]->Y ());
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    68
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    69
    surface->drawLine (P[4]->X (), P[4]->Y (), P[5]->X (), P[5]->Y ());
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    70
    surface->drawLine (P[7]->X (), P[7]->Y (), P[6]->X (), P[6]->Y ());
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    71
    surface->drawLine (P[7]->X (), P[7]->Y (), P[4]->X (), P[4]->Y ());
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    72
    surface->drawLine (P[6]->X (), P[6]->Y (), P[5]->X (), P[5]->Y ());
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    73
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    74
    surface->drawLine (P[0]->X (), P[0]->Y (), P[4]->X (), P[4]->Y ());
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    75
    surface->drawLine (P[1]->X (), P[1]->Y (), P[5]->X (), P[5]->Y ());
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    76
42
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    77
    surface->drawLine (P[2]->X (), P[2]->Y (), P[6]->X (), P[6]->Y ());
83b8151b966d Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 36
diff changeset
    78
    surface->drawLine (P[3]->X (), P[3]->Y (), P[7]->X (), P[7]->Y ());
4
236f8f747073 pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    79
}