15c82487 |
1 | // Copyright (C) 2006 Erik Dahlberg |
2 | // |
1a372e99 |
3 | // This file is part of LSystem3D. |
15c82487 |
4 | // |
5 | // LSystem3D is free software; you can redistribute it and/or |
6 | // modify it under the terms of the GNU General Public License |
7 | // as published by the Free Software Foundation; either version 2 |
8 | // of the License, or (at your option) any later version. |
9 | // |
10 | // LSystem3D is distributed in the hope that it will be useful, |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | // GNU General Public License for more details. |
14 | // |
15 | // You should have received a copy of the GNU General Public License |
16 | // along with LSystem3D; if not, write to the Free Software |
17 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
18 | |
19 | |
20 | |
21 | |
22 | #ifndef TURTLE_H |
23 | #define TURTLE_H |
24 | |
25 | #include <stack> |
26 | |
27 | #include "coordinate.h" |
28 | #include "model.h" |
29 | #include "vector.h" |
30 | |
31 | using namespace std; |
32 | |
33 | |
34 | |
35 | /** |
526db675 |
36 | * The model creator |
15c82487 |
37 | */ |
38 | class Turtle |
39 | { |
40 | public: |
68a7b857 |
41 | |
15c82487 |
42 | /** |
43 | * Constructor |
526db675 |
44 | * @param model create this model |
15c82487 |
45 | */ |
46 | Turtle(Model *model); |
47 | |
48 | /** |
49 | * Destructor |
50 | */ |
51 | ~Turtle(); |
52 | |
68a7b857 |
53 | |
54 | /** |
55 | * Reset to default state |
56 | */ |
57 | void reset(); |
58 | |
15c82487 |
59 | /** |
60 | * Turn left |
61 | */ |
62 | void turnLeft(); |
63 | |
64 | /** |
65 | * Turn right |
66 | */ |
67 | void turnRight(); |
68 | |
69 | /** |
70 | * Pitch down |
71 | */ |
72 | void pitchDown(); |
73 | |
74 | /** |
75 | * Pitch up |
76 | */ |
77 | void pitchUp(); |
78 | |
79 | /** |
80 | * Roll left |
81 | */ |
82 | void rollLeft(); |
83 | |
84 | /** |
85 | * Roll right |
86 | */ |
87 | void rollRight(); |
88 | |
89 | /** |
90 | * Turn around |
91 | */ |
92 | void turnAround(); |
93 | |
94 | /** |
95 | * Walk forward |
96 | */ |
97 | void walk(); |
98 | |
526db675 |
99 | /** |
100 | * Walk forward, creating a filled surface |
101 | */ |
102 | void fillWalk(); |
103 | |
15c82487 |
104 | /** |
105 | * Save current state to stack |
106 | */ |
107 | void push(); |
108 | |
109 | /** |
110 | * Restore old state from stack |
111 | */ |
112 | void pop(); |
113 | |
15c82487 |
114 | |
15c82487 |
115 | /** |
116 | * Set turn/pitch/roll angle |
117 | * @param angle the angle, in radians |
118 | */ |
119 | void setAngle(double radians); |
120 | |
68a7b857 |
121 | |
15c82487 |
122 | /** |
123 | * Get turn/pitch/roll angle |
124 | * @return the angle, in radians |
125 | */ |
126 | double getAngle(); |
127 | |
128 | protected: |
129 | |
526db675 |
130 | Coordinate _position; // Current position |
15c82487 |
131 | |
526db675 |
132 | Vector _heading; // Forward pointing vector |
133 | Vector _left; // Left pointing vector |
134 | Vector _up; // Up pointing vector |
15c82487 |
135 | |
526db675 |
136 | double _angle; // Turn/pitch/roll angle, in radians |
15c82487 |
137 | |
526db675 |
138 | stack<Coordinate> _positionStack; // Positions in stack |
139 | stack<Vector> _headingStack; // Heading vectors in stack |
140 | stack<Vector> _leftStack; // Left vectors in stack |
141 | stack<Vector> _upStack; // Up vectors in stack |
142 | stack<double> _diameterStack; // Diameters in stack |
143 | stack<int> _colorIndexStack; // Colors indices in stack |
15c82487 |
144 | |
526db675 |
145 | Model *_model; // The created model |
15c82487 |
146 | }; |
147 | |
148 | |
149 | |
150 | #endif |