author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Thu, 16 Apr 2009 12:50:39 +0200 | |
changeset 73 | d0578510aea1 |
parent 65 | 76514757b0d6 |
child 77 | 49e0babccb23 |
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 |
|
65
76514757b0d6
GNU Indent cannot handle C++ Source Files...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
54
diff
changeset
|
6 |
#include <cube.hpp> |
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 |
|
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
9 |
using namespace algebra; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
10 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
11 |
Cube::Cube (Surface * s) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
12 |
{ |
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
13 |
surface = s; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
14 |
name = "Cube"; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
15 |
height = 25; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
16 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
17 |
P[0] = new Vector (0, 0); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
18 |
P[1] = new Vector (100, 0); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
19 |
P[2] = new Vector (100, 100); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
20 |
P[3] = new Vector (0, 100); |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
21 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
22 |
P[4] = new Vector (25, 25); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
23 |
P[5] = new Vector (125, 25); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
24 |
P[6] = new Vector (125, 125); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
25 |
P[7] = new Vector (25, 125); |
54
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
26 |
|
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
27 |
refCounter++; |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
28 |
} |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
29 |
|
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
30 |
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
|
31 |
{ |
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
32 |
surface = s; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
33 |
name = "Cube"; |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
34 |
height = h; |
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
35 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
36 |
Vector location (h / 4, h / 4); |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
37 |
|
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
38 |
P[0] = new Vector (p1); |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
39 |
P[1] = new Vector (p2); |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
40 |
P[2] = new Vector (p3); |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
41 |
P[3] = new Vector (p4); |
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 < 4; i++) { |
54
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
44 |
P[4 + i] = new Vector (); |
43 | 45 |
*P[4 + i] = *P[i] + location; |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
46 |
} |
54
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
47 |
|
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
48 |
refCounter++; |
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 |
|
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
51 |
Cube::Cube (Surface * s, Vector p[4], int h) |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
52 |
{ |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
53 |
surface = s; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
54 |
name = "Cube"; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
55 |
height = h; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
56 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
57 |
Vector location (h / 4, h / 4); |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
58 |
|
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
59 |
for (int i = 0; i < 4; i++) { |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
60 |
P[i] = new Vector (p[i]); |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
61 |
P[4 + i] = new Vector (*P[i]); |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
62 |
*P[4 + i] = *P[i] + location; |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
63 |
} |
54
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
64 |
|
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
65 |
refCounter++; |
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
66 |
} |
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
67 |
|
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
68 |
Cube::Cube (const Cube & copy) |
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
69 |
{ |
c064ce9f40f5
Vector and PMC ChangeLog
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
46
diff
changeset
|
70 |
fprintf (stderr, "Copy Constructor in Cube disabled...\n"); |
45
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
71 |
} |
7197576fedcf
pmc: namespace algebra for vector
Emilio Largo <largo@largo.homelinux.org>
parents:
43
diff
changeset
|
72 |
|
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
73 |
Cube::~Cube () |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
74 |
{ |
43 | 75 |
for (int i = 0; i < 8; i++) { |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
76 |
#ifdef DEBUG |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
77 |
fprintf (stderr, "Removing P[%d]: ", i); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
78 |
#endif |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
79 |
delete P[i]; |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
80 |
} |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
81 |
} |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
82 |
|
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
83 |
void Cube::move (Vector location) |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
84 |
{ |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
85 |
for (int i = 0; i < 8; i++) { |
36 | 86 |
*P[i] = *P[i] + location; |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
87 |
} |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
88 |
} |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
89 |
|
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
90 |
void Cube::show () |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
91 |
{ |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
97 |
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
|
98 |
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
|
99 |
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
|
100 |
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
|
101 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
102 |
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
|
103 |
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
|
104 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
36
diff
changeset
|
105 |
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
|
106 |
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
|
107 |
} |