|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- //
- // particleSystem.cpp
- // emptyExample
- //
- // Created by Sebastian Holzki on 16.04.19.
- //
-
- #include "particleSystem.hpp"
-
-
-
-
- ParticleSystem::ParticleSystem(){
-
-
-
- }
-
- // -----------------------------------
-
- ParticleSystem::~ParticleSystem(){
-
-
-
- }
-
- // -----------------------------------
-
-
-
- void ParticleSystem::setup(){
-
-
- // xmlParticleSystems.loadFile("xml/particleSystem.xml");
-
- // this->particles.push_back(new Particle);
-
- // std::cout << "breakpoint particleSystem_1 erreicht, particleSystem_setup beendet" << std::endl;
-
- }
-
- // -----------------------------------------------
-
- //*** PARTICLESYSTEM UPDATE *** PARTICLESYSTEM UPDATE *** PARTICLESYSTEM UPDATE *** PARTICLESYSTEM UPDATE ***
-
-
- void ParticleSystem::update(float deltaT, particleMode currentMode, vector<ObjectPhysics*>* objectPhysics, vector<CheckedInVisitor*>* checkedInVisitors, float sceneWidth, float sceneHeight){
-
-
- //preparation
-
- double DELTA_T_IN_SECONDS = deltaT/1000;
-
- this->currentMode = currentMode;
-
- // *** PARTICLESYSTEM SWITCH *** PARTICLESYSTEM SWITCH *** PARTICLESYSTEM SWITCH *** PARTICLESYSTEM SWITCH ***
-
-
- //If the particlesystem itself needs some logic, it will happen in the following switch!
-
-
- switch ( currentMode )
- {
-
-
- case PARTICLE_MODE_DEFAULT: {
-
-
- //what does the particle system do if its mode is 'PARTICLE_MODE_DEFAULT'
-
-
- // value a = xmlParticleSystems.getValue (" default:..." , 0 ) ;
- // value b = xmlParticleSystems.getValue (" default:..." , 0 ) ;
- // value c = xmlParticleSystems.getValue (" default:..." , 0 ) ;
- // value d = xmlParticleSystems.getValue (" default:..." , 0 ) ;
- // value e ....
- // ...
-
- // PARTICLESYSTEM_BIRTHRATE = xmlParticleSystems.getValue("default:birthrate", 0);
-
-
-
- PARTICLESYSTEM_BIRTHRATE = 1; //testing default
-
-
-
-
-
-
- // std::cout << "birthrate from xml: " + ofToString(PARTICLESYSTEM_BIRTHRATE) << std::endl;
-
- break;
- }
-
- //------------------------
-
- case PARTICLE_MODE_POLYMESH: {
-
- //what does the particle system do if its mode is 'PARTICLE_MODE_POLYMESH'
-
- PARTICLESYSTEM_BIRTHRATE = 0;
- updateLines(currentMode, objectPhysics);
-
- // PARTICLESYSTEM_BIRTHRATE = xmlParticleSystems.getValue("polymesh:birthrate", 0);
- int PARTICLESYSTEM_BIRTHRATE_CHECKEDINVISITORS = 4;
-
- while (PRODUCED_PER_EMITTER < PARTICLESYSTEM_BIRTHRATE_CHECKEDINVISITORS){
-
- for(int i = 0; i < checkedInVisitors->size(); i++){
-
- if( checkedInVisitors->at(i)->getAge() <= 7){
-
- this->particles.push_back(new Particle);
-
- particles.back()->setup(checkedInVisitors->at(i)->getBottom(), sceneHeight);
-
- particles.back()->setRandomVelocityOnlyGoingUp();
-
- }
-
- }
-
- PRODUCED_PER_EMITTER++;
-
- }
-
- PRODUCED_PER_EMITTER = 0;
-
- break;
- }
-
- //------------------------
-
- case PARTICLE_MODE_RFID: {
-
-
- //what does the particle system do if its mode is 'PARTICLE_MODE_RFID'
-
- while (PRODUCED_PER_EMITTER < PARTICLESYSTEM_BIRTHRATE){
-
- for(int i = 0; i < checkedInVisitors->size(); i++){
-
- if( checkedInVisitors->at(i)->getAge() <= 5){
-
- this->particles.push_back(new Particle);
-
- particles.back()->setup(checkedInVisitors->at(i)->getBottom(), sceneHeight);
-
- particles.back()->setRandomVelocityOnlyGoingUp();
-
- }
-
- }
-
- PRODUCED_PER_EMITTER++;
-
- }
-
- PRODUCED_PER_EMITTER = 0;
-
-
-
-
-
- break;
-
- }
-
- //------------------------
-
- default: {
-
- //following two lines only help for compiling right now
-
- int a = 0;
- a++;
-
- }
-
- } //end of switch
-
- // std::cout << "breakpoint particleSystem_2 erreicht, switch anweisung beendet" << std::endl;
-
- // *** BIRTH CONTROL *** BIRTH CONTROL *** BIRTH CONTROL ***
-
- //the system will emit a new particle for every emitter, as long as the PRODUCED_PER_EMITTER is smaller than the wanted BIRTHRATE
- //PPE is growing until it reaches deltaT, so the while statement will be executed more often, if deltaT gets bigger
- //as long as the birthcount grows and is lower then the birthrate (depending on the mode (XML) ) it will emit once for every emitter
- //that is active (bool emitting = true)
-
-
-
- while (PRODUCED_PER_EMITTER < PARTICLESYSTEM_BIRTHRATE){
-
- for(int i = 0; i < objectPhysics->size(); i++){
-
- // if(( (*objectPhysics).at(i)->type == "emitter" ) && (objectPhysics->at(i)->emitting == true)){
- if( objectPhysics->at(i)->emitting == true){
-
- this->particles.push_back(new Particle);
-
- particles.back()->setup(objectPhysics->at(i)->getPosition(), sceneHeight);
- if(objectPhysics->at(i)->type == "emitterOnStele"){
- particles.back()->setRandomVelocityOnlyGoingUp();
- }else{
- particles.back()->setRandomVelocity();
- }
-
- }
- }
-
- PRODUCED_PER_EMITTER++;
- }
-
- PRODUCED_PER_EMITTER = 0;
-
-
- // *** PARTICLE SYSTEM UPDATING ITS PARTICLES *** *** PARTICLE SYSTEM UPDATING ITS PARTICLES *** PARTICLE SYSTEM UPDATING ITS PARTICLES ***
-
- //for "alle partikel im system" update in abhängigkeit vom übergebenen "mode"
- //The following lines will start working, when Particle::update has been reworked is active and particleMode implemented
-
- for (int p = 0; p < particles.size(); p++){
-
- particles.at(p)->update(deltaT, currentMode, objectPhysics, checkedInVisitors, sceneWidth, sceneHeight);
-
- //Delete particles that reached maxAge
- if(currentMode != PARTICLE_MODE_POLYMESH){
- if (particles.at(p)->getAgeNorm() > 1) {
- delete particles.at(p);
- particles.erase(particles.begin() + p);
- }
- }
-
-
-
- }
-
- }
-
- // -----------------------------------------------
-
-
- void ParticleSystem::draw(typeOfView activeTypeOfView){
-
- for(int i = 0; i < particles.size(); i++){
-
- particles.at(i)->draw(activeTypeOfView);
-
- }
-
- if( currentMode == PARTICLE_MODE_POLYMESH){
- for(int i = 0; i < lines.size(); i++){
-
- ofDrawLine(lines.at(i)->point1, lines.at(i)->point2);
-
- }
- }
-
- }
-
- // -----------------------------------------------
-
- void ParticleSystem::updateLines(particleMode currentMode, vector<ObjectPhysics*>* objectPhysics){
-
- lines.clear();
-
- if(currentMode == PARTICLE_MODE_POLYMESH){
-
- for(int i = 0; i < objectPhysics->size(); i++){
-
- if(( (*objectPhysics).at(i)->type == "attraktor" ) && (objectPhysics->at(i)->attracting == true)){
-
- for(int p = 0; p < particles.size(); p++){
-
- if(particles.at(p)->particleIsOnGround==true){
-
- ofVec2f distance = particles.at(p)->getPosition() - objectPhysics->at(i)->getPosition();
-
- if(distance.length() < 150){
-
- lines.push_back(new Line(particles.at(p)->getPosition(), objectPhysics->at(i)->getPosition()));
-
- for(int p2 = 0; p2 < particles.size(); p2++){
-
- ofVec2f distance = particles.at(p)->getPosition() - particles.at(p2)->getPosition();
-
- if(distance.length() < 50){
-
- lines.push_back(new Line(particles.at(p)->getPosition(), particles.at(p2)->getPosition()));
-
- }
-
- p2 += 4; //lower value -> worse performance & nicer effect (more connections between the particles)
- }
- }
-
- // p += 2 ; //if your system shows performance issues you might need to activate this line! (downside: effect seems to jump)
-
- }
- } //end of for schleife
- }
- }
- }
- }
|