Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: made include more local. stdincl.h not in base_object.h anymore

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