Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: now one can easily define all the initial values via macros

File size: 9.8 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
23#define PINIT_EMISSION_RATE          50
24#define PINIT_EMISSION_VELOCITY      5.0
25#define PINIT_SPREAD_ANGLE           0.1
26#define PINIT_EMITTER_TYPE           EMITTER_DOT
27#define PINIT_EMITTER_SIZE           1.0
28#define PINIT_START_RADIUS           5.0
29#define PINIT_END_RADIUS             0.0
30#define PINIT_LIFESPAN               1.0
31#define PINIT_CONSERVE_FACTOR        1.0
32#define PINIT_PARTICLE_TYPE          PARTICLE_SPRITE
33#define PINIT_INHERIT_SPEED          0.0
34
35
36void Framework::moduleInit(int argc, char** argv)
37{
38  // Creating a Test Particle System
39  ParticleSystem* system = new ParticleSystem(100000, PINIT_PARTICLE_TYPE);
40  system->setRadius(PINIT_START_RADIUS, PINIT_END_RADIUS ,0 ,0);
41  system->setLifeSpan(PINIT_LIFESPAN);
42  system->setConserve(PINIT_CONSERVE_FACTOR);
43
44  // Creating a Test Particle Emitter
45  ParticleEmitter* emitter = new ParticleEmitter(Vector(0 , 1, 0));
46  emitter->setEmissionRate(PINIT_EMISSION_RATE);
47  emitter->setEmissionVelocity(PINIT_EMISSION_VELOCITY ,0);
48  emitter->setSpread(PINIT_SPREAD_ANGLE ,0);
49  emitter->setType(PINIT_EMITTER_TYPE);
50  emitter->setSize(PINIT_EMITTER_SIZE);
51  // Add the Flow from the Emitter into the System
52  ParticleEngine::getInstance()->addConnection(emitter, system);
53}
54
55void Framework::moduleEventHandler(SDL_Event* event)
56{
57  switch (event->type)
58    {
59    case SDL_KEYDOWN:
60      switch (event->key.keysym.sym)
61        {
62        case SDLK_i:
63          ParticleEngine::getInstance()->debug();
64          break;
65        }
66    }
67}
68
69void Framework::moduleTick(float dt)
70{
71  ParticleEngine::getInstance()->tick(dt);
72}
73
74void Framework::moduleDraw() const
75{
76  ParticleEngine::getInstance()->draw();
77}
78
79
80void Framework::moduleHelp(void) const
81{
82  PRINT(0)("\n");
83  PRINT(0)("i - Particle-state Information\n\n");
84  PRINT(0)("\n");
85
86}
87
88int emitterChange(GtkWidget* nonInterest, void* widget)
89{
90  Option* option = (Option*) widget;
91  const char* name = option->getTitle();
92  char* value = option->save();
93
94  ParticleEmitter* tmpEmit = ParticleEngine::getInstance()->getEmitterByNumber(1);
95  if (tmpEmit)
96    {
97      if (!strcmp(name, "EmissionRate"))
98        {
99          tmpEmit->setEmissionRate(atof(value));
100          PRINT(3)("EmissionRate set to %f\n", atof(value));
101        }
102      else if (!strcmp(name, "Velocity"))
103        {
104          tmpEmit->setEmissionVelocity(atof(value));
105          PRINT(3)("Velocity set to %f\n", atof(value));
106        }
107      else if(!strcmp(name, "SpreadAngle"))
108        {
109          tmpEmit->setSpread(atof(value));
110          PRINT(3)("SpreadAngle set to %f\n", atof(value));
111        }
112      else if(!strcmp(name, "EmitterType"))
113        {
114          if (!strcmp(value, "EMITTER_DOT"))
115            tmpEmit->setType(EMITTER_DOT);
116          else if (!strcmp(value, "EMITTER_PLANE"))
117            tmpEmit->setType(EMITTER_PLANE);
118          else if (!strcmp(value, "EMITTER_CUBE"))
119            tmpEmit->setType(EMITTER_CUBE);
120          PRINT(3)("EmitterType set to %s\n", value);
121        }
122      else if(!strcmp(name, "EmitterSize"))
123        {
124          tmpEmit->setSize(atof(value));
125          PRINT(3)("EmitterSize set to %f\n", atof(value));
126        }
127    }
128  delete value;
129}
130
131
132int systemChange(GtkWidget* nonInterest, void* widget)
133{
134  Option* option = (Option*) widget;
135  const char* name = option->getTitle();
136  char* value = option->save();
137
138  ParticleSystem* tmpSys = ParticleEngine::getInstance()->getSystemByNumber(1);
139  if (tmpSys)
140    {
141      if (!strcmp(name, "StartRadius"))
142        {
143          tmpSys->setRadius(atof(value), tmpSys->getEndRadius());
144          PRINT(3)("ParticleStartRadius set to %f\n", atof(value));
145        }
146      else if (!strcmp(name, "EndRadius"))
147        {
148          tmpSys->setRadius( tmpSys->getStartRadius(), atof(value));
149          PRINT(3)("ParticleEndRadius set to %f\n", atof(value));
150        }
151
152      else if (!strcmp(name, "LifeSpan"))
153        {
154          tmpSys->setLifeSpan(atof(value));
155          PRINT(3)("ParticleLifeSpan set to %f\n", atof(value));
156        }
157
158      else if (!strcmp(name, "ConserveFactor"))
159        {
160          tmpSys->setConserve(atof(value));
161          PRINT(3)("ParticleConserveFactor set to %f\n", atof(value));
162        }
163
164      else if (!strcmp(name, "ParticleType"))
165        {
166          if (!strcmp(value, "PARTICLE_DOT"))
167            tmpSys->setType(PARTICLE_DOT);
168          else if (!strcmp(value, "PARTICLE_SPARK"))
169            tmpSys->setType(PARTICLE_SPARK);
170          else if (!strcmp(value, "PARTICLE_SPRITE"))
171            tmpSys->setType(PARTICLE_SPRITE);
172
173          PRINT(3)("ParticleType set to %s\n", value);
174        }
175
176      else if (!strcmp(name, "InheritSpeed"))
177        {
178          tmpSys->setInheritSpeed(atof(value));
179          PRINT(3)("ParticleInheritSpeed set to %f\n", atof(value));
180        }
181      else if (!strcmp(name, "RandomColor"))
182        {
183          tmpSys->setColor((float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, 1, 
184                           (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, .5, 
185                           (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, 0);
186        }
187    }
188  delete value;
189}
190
191
192void Framework::moduleInitGui(int argc, char** argv)
193{
194  Window* guiMainWindow = NULL;
195 
196  initGUI(0, NULL);
197 
198  guiMainWindow = new Window("ParticlesFUN");
199  {
200    Box* windowBox = new Box('v');
201    {
202      Frame* emitterFrame = new Frame("emitter-settings");
203      {
204        Box* emitterBox = new Box('v');
205        {
206          emitterBox->fill(new Label("EmissionRate"));
207          Slider* EmissionRate = new Slider("EmissionRate", 0, 1000);
208          EmissionRate->connectSignal("value_changed", (void*)EmissionRate, emitterChange );
209          EmissionRate->setValue(PINIT_EMISSION_RATE);
210          EmissionRate->redraw();
211          emitterBox->fill(EmissionRate);
212         
213          emitterBox->fill(new Label("Velocity"));
214          Slider* velocity = new Slider("Velocity", 0, 20);
215          velocity->setExactness(2);
216          velocity->connectSignal("value_changed", (void*)velocity, emitterChange );
217          velocity->setValue(PINIT_EMISSION_VELOCITY);
218          velocity->redraw();
219          emitterBox->fill(velocity);
220         
221          emitterBox->fill(new Label("SpreadAngle"));
222          Slider* SpreadAngle = new Slider("SpreadAngle", 0, M_PI);
223          SpreadAngle->setExactness(3);
224          SpreadAngle->connectSignal("value_changed", (void*)SpreadAngle, emitterChange );
225          SpreadAngle->setValue(PINIT_SPREAD_ANGLE);
226          SpreadAngle->redraw();
227          emitterBox->fill(SpreadAngle);
228
229          emitterBox->fill(new Label("EmitterType"));
230          Menu* EmitterType = new Menu("EmitterType");
231          EmitterType->addItem("EMITTER_DOT");
232          EmitterType->addItem("EMITTER_PLANE");
233          EmitterType->addItem("EMITTER_CUBE");
234          EmitterType->connectSignal("changed", (void*)EmitterType, emitterChange );
235          EmitterType->load("EMITTER_DOT");
236          emitterBox->fill(EmitterType);
237
238          emitterBox->fill(new Label("EmitterSize"));
239          Slider* EmitterSize = new Slider("EmitterSize", 0, 100);
240          EmitterSize->setExactness(1);
241          EmitterSize->connectSignal("value_changed", (void*)EmitterSize, emitterChange );
242          EmitterSize->setValue(PINIT_EMITTER_SIZE);
243          EmitterSize->redraw();
244          emitterBox->fill(EmitterSize);
245        }
246        emitterFrame->fill(emitterBox);
247      }
248      windowBox->fill(emitterFrame);
249     
250      Frame* systemFrame = new Frame("system-settings");
251      {
252        Box* systemBox = new Box('v');
253        {
254          systemBox->fill(new Label("StartRadius"));
255          Slider* StartRadius = new Slider("StartRadius", 0, 10);
256          StartRadius->setExactness(3);
257          StartRadius->connectSignal("value_changed", (void*)StartRadius, systemChange );
258          StartRadius->setValue(PINIT_START_RADIUS);
259          StartRadius->redraw();
260          systemBox->fill(StartRadius);
261
262          systemBox->fill(new Label("EndRadius"));
263          Slider* EndRadius = new Slider("EndRadius", 0, 10);
264          EndRadius->setExactness(3);
265          EndRadius->connectSignal("value_changed", (void*)EndRadius, systemChange );
266          EndRadius->setValue(PINIT_END_RADIUS);
267          EndRadius->redraw();
268          systemBox->fill(EndRadius);
269
270          systemBox->fill(new Label("LifeSpan"));
271          Slider* LifeSpan = new Slider("LifeSpan", 0, 10);
272          LifeSpan->setExactness(3);
273          LifeSpan->connectSignal("value_changed", (void*)LifeSpan, systemChange );
274          LifeSpan->setValue(PINIT_LIFESPAN);
275          LifeSpan->redraw();
276          systemBox->fill(LifeSpan);
277         
278          systemBox->fill(new Label("ConserveFactor"));
279          Slider* ConserveFactor = new Slider("ConserveFactor", 0, 1);
280          ConserveFactor->setExactness(3);
281          ConserveFactor->connectSignal("value_changed", (void*)ConserveFactor, systemChange );
282          ConserveFactor->setValue(PINIT_CONSERVE_FACTOR);
283          ConserveFactor->redraw();
284          systemBox->fill(ConserveFactor);
285
286          systemBox->fill(new Label("ParticleType"));
287          Menu* ParticleType = new Menu("ParticleType");
288          ParticleType->addItem("PARTICLE_DOT");
289          ParticleType->addItem("PARTICLE_SPARK");
290          ParticleType->addItem("PARTICLE_SPRITE");
291          ParticleType->connectSignal("changed", (void*)ParticleType, systemChange );     
292          ParticleType->load("PARTICLE_SPRITE");
293          systemBox->fill(ParticleType);
294         
295          systemBox->fill(new Label("InheritSpeed"));
296          Slider* InheritSpeed = new Slider("InheritSpeed", 0, 1);
297          InheritSpeed->setExactness(3);
298          InheritSpeed->connectSignal("value_changed", (void*)InheritSpeed, systemChange );
299          systemBox->fill(InheritSpeed);
300
301          Button* RandomColor = new Button("RandomColor");
302          RandomColor->connectSignal("released", (void*)RandomColor, systemChange);
303          systemBox->fill(RandomColor);
304
305        }
306        systemFrame->fill(systemBox);
307      }
308      windowBox->fill(systemFrame);
309     
310      Button* quitButton = new Button("quit");
311     
312      quitButton->connectSignal("clicked", NULL, quitGui);
313      //  Window::mainWindow->connectSignal("remove", this, GuiExec::quitGui);
314      Window::mainWindow->connectSignal("destroy", NULL, quitGui);
315     
316      windowBox->fill(quitButton);
317    }
318    guiMainWindow->fill(windowBox);
319  }
320  Window::mainWindow->showall();
321  Window::mainWindow->setSize(300, 500);
322}
Note: See TracBrowser for help on using the repository browser.