Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/physics: now the modular it is :)

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