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