Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/physics/src/subprojects/particles/particle_fun.cc @ 4334

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

orxonox/braches/physics: more modular, with eventHandler

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