1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | |
---|
15 | this file extends the framework file, so it renders what i want. |
---|
16 | */ |
---|
17 | |
---|
18 | #include "framework.h" |
---|
19 | |
---|
20 | #include "physics_engine.h" |
---|
21 | #include "particle_engine.h" |
---|
22 | |
---|
23 | |
---|
24 | void Framework::moduleInit(int argc, char** argv) |
---|
25 | { |
---|
26 | // Creating a Test Particle System |
---|
27 | ParticleSystem* system = new ParticleSystem(100000, PARTICLE_SPRITE); |
---|
28 | system->setRadius(0,0,0,0); |
---|
29 | system->setLifeSpan(0); |
---|
30 | system->setConserve(1.0); |
---|
31 | |
---|
32 | // Creating a Test Particle Emitter |
---|
33 | ParticleEmitter* emitter = new ParticleEmitter(Vector(0 , 1, 0)); |
---|
34 | emitter->setEmissionRate(0); |
---|
35 | emitter->setEmissionVelocity(0,0); |
---|
36 | emitter->setSpread(0,0); |
---|
37 | emitter->setType(EMITTER_DOT); |
---|
38 | emitter->setSize(0); |
---|
39 | // Add the Flow from the Emitter into the System |
---|
40 | ParticleEngine::getInstance()->addConnection(emitter, system); |
---|
41 | } |
---|
42 | |
---|
43 | void Framework::moduleEventHandler(SDL_Event* event) |
---|
44 | { |
---|
45 | switch (event->type) |
---|
46 | { |
---|
47 | case SDL_KEYDOWN: |
---|
48 | switch (event->key.keysym.sym) |
---|
49 | { |
---|
50 | case SDLK_i: |
---|
51 | ParticleEngine::getInstance()->debug(); |
---|
52 | break; |
---|
53 | } |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | void Framework::moduleTick(float dt) |
---|
58 | { |
---|
59 | ParticleEngine::getInstance()->tick(dt); |
---|
60 | } |
---|
61 | |
---|
62 | void Framework::moduleDraw(float dt) |
---|
63 | { |
---|
64 | ParticleEngine::getInstance()->draw(dt); |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | void Framework::moduleHelp(void) const |
---|
69 | { |
---|
70 | PRINT(0)("\n"); |
---|
71 | PRINT(0)("i - Particle-state Information\n\n"); |
---|
72 | PRINT(0)("\n"); |
---|
73 | |
---|
74 | } |
---|
75 | |
---|
76 | int emitterChange(GtkWidget* nonInterest, void* widget) |
---|
77 | { |
---|
78 | Option* option = (Option*) widget; |
---|
79 | const char* name = option->getTitle(); |
---|
80 | char* value = option->save(); |
---|
81 | |
---|
82 | ParticleEmitter* tmpEmit = ParticleEngine::getInstance()->getEmitterByNumber(1); |
---|
83 | if (tmpEmit) |
---|
84 | { |
---|
85 | if (!strcmp(name, "EmissionRate")) |
---|
86 | { |
---|
87 | tmpEmit->setEmissionRate(atof(value)); |
---|
88 | PRINT(3)("EmissionRate set to %f\n", atof(value)); |
---|
89 | } |
---|
90 | else if (!strcmp(name, "Velocity")) |
---|
91 | { |
---|
92 | tmpEmit->setEmissionVelocity(atof(value)); |
---|
93 | PRINT(3)("Velocity set to %f\n", atof(value)); |
---|
94 | } |
---|
95 | else if(!strcmp(name, "SpreadAngle")) |
---|
96 | { |
---|
97 | tmpEmit->setSpread(atof(value)); |
---|
98 | PRINT(3)("SpreadAngle set to %f\n", atof(value)); |
---|
99 | } |
---|
100 | else if(!strcmp(name, "EmitterType")) |
---|
101 | { |
---|
102 | if (!strcmp(value, "EMITTER_DOT")) |
---|
103 | tmpEmit->setType(EMITTER_DOT); |
---|
104 | else if (!strcmp(value, "EMITTER_PLANE")) |
---|
105 | tmpEmit->setType(EMITTER_PLANE); |
---|
106 | else if (!strcmp(value, "EMITTER_CUBE")) |
---|
107 | tmpEmit->setType(EMITTER_CUBE); |
---|
108 | PRINT(3)("EmitterType set to %s\n", value); |
---|
109 | } |
---|
110 | else if(!strcmp(name, "EmitterSize")) |
---|
111 | { |
---|
112 | tmpEmit->setSize(atof(value)); |
---|
113 | PRINT(3)("EmitterSize set to %f\n", atof(value)); |
---|
114 | } |
---|
115 | } |
---|
116 | delete value; |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | int systemChange(GtkWidget* nonInterest, void* widget) |
---|
121 | { |
---|
122 | Option* option = (Option*) widget; |
---|
123 | const char* name = option->getTitle(); |
---|
124 | char* value = option->save(); |
---|
125 | printf("%s\n", value); |
---|
126 | |
---|
127 | ParticleSystem* tmpSys = ParticleEngine::getInstance()->getSystemByNumber(1); |
---|
128 | if (tmpSys) |
---|
129 | { |
---|
130 | if (!strcmp(name, "StartRadius")) |
---|
131 | { |
---|
132 | tmpSys->setRadius(atof(value), tmpSys->getEndRadius()); |
---|
133 | PRINT(3)("ParticleStartRadius set to %f\n", atof(value)); |
---|
134 | } |
---|
135 | else if (!strcmp(name, "EndRadius")) |
---|
136 | { |
---|
137 | tmpSys->setRadius( tmpSys->getStartRadius(), atof(value)); |
---|
138 | PRINT(3)("ParticleEndRadius set to %f\n", atof(value)); |
---|
139 | } |
---|
140 | |
---|
141 | else if (!strcmp(name, "LifeSpan")) |
---|
142 | { |
---|
143 | tmpSys->setLifeSpan(atof(value)); |
---|
144 | PRINT(3)("ParticleLifeSpan set to %f\n", atof(value)); |
---|
145 | } |
---|
146 | |
---|
147 | else if (!strcmp(name, "ConserveFactor")) |
---|
148 | { |
---|
149 | tmpSys->setConserve(atof(value)); |
---|
150 | PRINT(3)("ParticleConserveFactor set to %f\n", atof(value)); |
---|
151 | } |
---|
152 | |
---|
153 | else if (!strcmp(name, "ParticleType")) |
---|
154 | { |
---|
155 | if (!strcmp(value, "PARTICLE_DOT")) |
---|
156 | tmpSys->setType(PARTICLE_DOT); |
---|
157 | else if (!strcmp(value, "PARTICLE_SPARK")) |
---|
158 | tmpSys->setType(PARTICLE_SPARK); |
---|
159 | else if (!strcmp(value, "PARTICLE_SPRITE")) |
---|
160 | tmpSys->setType(PARTICLE_SPRITE); |
---|
161 | |
---|
162 | PRINT(3)("ParticleType set to %s\n", value); |
---|
163 | } |
---|
164 | |
---|
165 | else if (!strcmp(name, "InheritSpeed")) |
---|
166 | { |
---|
167 | tmpSys->setInheritSpeed(atof(value)); |
---|
168 | PRINT(3)("ParticleInheritSpeed set to %f\n", atof(value)); |
---|
169 | } |
---|
170 | |
---|
171 | } |
---|
172 | delete value; |
---|
173 | } |
---|
174 | |
---|
175 | |
---|
176 | void Framework::moduleInitGui(int argc, char** argv) |
---|
177 | { |
---|
178 | Window* guiMainWindow = NULL; |
---|
179 | |
---|
180 | initGUI(0, NULL); |
---|
181 | |
---|
182 | guiMainWindow = new Window("ParticlesFUN"); |
---|
183 | { |
---|
184 | Box* windowBox = new Box('v'); |
---|
185 | { |
---|
186 | Frame* emitterFrame = new Frame("emitter-settings"); |
---|
187 | { |
---|
188 | Box* emitterBox = new Box('v'); |
---|
189 | { |
---|
190 | emitterBox->fill(new Label("EmissionRate")); |
---|
191 | Slider* EmissionRate = new Slider("EmissionRate", 0, 1000); |
---|
192 | EmissionRate->connectSignal("value_changed", (void*)EmissionRate, emitterChange ); |
---|
193 | emitterBox->fill(EmissionRate); |
---|
194 | |
---|
195 | emitterBox->fill(new Label("Velocity")); |
---|
196 | Slider* velocity = new Slider("Velocity", 0, 2); |
---|
197 | velocity->setExactness(3); |
---|
198 | velocity->connectSignal("value_changed", (void*)velocity, emitterChange ); |
---|
199 | emitterBox->fill(velocity); |
---|
200 | |
---|
201 | emitterBox->fill(new Label("SpreadAngle")); |
---|
202 | Slider* SpreadAngle = new Slider("SpreadAngle", 0, M_PI); |
---|
203 | SpreadAngle->setExactness(3); |
---|
204 | SpreadAngle->connectSignal("value_changed", (void*)SpreadAngle, emitterChange ); |
---|
205 | emitterBox->fill(SpreadAngle); |
---|
206 | |
---|
207 | emitterBox->fill(new Label("EmitterType")); |
---|
208 | Menu* EmitterType = new Menu("EmitterType"); |
---|
209 | EmitterType->addItem("EMITTER_DOT"); |
---|
210 | EmitterType->addItem("EMITTER_PLANE"); |
---|
211 | EmitterType->addItem("EMITTER_CUBE"); |
---|
212 | EmitterType->load("EMITTER_DOT"); |
---|
213 | EmitterType->connectSignal("changed", (void*)EmitterType, emitterChange ); |
---|
214 | emitterBox->fill(EmitterType); |
---|
215 | |
---|
216 | emitterBox->fill(new Label("EmitterSize")); |
---|
217 | Slider* EmitterSize = new Slider("EmitterSize", 0, 100); |
---|
218 | EmitterSize->setExactness(1); |
---|
219 | EmitterSize->connectSignal("value_changed", (void*)EmitterSize, emitterChange ); |
---|
220 | emitterBox->fill(EmitterSize); |
---|
221 | } |
---|
222 | emitterFrame->fill(emitterBox); |
---|
223 | } |
---|
224 | windowBox->fill(emitterFrame); |
---|
225 | |
---|
226 | Frame* systemFrame = new Frame("system-settings"); |
---|
227 | { |
---|
228 | Box* systemBox = new Box('v'); |
---|
229 | { |
---|
230 | systemBox->fill(new Label("StartRadius")); |
---|
231 | Slider* StartRadius = new Slider("StartRadius", 0, 10); |
---|
232 | StartRadius->setExactness(3); |
---|
233 | StartRadius->connectSignal("value_changed", (void*)StartRadius, systemChange ); |
---|
234 | systemBox->fill(StartRadius); |
---|
235 | |
---|
236 | systemBox->fill(new Label("EndRadius")); |
---|
237 | Slider* EndRadius = new Slider("EndRadius", 0, 10); |
---|
238 | EndRadius->setExactness(3); |
---|
239 | EndRadius->connectSignal("value_changed", (void*)EndRadius, systemChange ); |
---|
240 | systemBox->fill(EndRadius); |
---|
241 | |
---|
242 | systemBox->fill(new Label("LifeSpan")); |
---|
243 | Slider* LifeSpan = new Slider("LifeSpan", 0, 10); |
---|
244 | LifeSpan->setExactness(3); |
---|
245 | LifeSpan->connectSignal("value_changed", (void*)LifeSpan, systemChange ); |
---|
246 | systemBox->fill(LifeSpan); |
---|
247 | |
---|
248 | systemBox->fill(new Label("ConserveFactor")); |
---|
249 | Slider* ConserveFactor = new Slider("ConserveFactor", 0, 1); |
---|
250 | ConserveFactor->setExactness(3); |
---|
251 | ConserveFactor->load("1.0"); |
---|
252 | ConserveFactor->connectSignal("value_changed", (void*)ConserveFactor, systemChange ); |
---|
253 | systemBox->fill(ConserveFactor); |
---|
254 | |
---|
255 | systemBox->fill(new Label("ParticleType")); |
---|
256 | Menu* ParticleType = new Menu("ParticleType"); |
---|
257 | ParticleType->addItem("PARTICLE_DOT"); |
---|
258 | ParticleType->addItem("PARTICLE_SPARK"); |
---|
259 | ParticleType->addItem("PARTICLE_SPRITE"); |
---|
260 | ParticleType->load("PARTICLE_SPRITE"); |
---|
261 | ParticleType->connectSignal("changed", (void*)ParticleType, systemChange ); |
---|
262 | systemBox->fill(ParticleType); |
---|
263 | |
---|
264 | systemBox->fill(new Label("InheritSpeed")); |
---|
265 | Slider* InheritSpeed = new Slider("InheritSpeed", 0, 1); |
---|
266 | InheritSpeed->setExactness(3); |
---|
267 | InheritSpeed->connectSignal("value_changed", (void*)InheritSpeed, systemChange ); |
---|
268 | systemBox->fill(InheritSpeed); |
---|
269 | |
---|
270 | |
---|
271 | } |
---|
272 | systemFrame->fill(systemBox); |
---|
273 | } |
---|
274 | windowBox->fill(systemFrame); |
---|
275 | |
---|
276 | Button* quitButton = new Button("quit"); |
---|
277 | |
---|
278 | quitButton->connectSignal("clicked", NULL, quitGui); |
---|
279 | // Window::mainWindow->connectSignal("remove", this, GuiExec::quitGui); |
---|
280 | Window::mainWindow->connectSignal("destroy", NULL, quitGui); |
---|
281 | |
---|
282 | windowBox->fill(quitButton); |
---|
283 | } |
---|
284 | guiMainWindow->fill(windowBox); |
---|
285 | } |
---|
286 | Window::mainWindow->showall(); |
---|
287 | Window::mainWindow->setSize(300, 500); |
---|
288 | } |
---|