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 | #include "fields.h" |
---|
23 | #include "stdlibincl.h" |
---|
24 | |
---|
25 | #define PINIT_EMISSION_RATE 50 |
---|
26 | #define PINIT_EMISSION_VELOCITY 5.0 |
---|
27 | #define PINIT_SPREAD_ANGLE 0.1 |
---|
28 | #define PINIT_EMITTER_TYPE EMITTER_DOT |
---|
29 | #define PINIT_EMITTER_SIZE 1.0 |
---|
30 | #define PINIT_START_RADIUS 5.0 |
---|
31 | #define PINIT_END_RADIUS 0.0 |
---|
32 | #define PINIT_LIFESPAN 1.0 |
---|
33 | #define PINIT_CONSERVE_FACTOR 1.0 |
---|
34 | #define PINIT_PARTICLE_TYPE PARTICLE_SPRITE |
---|
35 | #define PINIT_INHERIT_SPEED 0.0 |
---|
36 | #define PINIT_PARTICLE_MASS 1.0 |
---|
37 | |
---|
38 | |
---|
39 | Field* twirl; |
---|
40 | Field* gravity; |
---|
41 | Field* pointGravity; |
---|
42 | |
---|
43 | void Framework::moduleInit(int argc, char** argv) |
---|
44 | { |
---|
45 | verbose = 5; |
---|
46 | ParticleEngine::getInstance(); |
---|
47 | PhysicsEngine::getInstance(); |
---|
48 | |
---|
49 | |
---|
50 | // Creating a Test Particle System |
---|
51 | ParticleSystem* system = new ParticleSystem(100000, PINIT_PARTICLE_TYPE); |
---|
52 | system->setRadius(PINIT_START_RADIUS, PINIT_END_RADIUS ,0 ,0); |
---|
53 | system->setLifeSpan(PINIT_LIFESPAN); |
---|
54 | |
---|
55 | system->setConserve(PINIT_CONSERVE_FACTOR); |
---|
56 | system->setMass(5,3,6); |
---|
57 | |
---|
58 | // Creating a Test Particle Emitter |
---|
59 | ParticleEmitter* emitter = new ParticleEmitter(Vector(0 , 1, 0)); |
---|
60 | emitter->setEmissionRate(PINIT_EMISSION_RATE); |
---|
61 | emitter->setEmissionVelocity(PINIT_EMISSION_VELOCITY ,0); |
---|
62 | emitter->setSpread(PINIT_SPREAD_ANGLE ,0); |
---|
63 | emitter->setType(PINIT_EMITTER_TYPE); |
---|
64 | emitter->setSize(PINIT_EMITTER_SIZE); |
---|
65 | emitter->setAbsCoor(Vector(3,0,0)); |
---|
66 | // Add the Flow from the Emitter into the System |
---|
67 | ParticleEngine::getInstance()->addConnection(emitter, system); |
---|
68 | |
---|
69 | |
---|
70 | twirl = new Twirl(); |
---|
71 | twirl->setMagnitude(0); |
---|
72 | gravity = new Gravity(); |
---|
73 | gravity->setMagnitude(0); |
---|
74 | pointGravity = new PointGravity(); |
---|
75 | pointGravity->setMagnitude(0); |
---|
76 | |
---|
77 | new PhysicsConnection(system, gravity); |
---|
78 | new PhysicsConnection(system, twirl); |
---|
79 | new PhysicsConnection(system, pointGravity); |
---|
80 | } |
---|
81 | |
---|
82 | void Framework::moduleEventHandler(SDL_Event* event) |
---|
83 | { |
---|
84 | switch (event->type) |
---|
85 | { |
---|
86 | case SDL_KEYDOWN: |
---|
87 | switch (event->key.keysym.sym) |
---|
88 | { |
---|
89 | case SDLK_i: |
---|
90 | ParticleEngine::getInstance()->debug(); |
---|
91 | PhysicsEngine::getInstance()->debug(); |
---|
92 | break; |
---|
93 | } |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | void Framework::moduleTick(float dt) |
---|
98 | { |
---|
99 | PhysicsEngine::getInstance()->tick(dt); |
---|
100 | ParticleEngine::getInstance()->tick(dt); |
---|
101 | } |
---|
102 | |
---|
103 | void Framework::moduleDraw() const |
---|
104 | { |
---|
105 | ParticleEngine::getInstance()->draw(); |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | void Framework::moduleHelp(void) const |
---|
110 | { |
---|
111 | PRINT(0)("\n"); |
---|
112 | PRINT(0)("i - Particle-state Information\n\n"); |
---|
113 | PRINT(0)("\n"); |
---|
114 | } |
---|
115 | |
---|
116 | int emitterChange(GtkWidget* nonInterest, void* widget) |
---|
117 | { |
---|
118 | Option* option = (Option*) widget; |
---|
119 | const char* name = option->getTitle(); |
---|
120 | char* value = option->save(); |
---|
121 | |
---|
122 | ParticleEmitter* tmpEmit = ParticleEngine::getInstance()->getEmitterByNumber(1); |
---|
123 | if (tmpEmit) |
---|
124 | { |
---|
125 | if (!strcmp(name, "EmissionRate")) |
---|
126 | { |
---|
127 | tmpEmit->setEmissionRate(atof(value)); |
---|
128 | PRINT(4)("EmissionRate set to %f\n", atof(value)); |
---|
129 | } |
---|
130 | else if (!strcmp(name, "Velocity")) |
---|
131 | { |
---|
132 | tmpEmit->setEmissionVelocity(atof(value)); |
---|
133 | PRINT(4)("Velocity set to %f\n", atof(value)); |
---|
134 | } |
---|
135 | else if(!strcmp(name, "SpreadAngle")) |
---|
136 | { |
---|
137 | tmpEmit->setSpread(atof(value), 0); |
---|
138 | PRINT(4)("SpreadAngle set to %f\n", atof(value)); |
---|
139 | } |
---|
140 | else if(!strcmp(name, "EmitterType")) |
---|
141 | { |
---|
142 | if (!strcmp(value, "EMITTER_DOT")) |
---|
143 | tmpEmit->setType(EMITTER_DOT); |
---|
144 | else if (!strcmp(value, "EMITTER_PLANE")) |
---|
145 | tmpEmit->setType(EMITTER_PLANE); |
---|
146 | else if (!strcmp(value, "EMITTER_CUBE")) |
---|
147 | tmpEmit->setType(EMITTER_CUBE); |
---|
148 | PRINT(4)("EmitterType set to %s\n", value); |
---|
149 | } |
---|
150 | else if(!strcmp(name, "EmitterSize")) |
---|
151 | { |
---|
152 | tmpEmit->setSize(atof(value)); |
---|
153 | PRINT(4)("EmitterSize set to %f\n", atof(value)); |
---|
154 | } |
---|
155 | } |
---|
156 | delete value; |
---|
157 | } |
---|
158 | |
---|
159 | |
---|
160 | int systemChange(GtkWidget* nonInterest, void* widget) |
---|
161 | { |
---|
162 | Option* option = (Option*) widget; |
---|
163 | const char* name = option->getTitle(); |
---|
164 | char* value = option->save(); |
---|
165 | |
---|
166 | ParticleSystem* tmpSys = ParticleEngine::getInstance()->getSystemByNumber(1); |
---|
167 | if (tmpSys) |
---|
168 | { |
---|
169 | if (!strcmp(name, "StartRadius")) |
---|
170 | { |
---|
171 | tmpSys->setRadius(atof(value), tmpSys->getEndRadius()); |
---|
172 | PRINT(4)("ParticleStartRadius set to %f\n", atof(value)); |
---|
173 | } |
---|
174 | else if (!strcmp(name, "EndRadius")) |
---|
175 | { |
---|
176 | tmpSys->setRadius( tmpSys->getStartRadius(), atof(value)); |
---|
177 | PRINT(4)("ParticleEndRadius set to %f\n", atof(value)); |
---|
178 | } |
---|
179 | |
---|
180 | else if (!strcmp(name, "LifeSpan")) |
---|
181 | { |
---|
182 | tmpSys->setLifeSpan(atof(value)); |
---|
183 | PRINT(4)("ParticleLifeSpan set to %f\n", atof(value)); |
---|
184 | } |
---|
185 | |
---|
186 | else if (!strcmp(name, "Mass")) |
---|
187 | { |
---|
188 | tmpSys->setMass(atof(value)); |
---|
189 | PRINT(4)("ParticleMass set to %f\n", atof(value)); |
---|
190 | } |
---|
191 | |
---|
192 | else if (!strcmp(name, "ConserveFactor")) |
---|
193 | { |
---|
194 | tmpSys->setConserve(atof(value)); |
---|
195 | PRINT(4)("ParticleConserveFactor set to %f\n", atof(value)); |
---|
196 | } |
---|
197 | |
---|
198 | else if (!strcmp(name, "ParticleType")) |
---|
199 | { |
---|
200 | if (!strcmp(value, "PARTICLE_DOT")) |
---|
201 | tmpSys->setType(PARTICLE_DOT); |
---|
202 | else if (!strcmp(value, "PARTICLE_SPARK")) |
---|
203 | tmpSys->setType(PARTICLE_SPARK); |
---|
204 | else if (!strcmp(value, "PARTICLE_SPRITE")) |
---|
205 | tmpSys->setType(PARTICLE_SPRITE); |
---|
206 | |
---|
207 | PRINT(4)("ParticleType set to %s\n", value); |
---|
208 | } |
---|
209 | |
---|
210 | else if (!strcmp(name, "InheritSpeed")) |
---|
211 | { |
---|
212 | tmpSys->setInheritSpeed(atof(value)); |
---|
213 | PRINT(4)("ParticleInheritSpeed set to %f\n", atof(value)); |
---|
214 | } |
---|
215 | else if (!strcmp(name, "RandomColor")) |
---|
216 | { |
---|
217 | tmpSys->setColor((float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, 1, |
---|
218 | (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, .5, |
---|
219 | (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, 0); |
---|
220 | } |
---|
221 | } |
---|
222 | delete value; |
---|
223 | } |
---|
224 | |
---|
225 | int fieldsChange(GtkWidget* nonInterest, void* widget) |
---|
226 | { |
---|
227 | Option* option = (Option*) widget; |
---|
228 | const char* name = option->getTitle(); |
---|
229 | char* value = option->save(); |
---|
230 | |
---|
231 | |
---|
232 | if (!strcmp(name, "Gravity")) |
---|
233 | { |
---|
234 | gravity->setMagnitude(atof(value)); |
---|
235 | } |
---|
236 | |
---|
237 | else if (!strcmp(name, "Twirl")) |
---|
238 | { |
---|
239 | twirl->setMagnitude(atof(value)); |
---|
240 | } |
---|
241 | |
---|
242 | else if (!strcmp(name, "PointGravity")) |
---|
243 | { |
---|
244 | pointGravity->setMagnitude(atof(value)); |
---|
245 | } |
---|
246 | |
---|
247 | } |
---|
248 | |
---|
249 | void Framework::moduleInitGui(int argc, char** argv) |
---|
250 | { |
---|
251 | Window* guiMainWindow = NULL; |
---|
252 | |
---|
253 | initGUI(0, NULL); |
---|
254 | |
---|
255 | guiMainWindow = new Window("ParticlesFUN"); |
---|
256 | { |
---|
257 | Box* windowBox = new Box('h'); |
---|
258 | { |
---|
259 | Frame* emitterFrame = new Frame("emitter-settings"); |
---|
260 | { |
---|
261 | Box* emitterBox = new Box('v'); |
---|
262 | { |
---|
263 | emitterBox->fill(new Label("EmissionRate")); |
---|
264 | Slider* EmissionRate = new Slider("EmissionRate", 0, 1000); |
---|
265 | EmissionRate->connectSignal("value_changed", (void*)EmissionRate, emitterChange ); |
---|
266 | EmissionRate->setValue(PINIT_EMISSION_RATE); |
---|
267 | EmissionRate->redraw(); |
---|
268 | emitterBox->fill(EmissionRate); |
---|
269 | |
---|
270 | emitterBox->fill(new Label("Velocity")); |
---|
271 | Slider* velocity = new Slider("Velocity", 0, 20); |
---|
272 | velocity->setExactness(2); |
---|
273 | velocity->connectSignal("value_changed", (void*)velocity, emitterChange ); |
---|
274 | velocity->setValue(PINIT_EMISSION_VELOCITY); |
---|
275 | velocity->redraw(); |
---|
276 | emitterBox->fill(velocity); |
---|
277 | |
---|
278 | emitterBox->fill(new Label("SpreadAngle")); |
---|
279 | Slider* SpreadAngle = new Slider("SpreadAngle", 0, M_PI); |
---|
280 | SpreadAngle->setExactness(3); |
---|
281 | SpreadAngle->connectSignal("value_changed", (void*)SpreadAngle, emitterChange ); |
---|
282 | SpreadAngle->setValue(PINIT_SPREAD_ANGLE); |
---|
283 | SpreadAngle->redraw(); |
---|
284 | emitterBox->fill(SpreadAngle); |
---|
285 | |
---|
286 | emitterBox->fill(new Label("EmitterType")); |
---|
287 | Menu* EmitterType = new Menu("EmitterType"); |
---|
288 | EmitterType->addItem("EMITTER_DOT"); |
---|
289 | EmitterType->addItem("EMITTER_PLANE"); |
---|
290 | EmitterType->addItem("EMITTER_CUBE"); |
---|
291 | EmitterType->connectSignal("changed", (void*)EmitterType, emitterChange ); |
---|
292 | EmitterType->load("EMITTER_DOT"); |
---|
293 | emitterBox->fill(EmitterType); |
---|
294 | |
---|
295 | emitterBox->fill(new Label("EmitterSize")); |
---|
296 | Slider* EmitterSize = new Slider("EmitterSize", 0, 100); |
---|
297 | EmitterSize->setExactness(1); |
---|
298 | EmitterSize->connectSignal("value_changed", (void*)EmitterSize, emitterChange ); |
---|
299 | EmitterSize->setValue(PINIT_EMITTER_SIZE); |
---|
300 | EmitterSize->redraw(); |
---|
301 | emitterBox->fill(EmitterSize); |
---|
302 | } |
---|
303 | emitterFrame->fill(emitterBox); |
---|
304 | } |
---|
305 | windowBox->fill(emitterFrame); |
---|
306 | |
---|
307 | Frame* systemFrame = new Frame("system-settings"); |
---|
308 | { |
---|
309 | Box* systemBox = new Box('v'); |
---|
310 | { |
---|
311 | systemBox->fill(new Label("StartRadius")); |
---|
312 | Slider* StartRadius = new Slider("StartRadius", 0, 10); |
---|
313 | StartRadius->setExactness(3); |
---|
314 | StartRadius->connectSignal("value_changed", (void*)StartRadius, systemChange ); |
---|
315 | StartRadius->setValue(PINIT_START_RADIUS); |
---|
316 | StartRadius->redraw(); |
---|
317 | systemBox->fill(StartRadius); |
---|
318 | |
---|
319 | systemBox->fill(new Label("EndRadius")); |
---|
320 | Slider* EndRadius = new Slider("EndRadius", 0, 10); |
---|
321 | EndRadius->setExactness(3); |
---|
322 | EndRadius->connectSignal("value_changed", (void*)EndRadius, systemChange ); |
---|
323 | EndRadius->setValue(PINIT_END_RADIUS); |
---|
324 | EndRadius->redraw(); |
---|
325 | systemBox->fill(EndRadius); |
---|
326 | |
---|
327 | systemBox->fill(new Label("ParticleMass")); |
---|
328 | Slider* Mass = new Slider("Mass", 0, 10); |
---|
329 | Mass->setExactness(2); |
---|
330 | Mass->connectSignal("value_changed", (void*)Mass, systemChange ); |
---|
331 | Mass->setValue(PINIT_PARTICLE_MASS); |
---|
332 | Mass->redraw(); |
---|
333 | systemBox->fill(Mass); |
---|
334 | |
---|
335 | |
---|
336 | systemBox->fill(new Label("LifeSpan")); |
---|
337 | Slider* LifeSpan = new Slider("LifeSpan", 0, 10); |
---|
338 | LifeSpan->setExactness(3); |
---|
339 | LifeSpan->connectSignal("value_changed", (void*)LifeSpan, systemChange ); |
---|
340 | LifeSpan->setValue(PINIT_LIFESPAN); |
---|
341 | LifeSpan->redraw(); |
---|
342 | systemBox->fill(LifeSpan); |
---|
343 | |
---|
344 | systemBox->fill(new Label("ConserveFactor")); |
---|
345 | Slider* ConserveFactor = new Slider("ConserveFactor", 0, 1); |
---|
346 | ConserveFactor->setExactness(3); |
---|
347 | ConserveFactor->connectSignal("value_changed", (void*)ConserveFactor, systemChange ); |
---|
348 | ConserveFactor->setValue(PINIT_CONSERVE_FACTOR); |
---|
349 | ConserveFactor->redraw(); |
---|
350 | systemBox->fill(ConserveFactor); |
---|
351 | |
---|
352 | systemBox->fill(new Label("ParticleType")); |
---|
353 | Menu* ParticleType = new Menu("ParticleType"); |
---|
354 | ParticleType->addItem("PARTICLE_DOT"); |
---|
355 | ParticleType->addItem("PARTICLE_SPARK"); |
---|
356 | ParticleType->addItem("PARTICLE_SPRITE"); |
---|
357 | ParticleType->connectSignal("changed", (void*)ParticleType, systemChange ); |
---|
358 | ParticleType->load("PARTICLE_SPRITE"); |
---|
359 | systemBox->fill(ParticleType); |
---|
360 | |
---|
361 | systemBox->fill(new Label("InheritSpeed")); |
---|
362 | Slider* InheritSpeed = new Slider("InheritSpeed", 0, 1); |
---|
363 | InheritSpeed->setExactness(3); |
---|
364 | InheritSpeed->connectSignal("value_changed", (void*)InheritSpeed, systemChange ); |
---|
365 | systemBox->fill(InheritSpeed); |
---|
366 | |
---|
367 | Button* RandomColor = new Button("RandomColor"); |
---|
368 | RandomColor->connectSignal("released", (void*)RandomColor, systemChange); |
---|
369 | systemBox->fill(RandomColor); |
---|
370 | |
---|
371 | } |
---|
372 | systemFrame->fill(systemBox); |
---|
373 | } |
---|
374 | windowBox->fill(systemFrame); |
---|
375 | |
---|
376 | Frame* fieldsFrame = new Frame("Field-Settings"); |
---|
377 | { |
---|
378 | Box* fieldsBox = new Box('v'); |
---|
379 | { |
---|
380 | fieldsBox->fill(new Label("Gravity")); |
---|
381 | Slider* Gravity = new Slider("Gravity", 0, 10); |
---|
382 | Gravity->setExactness(1); |
---|
383 | Gravity->connectSignal("value_changed", (void*)Gravity, fieldsChange ); |
---|
384 | Gravity->setValue(0); |
---|
385 | Gravity->redraw(); |
---|
386 | fieldsBox->fill(Gravity); |
---|
387 | |
---|
388 | |
---|
389 | fieldsBox->fill(new Label("Twirl")); |
---|
390 | Slider* Twirl = new Slider("Twirl", 0, 10); |
---|
391 | Twirl->setExactness(1); |
---|
392 | Twirl->connectSignal("value_changed", (void*)Twirl, fieldsChange ); |
---|
393 | Twirl->setValue(0); |
---|
394 | Twirl->redraw(); |
---|
395 | fieldsBox->fill(Twirl); |
---|
396 | |
---|
397 | |
---|
398 | fieldsBox->fill(new Label("PointGravity")); |
---|
399 | Slider* PointGravity = new Slider("PointGravity", 0, 10); |
---|
400 | PointGravity->setExactness(1); |
---|
401 | PointGravity->connectSignal("value_changed", (void*)PointGravity, fieldsChange ); |
---|
402 | PointGravity->setValue(0); |
---|
403 | PointGravity->redraw(); |
---|
404 | fieldsBox->fill(PointGravity); |
---|
405 | |
---|
406 | } |
---|
407 | fieldsFrame->fill(fieldsBox); |
---|
408 | } |
---|
409 | windowBox->fill(fieldsFrame); |
---|
410 | |
---|
411 | Button* quitButton = new Button("quit"); |
---|
412 | |
---|
413 | quitButton->connectSignal("clicked", NULL, quitGui); |
---|
414 | // Window::mainWindow->connectSignal("remove", this, GuiExec::quitGui); |
---|
415 | Window::mainWindow->connectSignal("destroy", NULL, quitGui); |
---|
416 | windowBox->fill(quitButton); |
---|
417 | |
---|
418 | } |
---|
419 | guiMainWindow->fill(windowBox); |
---|
420 | } |
---|
421 | Window::mainWindow->showall(); |
---|
422 | Window::mainWindow->setSize(300, 500); |
---|
423 | } |
---|