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