From 14de0ec2f75fef4416b67350a9b550da5dc84754 Mon Sep 17 00:00:00 2001 From: Tobias Lindner Date: Thu, 23 May 2019 15:52:48 +0000 Subject: [PATCH] upload --- src/particle.cpp | 270 +++++++++++++++++++++++++++++++---------------- src/particle.h | 39 +++++-- 2 files changed, 210 insertions(+), 99 deletions(-) diff --git a/src/particle.cpp b/src/particle.cpp index 4c30988..ef7d055 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -8,73 +8,173 @@ 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; - 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); + //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"); - -} - - - -//-------------------------------------------------------------------------------------- - -void Particle::update(float deltaT, vector* 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(); - } + drag = ofRandom(0.95, 0.998); } + tex.load("img/br.png"); +} + +//-------------------------------------------------------------------------------------- + +void Particle::update(float deltaT, vector* attractors,vector 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); + + 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; + + vel *= drag; + vel += frc * 0.2; + + if (pos.y + vel.y > ofGetHeight()) { + pos.y -= ofGetHeight(); + } + } + 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; - position += (vel * deltaT); + pos += (vel * deltaT); // *** COLLISION *** COLLISION *** COLLISION *** COLLISION *** COLLISION *** COLLISION @@ -89,60 +189,50 @@ void Particle::update(float deltaT, vector* attractors) { //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); + 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() { return age / maxLife; } - //-------------------------------------------------------------------------------------- - +void Particle::setVel(float min, float max) { + vel.x = ofRandom(min,max); + vel.y = ofRandom(min,max); +} float Particle::getMaxLife() { return 1; } +float Particle::getY() { + return pos.y; +} + + +float Particle::getX() { + return pos.x; +} + -//-------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/src/particle.h b/src/particle.h index f139eb8..e37d856 100644 --- a/src/particle.h +++ b/src/particle.h @@ -1,33 +1,54 @@ #pragma once #include "ofMain.h" +#include "ofxXmlSettings.h" #include "attractor.h" -#include "line.h" -class Particle -{ +enum particleMode{ + PARTICLE_MODE_DEFAULT, + PARTICLE_MODE_ATTRACTOR, + PARTICLE_MODE_RAIN, + PARTICLE_MODE_RADIAL, + PARTICLE_MODE_DETRACTOR, + PARTICLE_MODE_POLY, + PARTICLE_MODE_BRUNIG +}; + +class Particle{ public: Particle(); - ~Particle(); - void setup(ofVec2f position); + void setup(particleMode newMode); - void update(float deltaT, vector* attractors); + void update(float deltaT, vector* attractors, vector system); + void setMode(particleMode newMode); + particleMode mode; void draw(); + void reset(ofVec2f _pos); + + float getX(); + float getY(); + + void setVel(float min, float max); float getAgeNorm(); float getMaxLife(); + - -private: + ofxXmlSettings effect; int counterOfActiveAttractors; ofVec2f vel; - ofVec2f position; + ofVec2f pos; + ofVec2f frc; + + float scale; + float drag; + float uniqueVal; float maxLife; float age;