- Timestamp:
- Jun 7, 2005, 9:14:18 AM (19 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/subprojects/collision_detection/collision_detection.cc
r4529 r4530 18 18 #include "framework.h" 19 19 20 #include "physics_engine.h"21 #include "particle_engine.h"22 20 #include "fields.h" 23 21 #include "stdlibincl.h" 24 22 25 #define PINIT_EMISSION_RATE 5026 #define PINIT_EMISSION_VELOCITY 5.027 #define PINIT_SPREAD_ANGLE 0.128 #define PINIT_EMITTER_TYPE EMITTER_DOT29 #define PINIT_EMITTER_SIZE 1.030 #define PINIT_START_RADIUS 5.031 #define PINIT_END_RADIUS 0.032 #define PINIT_LIFESPAN 1.033 #define PINIT_CONSERVE_FACTOR 1.034 #define PINIT_PARTICLE_TYPE PARTICLE_SPRITE35 #define PINIT_INHERIT_SPEED 0.036 #define PINIT_PARTICLE_MASS 1.037 38 39 Field* twirl;40 Field* gravity;41 Field* pointGravity;42 23 43 24 void Framework::moduleInit(int argc, char** argv) 44 25 { 45 verbose = 5;46 ParticleEngine::getInstance();47 PhysicsEngine::getInstance();48 49 50 // Creating a Test Particle System51 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 Emitter57 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 System65 ParticleEngine::getInstance()->addConnection(emitter, system);66 67 68 twirl = new Twirl();69 twirl->setMagnitude(0);70 gravity = new Gravity();71 gravity->setMagnitude(0);72 pointGravity = new PointGravity();73 pointGravity->setMagnitude(0);74 75 new PhysicsConnection(system, gravity);76 new PhysicsConnection(system, twirl);77 new PhysicsConnection(system, pointGravity);78 26 } 79 27 … … 86 34 { 87 35 case SDLK_i: 88 ParticleEngine::getInstance()->debug();89 PhysicsEngine::getInstance()->debug();90 36 break; 91 37 } … … 95 41 void Framework::moduleTick(float dt) 96 42 { 97 PhysicsEngine::getInstance()->tick(dt);98 ParticleEngine::getInstance()->tick(dt);99 43 } 100 44 101 45 void Framework::moduleDraw() const 102 46 { 103 ParticleEngine::getInstance()->draw();104 47 } 105 48 … … 108 51 { 109 52 PRINT(0)("\n"); 110 PRINT(0)("i - Particle-state Information\n\n");53 PRINT(0)("i - print debug information of Collision-detection\n"); 111 54 PRINT(0)("\n"); 112 }113 114 int emitterChange(GtkWidget* nonInterest, void* widget)115 {116 Option* option = (Option*) widget;117 const char* name = option->getTitle();118 char* value = option->save();119 120 ParticleEmitter* tmpEmit = ParticleEngine::getInstance()->getEmitterByNumber(1);121 if (tmpEmit)122 {123 if (!strcmp(name, "EmissionRate"))124 {125 tmpEmit->setEmissionRate(atof(value));126 PRINT(4)("EmissionRate set to %f\n", atof(value));127 }128 else if (!strcmp(name, "Velocity"))129 {130 tmpEmit->setEmissionVelocity(atof(value));131 PRINT(4)("Velocity set to %f\n", atof(value));132 }133 else if(!strcmp(name, "SpreadAngle"))134 {135 tmpEmit->setSpread(atof(value), 0);136 PRINT(4)("SpreadAngle set to %f\n", atof(value));137 }138 else if(!strcmp(name, "EmitterType"))139 {140 if (!strcmp(value, "EMITTER_DOT"))141 tmpEmit->setType(EMITTER_DOT);142 else if (!strcmp(value, "EMITTER_PLANE"))143 tmpEmit->setType(EMITTER_PLANE);144 else if (!strcmp(value, "EMITTER_CUBE"))145 tmpEmit->setType(EMITTER_CUBE);146 PRINT(4)("EmitterType set to %s\n", value);147 }148 else if(!strcmp(name, "EmitterSize"))149 {150 tmpEmit->setSize(atof(value));151 PRINT(4)("EmitterSize set to %f\n", atof(value));152 }153 }154 delete value;155 }156 157 158 int systemChange(GtkWidget* nonInterest, void* widget)159 {160 Option* option = (Option*) widget;161 const char* name = option->getTitle();162 char* value = option->save();163 164 ParticleSystem* tmpSys = ParticleEngine::getInstance()->getSystemByNumber(1);165 if (tmpSys)166 {167 if (!strcmp(name, "StartRadius"))168 {169 tmpSys->setRadius(atof(value), tmpSys->getEndRadius());170 PRINT(4)("ParticleStartRadius set to %f\n", atof(value));171 }172 else if (!strcmp(name, "EndRadius"))173 {174 tmpSys->setRadius( tmpSys->getStartRadius(), atof(value));175 PRINT(4)("ParticleEndRadius set to %f\n", atof(value));176 }177 178 else if (!strcmp(name, "LifeSpan"))179 {180 tmpSys->setLifeSpan(atof(value));181 PRINT(4)("ParticleLifeSpan set to %f\n", atof(value));182 }183 184 else if (!strcmp(name, "Mass"))185 {186 tmpSys->setMass(atof(value));187 PRINT(4)("ParticleMass set to %f\n", atof(value));188 }189 190 else if (!strcmp(name, "ConserveFactor"))191 {192 tmpSys->setConserve(atof(value));193 PRINT(4)("ParticleConserveFactor set to %f\n", atof(value));194 }195 196 else if (!strcmp(name, "ParticleType"))197 {198 if (!strcmp(value, "PARTICLE_DOT"))199 tmpSys->setType(PARTICLE_DOT);200 else if (!strcmp(value, "PARTICLE_SPARK"))201 tmpSys->setType(PARTICLE_SPARK);202 else if (!strcmp(value, "PARTICLE_SPRITE"))203 tmpSys->setType(PARTICLE_SPRITE);204 205 PRINT(4)("ParticleType set to %s\n", value);206 }207 208 else if (!strcmp(name, "InheritSpeed"))209 {210 tmpSys->setInheritSpeed(atof(value));211 PRINT(4)("ParticleInheritSpeed set to %f\n", atof(value));212 }213 else if (!strcmp(name, "RandomColor"))214 {215 tmpSys->setColor((float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, 1,216 (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, .5,217 (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, 0);218 }219 }220 delete value;221 }222 223 int fieldsChange(GtkWidget* nonInterest, void* widget)224 {225 Option* option = (Option*) widget;226 const char* name = option->getTitle();227 char* value = option->save();228 229 230 if (!strcmp(name, "Gravity"))231 {232 gravity->setMagnitude(atof(value));233 }234 235 else if (!strcmp(name, "Twirl"))236 {237 twirl->setMagnitude(atof(value));238 }239 240 else if (!strcmp(name, "PointGravity"))241 {242 pointGravity->setMagnitude(atof(value));243 }244 245 55 } 246 56 … … 251 61 initGUI(0, NULL); 252 62 253 guiMainWindow = new Window(" ParticlesFUN");63 guiMainWindow = new Window("Collision_detection"); 254 64 { 255 Box* windowBox = new Box('h'); 256 { 257 Frame* emitterFrame = new Frame("emitter-settings"); 258 { 259 Box* emitterBox = new Box('v'); 260 { 261 emitterBox->fill(new Label("EmissionRate")); 262 Slider* EmissionRate = new Slider("EmissionRate", 0, 1000); 263 EmissionRate->connectSignal("value_changed", (void*)EmissionRate, emitterChange ); 264 EmissionRate->setValue(PINIT_EMISSION_RATE); 265 EmissionRate->redraw(); 266 emitterBox->fill(EmissionRate); 267 268 emitterBox->fill(new Label("Velocity")); 269 Slider* velocity = new Slider("Velocity", 0, 20); 270 velocity->setExactness(2); 271 velocity->connectSignal("value_changed", (void*)velocity, emitterChange ); 272 velocity->setValue(PINIT_EMISSION_VELOCITY); 273 velocity->redraw(); 274 emitterBox->fill(velocity); 275 276 emitterBox->fill(new Label("SpreadAngle")); 277 Slider* SpreadAngle = new Slider("SpreadAngle", 0, M_PI); 278 SpreadAngle->setExactness(3); 279 SpreadAngle->connectSignal("value_changed", (void*)SpreadAngle, emitterChange ); 280 SpreadAngle->setValue(PINIT_SPREAD_ANGLE); 281 SpreadAngle->redraw(); 282 emitterBox->fill(SpreadAngle); 283 284 emitterBox->fill(new Label("EmitterType")); 285 Menu* EmitterType = new Menu("EmitterType"); 286 EmitterType->addItem("EMITTER_DOT"); 287 EmitterType->addItem("EMITTER_PLANE"); 288 EmitterType->addItem("EMITTER_CUBE"); 289 EmitterType->connectSignal("changed", (void*)EmitterType, emitterChange ); 290 EmitterType->load("EMITTER_DOT"); 291 emitterBox->fill(EmitterType); 292 293 emitterBox->fill(new Label("EmitterSize")); 294 Slider* EmitterSize = new Slider("EmitterSize", 0, 100); 295 EmitterSize->setExactness(1); 296 EmitterSize->connectSignal("value_changed", (void*)EmitterSize, emitterChange ); 297 EmitterSize->setValue(PINIT_EMITTER_SIZE); 298 EmitterSize->redraw(); 299 emitterBox->fill(EmitterSize); 300 } 301 emitterFrame->fill(emitterBox); 302 } 303 windowBox->fill(emitterFrame); 304 305 Frame* systemFrame = new Frame("system-settings"); 306 { 307 Box* systemBox = new Box('v'); 308 { 309 systemBox->fill(new Label("StartRadius")); 310 Slider* StartRadius = new Slider("StartRadius", 0, 10); 311 StartRadius->setExactness(3); 312 StartRadius->connectSignal("value_changed", (void*)StartRadius, systemChange ); 313 StartRadius->setValue(PINIT_START_RADIUS); 314 StartRadius->redraw(); 315 systemBox->fill(StartRadius); 316 317 systemBox->fill(new Label("EndRadius")); 318 Slider* EndRadius = new Slider("EndRadius", 0, 10); 319 EndRadius->setExactness(3); 320 EndRadius->connectSignal("value_changed", (void*)EndRadius, systemChange ); 321 EndRadius->setValue(PINIT_END_RADIUS); 322 EndRadius->redraw(); 323 systemBox->fill(EndRadius); 324 325 systemBox->fill(new Label("ParticleMass")); 326 Slider* Mass = new Slider("Mass", 0, 10); 327 Mass->setExactness(2); 328 Mass->connectSignal("value_changed", (void*)Mass, systemChange ); 329 Mass->setValue(PINIT_PARTICLE_MASS); 330 Mass->redraw(); 331 systemBox->fill(Mass); 332 333 334 systemBox->fill(new Label("LifeSpan")); 335 Slider* LifeSpan = new Slider("LifeSpan", 0, 10); 336 LifeSpan->setExactness(3); 337 LifeSpan->connectSignal("value_changed", (void*)LifeSpan, systemChange ); 338 LifeSpan->setValue(PINIT_LIFESPAN); 339 LifeSpan->redraw(); 340 systemBox->fill(LifeSpan); 341 342 systemBox->fill(new Label("ConserveFactor")); 343 Slider* ConserveFactor = new Slider("ConserveFactor", 0, 1); 344 ConserveFactor->setExactness(3); 345 ConserveFactor->connectSignal("value_changed", (void*)ConserveFactor, systemChange ); 346 ConserveFactor->setValue(PINIT_CONSERVE_FACTOR); 347 ConserveFactor->redraw(); 348 systemBox->fill(ConserveFactor); 349 350 systemBox->fill(new Label("ParticleType")); 351 Menu* ParticleType = new Menu("ParticleType"); 352 ParticleType->addItem("PARTICLE_DOT"); 353 ParticleType->addItem("PARTICLE_SPARK"); 354 ParticleType->addItem("PARTICLE_SPRITE"); 355 ParticleType->connectSignal("changed", (void*)ParticleType, systemChange ); 356 ParticleType->load("PARTICLE_SPRITE"); 357 systemBox->fill(ParticleType); 358 359 systemBox->fill(new Label("InheritSpeed")); 360 Slider* InheritSpeed = new Slider("InheritSpeed", 0, 1); 361 InheritSpeed->setExactness(3); 362 InheritSpeed->connectSignal("value_changed", (void*)InheritSpeed, systemChange ); 363 systemBox->fill(InheritSpeed); 364 365 Button* RandomColor = new Button("RandomColor"); 366 RandomColor->connectSignal("released", (void*)RandomColor, systemChange); 367 systemBox->fill(RandomColor); 368 369 } 370 systemFrame->fill(systemBox); 371 } 372 windowBox->fill(systemFrame); 373 374 Frame* fieldsFrame = new Frame("Field-Settings"); 375 { 376 Box* fieldsBox = new Box('v'); 377 { 378 fieldsBox->fill(new Label("Gravity")); 379 Slider* Gravity = new Slider("Gravity", 0, 10); 380 Gravity->setExactness(1); 381 Gravity->connectSignal("value_changed", (void*)Gravity, fieldsChange ); 382 Gravity->setValue(0); 383 Gravity->redraw(); 384 fieldsBox->fill(Gravity); 385 386 387 fieldsBox->fill(new Label("Twirl")); 388 Slider* Twirl = new Slider("Twirl", 0, 10); 389 Twirl->setExactness(1); 390 Twirl->connectSignal("value_changed", (void*)Twirl, fieldsChange ); 391 Twirl->setValue(0); 392 Twirl->redraw(); 393 fieldsBox->fill(Twirl); 394 395 396 fieldsBox->fill(new Label("PointGravity")); 397 Slider* PointGravity = new Slider("PointGravity", 0, 10); 398 PointGravity->setExactness(1); 399 PointGravity->connectSignal("value_changed", (void*)PointGravity, fieldsChange ); 400 PointGravity->setValue(0); 401 PointGravity->redraw(); 402 fieldsBox->fill(PointGravity); 403 404 } 405 fieldsFrame->fill(fieldsBox); 406 } 407 windowBox->fill(fieldsFrame); 408 409 Button* quitButton = new Button("quit"); 410 411 quitButton->connectSignal("clicked", NULL, quitGui); 412 // Window::mainWindow->connectSignal("remove", this, GuiExec::quitGui); 413 Window::mainWindow->connectSignal("destroy", NULL, quitGui); 414 windowBox->fill(quitButton); 415 416 } 417 guiMainWindow->fill(windowBox); 65 // all the Widgets you need 418 66 } 419 67 Window::mainWindow->showall();
Note: See TracChangeset
for help on using the changeset viewer.