|
|
|
|
|
|
|
|
|
|
|
|
|
|
Particle::Particle() |
|
|
Particle::Particle() |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
Particle::~Particle() |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uniqueVal = ofRandom(-10000, 10000); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------- |
|
|
//-------------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Particle::setup(ofVec2f _position) { |
|
|
|
|
|
|
|
|
|
|
|
this->position = _position; |
|
|
|
|
|
|
|
|
|
|
|
vel.set(ofRandom(-3.0, 3.0), ofRandom(-3.0, 3.0)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Particle::setup(particleMode newMode) { |
|
|
|
|
|
mode = newMode; |
|
|
age = 0.0; |
|
|
age = 0.0; |
|
|
maxLife = 12.0; |
|
|
|
|
|
|
|
|
|
|
|
color.set(250, 250, 250); |
|
|
|
|
|
|
|
|
|
|
|
size = ofRandom(4.0, 0.01); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
maxLife = 10.0; |
|
|
|
|
|
frc = ofVec2f(0, 0); |
|
|
|
|
|
size = ofRandom(1, 1); |
|
|
|
|
|
size = .5; |
|
|
mass = ofRandom(100, 250); |
|
|
mass = ofRandom(100, 250); |
|
|
|
|
|
//setVel(-40, 40); |
|
|
|
|
|
if (mode == PARTICLE_MODE_DEFAULT) { |
|
|
|
|
|
effect.loadFile("xml/default.xml"); |
|
|
|
|
|
int velMin = effect.getValue("default:velMin", 0); |
|
|
|
|
|
int velMax = effect.getValue("default:velMax", 0); |
|
|
|
|
|
setVel(velMin, velMax); |
|
|
|
|
|
int lifeMax = effect.getValue("default:maxLife", 0); |
|
|
|
|
|
maxLife = lifeMax; |
|
|
|
|
|
int sizeMin = effect.getValue("default:sizeMin", 0); |
|
|
|
|
|
int sizeMax = effect.getValue("default:sizeMax", 0); |
|
|
|
|
|
size = ofRandom(sizeMin, sizeMax); |
|
|
|
|
|
pos.x = ofRandomWidth(); |
|
|
|
|
|
pos.y = ofRandomHeight(); |
|
|
|
|
|
} |
|
|
|
|
|
else if (mode == PARTICLE_MODE_RADIAL) { |
|
|
|
|
|
effect.loadFile("xml/radial.xml"); |
|
|
|
|
|
int velMin = effect.getValue("default:velMin", 0); |
|
|
|
|
|
int velMax = effect.getValue("default:velMax", 0); |
|
|
|
|
|
setVel(velMin, velMax); |
|
|
|
|
|
int lifeMax = effect.getValue("default:maxLife", 0); |
|
|
|
|
|
maxLife = lifeMax; |
|
|
|
|
|
int sizeMin = effect.getValue("default:sizeMin", 0); |
|
|
|
|
|
int sizeMax = effect.getValue("default:sizeMax", 0); |
|
|
|
|
|
size = ofRandom(sizeMin, sizeMax); |
|
|
|
|
|
pos.x = ofGetWidth()/2; |
|
|
|
|
|
pos.y = ofGetHeight()/2; |
|
|
|
|
|
} |
|
|
|
|
|
else if (mode == PARTICLE_MODE_RAIN) { |
|
|
|
|
|
effect.loadFile("xml/rain.xml"); |
|
|
|
|
|
int velMin = effect.getValue("default:velMin", 0); |
|
|
|
|
|
int velMax = effect.getValue("default:velMax", 0); |
|
|
|
|
|
setVel(velMin, velMax); |
|
|
|
|
|
int lifeMax = effect.getValue("default:maxLife", 0); |
|
|
|
|
|
maxLife = lifeMax; |
|
|
|
|
|
int sizeMin = effect.getValue("default:sizeMin", 0); |
|
|
|
|
|
int sizeMax = effect.getValue("default:sizeMax", 0); |
|
|
|
|
|
size = ofRandom(sizeMin, sizeMax); |
|
|
|
|
|
pos.x = ofRandomWidth(); |
|
|
|
|
|
pos.y = ofRandomHeight(); |
|
|
|
|
|
drag = ofRandom(0.97, 0.99); |
|
|
|
|
|
vel.y = fabs(vel.y) * 6.0; |
|
|
|
|
|
} |
|
|
|
|
|
else if (mode == PARTICLE_MODE_ATTRACTOR) { |
|
|
|
|
|
effect.loadFile("xml/attractor.xml"); |
|
|
|
|
|
int velMin = effect.getValue("default:velMin", 0); |
|
|
|
|
|
int velMax = effect.getValue("default:velMax", 0); |
|
|
|
|
|
setVel(velMin, velMax); |
|
|
|
|
|
int lifeMax = effect.getValue("default:maxLife", 0); |
|
|
|
|
|
maxLife = lifeMax; |
|
|
|
|
|
int sizeMin = effect.getValue("default:sizeMin", 0); |
|
|
|
|
|
int sizeMax = effect.getValue("default:sizeMax", 0); |
|
|
|
|
|
size = ofRandom(sizeMin, sizeMax); |
|
|
|
|
|
pos.x = ofRandomWidth(); |
|
|
|
|
|
pos.y = ofRandomHeight(); |
|
|
|
|
|
} |
|
|
|
|
|
else if (mode == PARTICLE_MODE_DETRACTOR) { |
|
|
|
|
|
effect.loadFile("xml/detractor.xml"); |
|
|
|
|
|
int velMin = effect.getValue("default:velMin", 0); |
|
|
|
|
|
int velMax = effect.getValue("default:velMax", 0); |
|
|
|
|
|
setVel(velMin, velMax); |
|
|
|
|
|
int lifeMax = effect.getValue("default:maxLife", 0); |
|
|
|
|
|
maxLife = lifeMax; |
|
|
|
|
|
int sizeMin = effect.getValue("default:sizeMin", 0); |
|
|
|
|
|
int sizeMax = effect.getValue("default:sizeMax", 0); |
|
|
|
|
|
size = ofRandom(sizeMin, sizeMax); |
|
|
|
|
|
pos.x = ofRandomWidth(); |
|
|
|
|
|
pos.y = ofRandomHeight(); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
|
|
|
tex.load("img/overlay.png"); |
|
|
|
|
|
|
|
|
drag = ofRandom(0.95, 0.998); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
tex.load("img/br.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; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void Particle::update(float deltaT, vector<Attractor*>* attractors,vector<Particle*> system) { |
|
|
|
|
|
if (mode == PARTICLE_MODE_DEFAULT) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else if (mode == PARTICLE_MODE_RAIN) { |
|
|
|
|
|
float wind = ofSignedNoise(pos.x * 0.003, pos.y * 0.006, ofGetElapsedTimef() * 0.6); |
|
|
|
|
|
|
|
|
counterOfActiveAttractors++; |
|
|
|
|
|
force.set(attractors->at(i)->getX() - position.x, attractors->at(i)->getY() - position.y); |
|
|
|
|
|
|
|
|
frc.x = wind * 0.25 + ofSignedNoise(uniqueVal, pos.y * 0.08) * 0.6; |
|
|
|
|
|
frc.y = ofSignedNoise(uniqueVal, pos.x * 0.06, ofGetElapsedTimef()*0.2) * 0.09 + 0.18; |
|
|
|
|
|
|
|
|
if (force.length() < 150) { |
|
|
|
|
|
force = 60 * force.getNormalized(); |
|
|
|
|
|
size = size + ofRandom(.01, 0.01); |
|
|
|
|
|
|
|
|
vel *= drag; |
|
|
|
|
|
vel += frc * 0.2; |
|
|
|
|
|
|
|
|
vel += force; |
|
|
|
|
|
vel = mass * vel.getNormalized(); |
|
|
|
|
|
|
|
|
if (pos.y + vel.y > ofGetHeight()) { |
|
|
|
|
|
pos.y -= ofGetHeight(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
else { |
|
|
|
|
|
force = 0 * force.getNormalized(); |
|
|
|
|
|
vel += force; |
|
|
|
|
|
vel = mass * vel.getNormalized(); |
|
|
|
|
|
|
|
|
else if (mode == PARTICLE_MODE_ATTRACTOR) { |
|
|
|
|
|
|
|
|
|
|
|
ofVec2f force; |
|
|
|
|
|
counterOfActiveAttractors = 0; |
|
|
|
|
|
for (int i = 0; i < attractors->size(); i++) { |
|
|
|
|
|
if (attractors->at(i)->getX() == 0 && attractors->at(i)->getY() == 0) { |
|
|
|
|
|
vel += force; |
|
|
|
|
|
vel = mass * vel.getNormalized(); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
counterOfActiveAttractors++; |
|
|
|
|
|
force.set(attractors->at(i)->getX() - pos.x, attractors->at(i)->getY() - pos.y); |
|
|
|
|
|
|
|
|
|
|
|
if (force.length() < 250) { |
|
|
|
|
|
force = 40 * force.getNormalized(); |
|
|
|
|
|
size = size + ofRandom(.03, 0.01); |
|
|
|
|
|
vel += force; |
|
|
|
|
|
vel = mass * vel.getNormalized(); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
force = 0 * force.getNormalized(); |
|
|
|
|
|
vel += force; |
|
|
|
|
|
vel = mass * vel.getNormalized(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
else if (mode == PARTICLE_MODE_DETRACTOR) { |
|
|
|
|
|
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() - pos.x, attractors->at(i)->getY() - pos.y); |
|
|
|
|
|
|
|
|
|
|
|
if (force.length() < 600) { |
|
|
|
|
|
force.normalize(); |
|
|
|
|
|
size = size + ofRandom(.01, 0.01); |
|
|
|
|
|
|
|
|
|
|
|
vel += -force*2000; |
|
|
|
|
|
vel = mass * vel.getNormalized(); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
force = 0 * force.getNormalized(); |
|
|
|
|
|
vel += force; |
|
|
|
|
|
vel = mass * vel.getNormalized(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
//Update particle pos |
|
|
age += deltaT * .5; |
|
|
age += deltaT * .5; |
|
|
position += (vel * deltaT); |
|
|
|
|
|
|
|
|
pos += (vel * deltaT); |
|
|
|
|
|
|
|
|
// *** COLLISION *** COLLISION *** COLLISION *** COLLISION *** COLLISION *** COLLISION |
|
|
// *** COLLISION *** COLLISION *** COLLISION *** COLLISION *** COLLISION *** COLLISION |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//else { |
|
|
//else { |
|
|
//position += (vel * deltaT); |
|
|
//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() { |
|
|
void Particle::draw() { |
|
|
|
|
|
|
|
|
color.set(getAgeNorm() * 241,241/ getAgeNorm() ,219); |
|
|
color.set(getAgeNorm() * 241,241/ getAgeNorm() ,219); |
|
|
|
|
|
|
|
|
ofSetColor(color, (1 - getAgeNorm()) * 255); |
|
|
ofSetColor(color, (1 - getAgeNorm()) * 255); |
|
|
//tex.setColor(color); |
|
|
|
|
|
//tex.draw(position, size, size); |
|
|
|
|
|
|
|
|
if (mode == PARTICLE_MODE_BRUNIG) { |
|
|
|
|
|
tex.setColor(color); |
|
|
|
|
|
tex.draw(pos.x, pos.y, size); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
ofDrawCircle(pos.x, pos.y, size); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
ofDrawCircle(position, size); |
|
|
|
|
|
|
|
|
//------------------------------------------------------------------ |
|
|
|
|
|
void Particle::setMode(particleMode newMode) { |
|
|
|
|
|
mode = newMode; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------- |
|
|
//-------------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float Particle::getAgeNorm() { |
|
|
float Particle::getAgeNorm() { |
|
|
return age / maxLife; |
|
|
return age / maxLife; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------- |
|
|
//-------------------------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
void Particle::setVel(float min, float max) { |
|
|
|
|
|
vel.x = ofRandom(min,max); |
|
|
|
|
|
vel.y = ofRandom(min,max); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
float Particle::getMaxLife() { |
|
|
float Particle::getMaxLife() { |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
float Particle::getY() { |
|
|
|
|
|
return pos.y; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float Particle::getX() { |
|
|
|
|
|
return pos.x; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------- |
|
|
|