Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/subprojects/particles/particle_fun.cc @ 4639

Last change on this file since 4639 was 4639, checked in by bensch, 19 years ago

orxonox/trunk: particleFun draws some Particles again

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