Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/physics: segfault-prevention

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