Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: objModel's materials should now automatically load textures

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