|
|
@@ -0,0 +1,148 @@ |
|
|
|
|
|
|
|
// particle.cpp |
|
|
|
// particleSystem |
|
|
|
// |
|
|
|
|
|
|
|
#include "particle.h" |
|
|
|
#include "ofApp.h" |
|
|
|
|
|
|
|
Particle::Particle() |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
Particle::~Particle() |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
void Particle::setup(ofVec2f _position) { |
|
|
|
|
|
|
|
this->position = _position; |
|
|
|
|
|
|
|
vel.set(ofRandom(-3.0, 3.0), ofRandom(-3.0, 3.0)); |
|
|
|
|
|
|
|
age = 0.0; |
|
|
|
maxLife = 12.0; |
|
|
|
|
|
|
|
color.set(250, 250, 250); |
|
|
|
|
|
|
|
size = ofRandom(4.0, 0.01); |
|
|
|
|
|
|
|
mass = ofRandom(100, 250); |
|
|
|
|
|
|
|
tex.load("img/overlay.png"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
void Particle::update(float deltaT, vector<Attractor*>* attractors) { |
|
|
|
|
|
|
|
ofVec2f force; |
|
|
|
counterOfActiveAttractors = 0; |
|
|
|
for (int i = 0; i < attractors->size(); i++) { |
|
|
|
if (attractors->at(i)->getX() == 0 && attractors->at(i)->getY() == 0) { |
|
|
|
force = 0 * force.getNormalized(); |
|
|
|
vel += force; |
|
|
|
vel = mass * vel.getNormalized(); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
counterOfActiveAttractors++; |
|
|
|
force.set(attractors->at(i)->getX() - position.x, attractors->at(i)->getY() - position.y); |
|
|
|
|
|
|
|
if (force.length() < 150) { |
|
|
|
force = 60 * force.getNormalized(); |
|
|
|
size = size + ofRandom(.01, 0.01); |
|
|
|
|
|
|
|
vel += force; |
|
|
|
vel = mass * vel.getNormalized(); |
|
|
|
} |
|
|
|
else { |
|
|
|
force = 0 * force.getNormalized(); |
|
|
|
vel += force; |
|
|
|
vel = mass * vel.getNormalized(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
age += deltaT * .5; |
|
|
|
position += (vel * deltaT); |
|
|
|
|
|
|
|
// *** COLLISION *** COLLISION *** COLLISION *** COLLISION *** COLLISION *** COLLISION |
|
|
|
|
|
|
|
//if (position.x <= 0 || position.x >= ofGetWidth()) { |
|
|
|
//vel.x = -vel.x; |
|
|
|
//position += (vel * deltaT); |
|
|
|
//} |
|
|
|
//else if (position.y <= 0 || position.y >= ofGetHeight()) { |
|
|
|
//vel.y = -vel.y; |
|
|
|
//position += (vel * deltaT); |
|
|
|
//} |
|
|
|
//else { |
|
|
|
//position += (vel * deltaT); |
|
|
|
//} |
|
|
|
|
|
|
|
|
|
|
|
//void thParticle::update(float deltaT, ofVec2f attractor){ |
|
|
|
// |
|
|
|
// |
|
|
|
// age += deltaT; |
|
|
|
// |
|
|
|
// ofVec2f force = attractor - position; |
|
|
|
// color.set(250,250, 250, (1 - age / maxLife) * 255); |
|
|
|
// |
|
|
|
// if( force.length() < 40 && force.length() > 11 ){ |
|
|
|
// velocity = velocity.getNormalized() * mass; |
|
|
|
// velocity += 0.01 * force ; |
|
|
|
// |
|
|
|
// }else if(force.length() < 12){ |
|
|
|
// velocity = velocity.getNormalized() * mass; |
|
|
|
// velocity += 5 * force ; |
|
|
|
// |
|
|
|
// }else{ |
|
|
|
// |
|
|
|
// velocity = velocity.getNormalized() * mass; |
|
|
|
// velocity += 0.12 * force ; |
|
|
|
// } |
|
|
|
// position += velocity * deltaT; |
|
|
|
//} |
|
|
|
} |
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
void Particle::draw() { |
|
|
|
|
|
|
|
color.set(getAgeNorm() * 241,241/ getAgeNorm() ,219); |
|
|
|
|
|
|
|
ofSetColor(color, (1 - getAgeNorm()) * 255); |
|
|
|
//tex.setColor(color); |
|
|
|
//tex.draw(position, size, size); |
|
|
|
|
|
|
|
ofDrawCircle(position, size); |
|
|
|
} |
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
float Particle::getAgeNorm() { |
|
|
|
return age / maxLife; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
float Particle::getMaxLife() { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------- |