|
|
|
|
|
|
|
|
|
|
|
// |
|
|
|
|
|
// 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 |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |