/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Benjamin Grauer co-programmer: ... this file extends the framework file, so it renders what i want. */ #include "framework.h" #include "physics_engine.h" #include "particle_engine.h" #include "fields.h" #include "stdlibincl.h" #include "graphics_engine.h" #include #define PINIT_EMISSION_RATE 50 #define PINIT_EMISSION_VELOCITY 5.0 #define PINIT_SPREAD_ANGLE 0.1 #define PINIT_EMITTER_TYPE EMITTER_DOT #define PINIT_EMITTER_SIZE 1.0 #define PINIT_START_RADIUS 5.0 #define PINIT_END_RADIUS 0.0 #define PINIT_LIFESPAN 1.0 #define PINIT_CONSERVE_FACTOR 1.0 #define PINIT_PARTICLE_TYPE PARTICLE_SPRITE #define PINIT_INHERIT_SPEED 0.0 #define PINIT_PARTICLE_MASS 1.0 #define PINIT_MODEL_DIRECTORY "models/" Field* twirl; Field* gravity; Field* pointGravity; void Framework::moduleInit(int argc, char** argv) { GraphicsEngine::getInstance()->setWindowName("ParticlesFun", "particles"); verbose = 5; ParticleEngine::getInstance(); PhysicsEngine::getInstance(); // Creating a Test Particle System ParticleSystem* system = new ParticleSystem(100000, PINIT_PARTICLE_TYPE); system->setRadius(0, PINIT_START_RADIUS, 0 ); system->setRadius(1, PINIT_END_RADIUS, 0 ); system->setLifeSpan(PINIT_LIFESPAN); system->setConserve(PINIT_CONSERVE_FACTOR); //system->setMass(5,3,6); // Creating a Test Particle Emitter ParticleEmitter* emitter = new ParticleEmitter(Vector(0 , 1, 0)); emitter->setEmissionRate(PINIT_EMISSION_RATE); emitter->setEmissionVelocity(PINIT_EMISSION_VELOCITY ,0); emitter->setSpread(PINIT_SPREAD_ANGLE ,0); emitter->setType(PINIT_EMITTER_TYPE); emitter->setSize(PINIT_EMITTER_SIZE); emitter->setAbsCoor(Vector(3,0,0)); // Add the Flow from the Emitter into the System ParticleEngine::getInstance()->addConnection(emitter, system); twirl = new Twirl(); twirl->setMagnitude(0); gravity = new Gravity(); gravity->setMagnitude(0); pointGravity = new PointGravity(); pointGravity->setMagnitude(0); new PhysicsConnection(system, gravity); new PhysicsConnection(system, twirl); new PhysicsConnection(system, pointGravity); } void Framework::moduleEventHandler(SDL_Event* event) { switch (event->type) { case SDL_KEYDOWN: switch (event->key.keysym.sym) { case SDLK_i: ParticleEngine::getInstance()->debug(); PhysicsEngine::getInstance()->debug(); break; } } } void Framework::moduleTick(float dt) { PhysicsEngine::getInstance()->tick(dt); ParticleEngine::getInstance()->tick(dt); } void Framework::moduleDraw() const { ParticleEngine::getInstance()->draw(); } void Framework::moduleHelp(void) const { PRINT(0)("\n"); PRINT(0)("i - Particle-state Information\n\n"); PRINT(0)("\n"); } int emitterChange(GtkWidget* nonInterest, void* widget) { Option* option = (Option*) widget; const char* name = option->getTitle(); char* value = option->save(); ParticleEmitter* tmpEmit = ParticleEngine::getInstance()->getEmitterByNumber(1); if (tmpEmit) { if (!strcmp(name, "EmissionRate")) { tmpEmit->setEmissionRate(atof(value)); PRINT(4)("EmissionRate set to %f\n", atof(value)); } else if (!strcmp(name, "Velocity")) { tmpEmit->setEmissionVelocity(atof(value)); PRINT(4)("Velocity set to %f\n", atof(value)); } else if(!strcmp(name, "SpreadAngle")) { tmpEmit->setSpread(atof(value), 0); PRINT(4)("SpreadAngle set to %f\n", atof(value)); } else if(!strcmp(name, "EmitterType")) { if (!strcmp(value, "EMITTER_DOT")) tmpEmit->setType(EMITTER_DOT); else if (!strcmp(value, "EMITTER_PLANE")) tmpEmit->setType(EMITTER_PLANE); else if (!strcmp(value, "EMITTER_CUBE")) tmpEmit->setType(EMITTER_CUBE); PRINT(4)("EmitterType set to %s\n", value); } else if(!strcmp(name, "EmitterSize")) { tmpEmit->setSize(atof(value)); PRINT(4)("EmitterSize set to %f\n", atof(value)); } else if (!strcmp(name, "InheritSpeed")) { tmpEmit->setInheritSpeed(atof(value)); PRINT(4)("ParticleInheritSpeed set to %f\n", atof(value)); } } delete value; } int systemChange(GtkWidget* nonInterest, void* widget) { Option* option = (Option*) widget; const char* name = option->getTitle(); char* value = option->save(); ParticleSystem* tmpSys = ParticleEngine::getInstance()->getSystemByNumber(1); if (tmpSys) { if (!strcmp(name, "StartRadius")) { tmpSys->setRadius(0, atof(value)); PRINT(4)("ParticleStartRadius set to %f\n", atof(value)); } else if (!strcmp(name, "EndRadius")) { tmpSys->setRadius( 1, atof(value)); PRINT(4)("ParticleEndRadius set to %f\n", atof(value)); } else if (!strcmp(name, "LifeSpan")) { tmpSys->setLifeSpan(atof(value)); PRINT(4)("ParticleLifeSpan set to %f\n", atof(value)); } else if (!strcmp(name, "Mass")) { tmpSys->setMass(0, atof(value)); PRINT(4)("ParticleMass set to %f\n", atof(value)); } else if (!strcmp(name, "ConserveFactor")) { tmpSys->setConserve(atof(value)); PRINT(4)("ParticleConserveFactor set to %f\n", atof(value)); } else if (!strcmp(name, "ParticleType")) { if (!strcmp(value, "PARTICLE_DOT")) tmpSys->setType(PARTICLE_DOT); else if (!strcmp(value, "PARTICLE_SPARK")) tmpSys->setType(PARTICLE_SPARK); else if (!strcmp(value, "PARTICLE_SPRITE")) tmpSys->setType(PARTICLE_SPRITE); PRINT(4)("ParticleType set to %s\n", value); } else if(!strcmp(name, "ParticleModel")) { char* modelName = new char[strlen(PINIT_MODEL_DIRECTORY) + strlen(value)+1]; sprintf(modelName, "%s%s", PINIT_MODEL_DIRECTORY, value); tmpSys->setModel(ResourceManager::getFullName(modelName)); delete modelName; } else if (!strcmp(name, "RandomColor")) { tmpSys->setColor(0, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, 1); tmpSys->setColor(.5, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, .5); tmpSys->setColor(.5, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, 0); } } delete value; } int fieldsChange(GtkWidget* nonInterest, void* widget) { Option* option = (Option*) widget; const char* name = option->getTitle(); char* value = option->save(); if (!strcmp(name, "Gravity")) { gravity->setMagnitude(atof(value)); } else if (!strcmp(name, "Twirl")) { twirl->setMagnitude(atof(value)); } else if (!strcmp(name, "PointGravity")) { pointGravity->setMagnitude(atof(value)); } } void Framework::moduleInitGui(int argc, char** argv) { Window* guiMainWindow = NULL; initGUI(0, NULL); guiMainWindow = new Window("ParticlesFUN"); { Box* windowBox = new Box('h'); { Frame* emitterFrame = new Frame("emitter-settings"); { Box* emitterBox = new Box('v'); { emitterBox->fill(new Label("EmissionRate")); Slider* EmissionRate = new Slider("EmissionRate", 0, 1000); EmissionRate->connectSignal("value_changed", (void*)EmissionRate, emitterChange ); EmissionRate->setValue(PINIT_EMISSION_RATE); EmissionRate->redraw(); emitterBox->fill(EmissionRate); emitterBox->fill(new Label("Velocity")); Slider* velocity = new Slider("Velocity", 0, 20); velocity->setExactness(2); velocity->connectSignal("value_changed", (void*)velocity, emitterChange ); velocity->setValue(PINIT_EMISSION_VELOCITY); velocity->redraw(); emitterBox->fill(velocity); emitterBox->fill(new Label("SpreadAngle")); Slider* SpreadAngle = new Slider("SpreadAngle", 0, M_PI); SpreadAngle->setExactness(3); SpreadAngle->connectSignal("value_changed", (void*)SpreadAngle, emitterChange ); SpreadAngle->setValue(PINIT_SPREAD_ANGLE); SpreadAngle->redraw(); emitterBox->fill(SpreadAngle); emitterBox->fill(new Label("EmitterType")); Menu* EmitterType = new Menu("EmitterType"); EmitterType->addItem("EMITTER_DOT"); EmitterType->addItem("EMITTER_PLANE"); EmitterType->addItem("EMITTER_CUBE"); EmitterType->connectSignal("changed", (void*)EmitterType, emitterChange ); EmitterType->load("EMITTER_DOT"); emitterBox->fill(EmitterType); emitterBox->fill(new Label("EmitterSize")); Slider* EmitterSize = new Slider("EmitterSize", 0, 100); EmitterSize->setExactness(1); EmitterSize->connectSignal("value_changed", (void*)EmitterSize, emitterChange ); EmitterSize->setValue(PINIT_EMITTER_SIZE); EmitterSize->redraw(); emitterBox->fill(EmitterSize); emitterBox->fill(new Label("InheritSpeed")); Slider* InheritSpeed = new Slider("InheritSpeed", 0, 1); InheritSpeed->setExactness(3); InheritSpeed->connectSignal("value_changed", (void*)InheritSpeed, emitterChange ); emitterBox->fill(InheritSpeed); } emitterFrame->fill(emitterBox); } windowBox->fill(emitterFrame); Frame* systemFrame = new Frame("system-settings"); { Box* systemBox = new Box('v'); { systemBox->fill(new Label("StartRadius")); Slider* StartRadius = new Slider("StartRadius", 0, 10); StartRadius->setExactness(3); StartRadius->connectSignal("value_changed", (void*)StartRadius, systemChange ); StartRadius->setValue(PINIT_START_RADIUS); StartRadius->redraw(); systemBox->fill(StartRadius); systemBox->fill(new Label("EndRadius")); Slider* EndRadius = new Slider("EndRadius", 0, 10); EndRadius->setExactness(3); EndRadius->connectSignal("value_changed", (void*)EndRadius, systemChange ); EndRadius->setValue(PINIT_END_RADIUS); EndRadius->redraw(); systemBox->fill(EndRadius); systemBox->fill(new Label("ParticleMass")); Slider* Mass = new Slider("Mass", 0, 10); Mass->setExactness(2); Mass->connectSignal("value_changed", (void*)Mass, systemChange ); Mass->setValue(PINIT_PARTICLE_MASS); Mass->redraw(); systemBox->fill(Mass); systemBox->fill(new Label("LifeSpan")); Slider* LifeSpan = new Slider("LifeSpan", 0, 10); LifeSpan->setExactness(3); LifeSpan->connectSignal("value_changed", (void*)LifeSpan, systemChange ); LifeSpan->setValue(PINIT_LIFESPAN); LifeSpan->redraw(); systemBox->fill(LifeSpan); systemBox->fill(new Label("ConserveFactor")); Slider* ConserveFactor = new Slider("ConserveFactor", 0, 1); ConserveFactor->setExactness(3); ConserveFactor->connectSignal("value_changed", (void*)ConserveFactor, systemChange ); ConserveFactor->setValue(PINIT_CONSERVE_FACTOR); ConserveFactor->redraw(); systemBox->fill(ConserveFactor); systemBox->fill(new Label("ParticleType")); Menu* ParticleType = new Menu("ParticleType"); ParticleType->addItem("PARTICLE_DOT"); ParticleType->addItem("PARTICLE_SPARK"); ParticleType->addItem("PARTICLE_SPRITE"); ParticleType->connectSignal("changed", (void*)ParticleType, systemChange ); ParticleType->load("PARTICLE_SPRITE"); systemBox->fill(ParticleType); systemBox->fill(new Label("ParticleModel")); Menu* ParticleModel = new Menu("ParticleModel"); { DIR* directory; directory = opendir(ResourceManager::getFullName(PINIT_MODEL_DIRECTORY)); dirent* file; while(file = readdir(directory)) { printf("%s\n", file->d_name); if(strstr(file->d_name, ".obj")) ParticleModel->addItem(file->d_name); } } ParticleModel->connectSignal("changed", (void*)ParticleModel, systemChange ); systemBox->fill(ParticleModel); Button* RandomColor = new Button("RandomColor"); RandomColor->connectSignal("released", (void*)RandomColor, systemChange); systemBox->fill(RandomColor); } systemFrame->fill(systemBox); } windowBox->fill(systemFrame); Frame* fieldsFrame = new Frame("Field-Settings"); { Box* fieldsBox = new Box('v'); { fieldsBox->fill(new Label("Gravity")); Slider* Gravity = new Slider("Gravity", 0, 10); Gravity->setExactness(1); Gravity->connectSignal("value_changed", (void*)Gravity, fieldsChange ); Gravity->setValue(0); Gravity->redraw(); fieldsBox->fill(Gravity); fieldsBox->fill(new Label("Twirl")); Slider* Twirl = new Slider("Twirl", 0, 10); Twirl->setExactness(1); Twirl->connectSignal("value_changed", (void*)Twirl, fieldsChange ); Twirl->setValue(0); Twirl->redraw(); fieldsBox->fill(Twirl); fieldsBox->fill(new Label("PointGravity")); Slider* PointGravity = new Slider("PointGravity", 0, 10); PointGravity->setExactness(1); PointGravity->connectSignal("value_changed", (void*)PointGravity, fieldsChange ); PointGravity->setValue(0); PointGravity->redraw(); fieldsBox->fill(PointGravity); } fieldsFrame->fill(fieldsBox); } windowBox->fill(fieldsFrame); Button* quitButton = new Button("quit"); quitButton->connectSignal("clicked", NULL, quitGui); // Window::mainWindow->connectSignal("remove", this, GuiExec::quitGui); Window::mainWindow->connectSignal("destroy", NULL, quitGui); windowBox->fill(quitButton); } guiMainWindow->fill(windowBox); } Window::mainWindow->showall(); Window::mainWindow->setSize(300, 500); }