void Particles::update(const phantom::PhantomTime& time) { this->_currentdensity -= time.getElapsed(); currentLifetime += time.getElapsed(); for(auto particle = _particles.begin(); particle != _particles.end();) { (*particle)->lifetime -= time.getElapsed(); if((*particle)->lifetime < 0.0f) { delete (*particle); particle = _particles.erase(particle); createNewParticle(); continue; } Vector3 random((float)(rand() % randomness) - randomnessHalf, (float)(rand() % randomness) - randomnessHalf, (float)(rand() % randomness) - randomnessHalf); random.x = random.x / 100.0f; random.y = random.y / 100.0f; random.z = random.z / 100.0f; (*particle)->acceleration = this->direction + random; (*particle)->velocity += (*particle)->acceleration * speed * time.getElapsed(); (*particle)->position += (*particle)->velocity; ++particle; } if(_particles.size() < count && this->_currentdensity < 0) { this->_currentdensity = this->density; createNewParticle(); } if(currentLifetime > totalLifetime + lifetime && !(totalLifetime < -0.9f && totalLifetime > -1.1f)) destroy(); }
//-------------------------------------------------------------- void ofApp::update(){ if(particles.size()<maxParticles){ createNewParticle(); //create a new BasicParticle and place at the back of our vector //particleSizeChecker(); //check to see if there are too many particles in our vector } for(int i = 0; i < particles.size(); i++){ //iterate through our vector to update our BasicParticle Objects particles[i].applyForce(wind); //pass our wind ofPoint and apply it on our particle via the applyForces method particles[i].applyForce(gravity); //same for gravity particles[i].update(); //update our particle at location i within our vector } //ADD RANDOM WIND EVENT if (counter == 10) { wind.x = ofRandom(-1.0,1.0); wind.y = ofRandom(-1.0,1.0); counter++; cout<<"RANDOM WIND EVENT"<<endl; cout<<"WIND = "<<wind.x<<","<<wind.y<<endl; }else if(counter > 1000){ wind.x = 0.2; wind.y = 0.2; counter = 0; cout<<"WIND RESET"<<endl; }else{ counter++; } }
//-------------------------------------------------------------- void ofApp::update(){ //p.update(); //calculate our Circle object's new position if(circles.size()<maxcircles){ createNewParticle(); particleSizeChecker(); } for(int i = 0; i < circles.size(); i++){ //iterate through our vector to update our Circle Objects //circles[i].applyForce(wind); //pass our wind ofPoint and apply it on our particle via the applyForces method circles[i].applyForce(gravity); //same for gravity circles[i].reduceAlpha(); circles[i].update(); //update our particle at location i within our vector circles[i].expandCircle(); } //cout<<"CURRENT NUMBER OF circles = "<<circles.size()<<endl; //ADD RANDOM WIND EVENT if (counter == 500) { wind.x = ofRandom(-2.0,2.0); wind.y = ofRandom(-2.0,2.0); counter++; cout<<"RANDOM WIND EVENT"<<endl; cout<<"WIND = "<<wind.x<<","<<wind.y<<endl; }else if(counter > 1000){ wind.x = 0.2; wind.y = 0.0; counter = 0; cout<<"WIND RESET"<<endl; }else{ counter++; } //lets scale the vol up to a 0-1 range scaledVol = ofMap(smoothedVol, 0.0, 0.17, 0.0, 1.0, true); //lets record the volume into an array volHistory.push_back( scaledVol ); //if we are bigger the the size we want to record - lets drop the oldest value if( volHistory.size() >= 400 ){ volHistory.erase(volHistory.begin(), volHistory.begin()+1); } cout<<scaledVol<<endl; }
//-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ //on our mouse click add a new particle to our vector createNewParticle(); //create a new BasicParticle and place at the back of our vector particleSizeChecker(); //check to see if there are too many particles in our vector }