author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Thu, 16 Apr 2009 12:49:12 +0200 | |
changeset 42 | 83b8151b966d |
parent 36 | f52a9deddfc0 |
child 43 | cf8c1b5127b2 |
permissions | -rw-r--r-- |
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 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
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; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
29 |
|
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
30 |
P[0] = new Vector (p1); |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
31 |
P[1] = new Vector (p2); |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
32 |
P[2] = new Vector (p3); |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
33 |
P[3] = new Vector (p4); |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
34 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
35 |
for (int i = 0; i < 4; i++) { |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
36 |
P[4 + i] = new Vector (*P[i]); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
37 |
*P[4 + i] = *P[i] + Vector (h / 2, h / 2); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
38 |
} |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
39 |
} |
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 |
Cube::~Cube () |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
42 |
{ |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
43 |
for (int i = 0; i < 6; i++) { |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
44 |
#ifdef DEBUG |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
45 |
fprintf (stderr, "Removing P[%d]: ", i); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
46 |
#endif |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
47 |
delete P[i]; |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
48 |
} |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
49 |
} |
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 |
void Cube::move (Vector location) |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
52 |
{ |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
53 |
for (int i = 0; i < 8; i++) { |
36 | 54 |
*P[i] = *P[i] + location; |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
55 |
} |
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 |
void Cube::show () |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
59 |
{ |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
60 |
/* Implement some Sanity Checks */ |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
61 |
int height = surface->getHeight (); |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
62 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
63 |
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
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
73 |
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
|
74 |
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
|
75 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
76 |
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
|
77 |
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
|
78 |
} |