123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- //
- // particle.cpp
- // emptyExample
- //
- // Created by Sebastian Holzki on 16.04.19.
- //
-
- #include "particle.h"
-
-
-
- Particle::Particle()
- {
-
-
- }
-
- // -----------------------------------
-
- Particle::~Particle()
- {
-
-
- }
-
-
- // -----------------------------------
-
- void Particle::setup(ofVec2f pos, float maxAge) {
-
- this->position = pos; //Pointer to Position ofVec2f position
-
- velocity.set(0, 0);
- //vel.set(ofRandom(-20.0, 20.0), ofRandom(-90, -100)); //Movement direction
- age = 0.0;
- maxLife = 12.0;
- //maxLife = ofRandom(maxAge - 5, maxAge); //Max life of a particle
- color.set(5, 241, 219);
- //size = 2.0;
- //mass = 100;
- size = ofRandom(4.0, 0.01);
- mass = ofRandom(100, 250); //Changes the particle velocity
- valueToMoveToTop = 0; //Counter which causes the particle and the attractor to move to top
- valueToMoveToRight = 0; //Counter which causes the particle and the attractor to move to right
- ticksToMoveParticlesToRight = 70; //Framerate for movement velocity
- counterToMoveParticlesToRight = 0; //Counter for delay on top
- particleLeftScene = false; //Particle are out of ScenesizeX on the right side
-
- }
-
-
- // -----------------------------------
-
- void Particle::update(float deltaT) {
-
- }
-
- // --------------------------------------------------------------------------------
-
- void Particle::updateParticle(double deltaT, ofVec2f attractor, bool cloudAttractorIsSet, bool imageIsOnTop, bool tornadoIsFinished, int imageHeight, int imageWidth, float sceneSizeX, float sceneSizeY) {
-
- //Movement of particle in the different settings
-
- //doMovementOfParticlesAtRain(tornadoIsFinished, deltaT, sceneSizeX);
-
- if (cloudAttractorIsSet == true) {
- doMovementOfParticlesAtRocketEffect(sceneSizeY, imageHeight, imageWidth, sceneSizeX, attractor, deltaT);
- }
-
- if (tornadoIsFinished == true && cloudAttractorIsSet == false) {
- doMovementOfParticlesAtSymbols(deltaT, attractor);
- }
-
- if (imageIsOnTop == true) {
- doMovementOfHexagonOnTheTop(attractor, sceneSizeX, deltaT);
- }
-
- }
-
- //--------------------------------------------------------------
- void Particle::doMovementOfParticlesAtRain(bool tornadoIsFinished, double deltaT, float sceneSizeX)
- {
- if (tornadoIsFinished == false) { //Movement of partile from bottom to top
- position += vel * deltaT;
- age += deltaT;
-
- if (position.x >= sceneSizeX) {
- position.x = ofRandom(-1, -5);
- }
- }
- }
-
- //--------------------------------------------------------------
- void Particle::doMovementOfParticlesAtSymbols(double deltaT, ofVec2f &attractor)
- {
- valueToMoveToTop = 0;
- valueToMoveToRight = 0;
- counterToMoveParticlesToRight = 0;
-
- age += deltaT;
- vel *= 0.1;
- ofVec2f force = attractor - position; //Attraction
-
- if (50 < force.length() < 150) { //Movement of the particle which is located at a radius of 50 to 150 around the attractor
- force = 10 * force.getNormalized();
-
- vel += force; //Movement to attractor
- vel = mass * vel.getNormalized();
- }
- else if (150 < force.length() < 500) { //Movement of the particle which is located at a radius of 150 to 500 around the attractor
- force = 8 * force.getNormalized();
-
- vel += force;
- vel = mass * vel.getNormalized();
- }
- else { //Movement of the particle which is located at a radius more than 500 around the attractor
- force = 2 * force.getNormalized();
- vel += force;
- vel = mass / 1.2* vel.getNormalized();
- }
- position += (vel / 1.5 * deltaT); //Position = m/s * s [particle placed static]
- }
-
- //--------------------------------------------------------------
- void Particle::doMovementOfParticlesAtRocketEffect(float sceneSizeY, int imageHeight, int imageWidth, float sceneSizeX, ofVec2f &attractor, double deltaT)
- {
- int y = ((sceneSizeY / 2) + imageHeight); //Beginning height for attractor
- int x = ofRandom(sceneSizeX / 2 - imageWidth / 2, sceneSizeX / 2 + imageWidth / 2); //Width for attractor
-
- if (y - valueToMoveToTop - imageHeight > 200) { //Increase counter depending on velocity for movement to top
- valueToMoveToTop += 3; //Movement by 3 to top (pro Frame)
- }
- else if (y - valueToMoveToTop - imageHeight > 10) { //Increase counter depending on velocity for movement to top
- valueToMoveToTop += 2; //Movement by 3 to top (pro Frame)
-
- }
-
- else if (counterToMoveParticlesToRight < ticksToMoveParticlesToRight) { //Delay on top
- counterToMoveParticlesToRight++;
- }
- else if (y - valueToMoveToTop - imageHeight <= 10) { //Increase counter depending on velocity for movement to right( Movement by 3 to right (pro Frame))
- valueToMoveToRight += 3;
- }
-
- attractor.set(x + valueToMoveToRight, y - valueToMoveToTop);
-
-
- age += deltaT;
- vel *= 0.1;
- ofVec2f force = (attractor - position); //Attraction
-
- if (30 < force.length() < 150) { //Movement of the particle which is located at a radius of 30 to 150 around the attractor
- force = 17 * force.getNormalized();
-
- vel += force; //Movement to attractor
- vel = (mass / 1.2) * vel.getNormalized(); //Particle don't pass the symbol
- }
- else if (150 < force.length() < 250) { //Movement of the particle which is located at a radius of 150 to 250 around the attractor
- force = 14 * force.getNormalized();
-
- vel += force;
- vel = mass * 10 * vel.getNormalized();
- }
- else if (250 < force.length() < 500) { //Movement of the particle which is located at a radius of 250 to 500 around the attractor
- force = 14 * force.getNormalized();
-
- vel += force;
- vel = mass * 4 * vel.getNormalized();
- }
- else { //Movement of the particle which is located at a radius more than 500 around the attractor
- force = 20 * force.getNormalized();
- vel += force;
- vel = mass * vel.getNormalized();
- }
- position += (vel / 1.7 * deltaT); //Position = m/s * s [particle placed static]
- }
-
- //--------------------------------------------------------------
- void Particle::doMovementOfHexagonOnTheTop(ofVec2f &attractor, float sceneSizeX, double deltaT)
- {
- if (attractor.x + valueToMoveToRight >= sceneSizeX + 120) {
- particleLeftScene = true;
- }
- else {
- particleLeftScene = false;
- }
- age += deltaT;
- vel *= 0.1;
- ofVec2f force = attractor - position; //Attraction
-
- if (50 < force.length() < 150) { //Movement of the particle which is located at a radius of 50 to 150 around the attractor
- force = 60 * force.getNormalized(); //Anziehungskraft des Attraktors auf die Partikel
-
- vel += force; //Bewegung zum Attraktor
- vel = mass * vel.getNormalized();
- }
- else { //Movement of the particle which is located at a radius of more than 150 around the attractor
- force = 100 * force.getNormalized();
-
- vel += force;
- vel = mass / 2 * vel.getNormalized();
- }
- position += (vel * deltaT); //Position = m/s * s [particle placed static]
- }
-
- // -----------------------------------
-
- void Particle::draw() {
- if (position.x > 0 || position.x < 300) {
- ofSetColor(this->color); //To make particle turquoise
- color.set(getAgeNorm() * 241, 241 / getAgeNorm(), 219); //Color (Disco)
- }
- else {
- ofSetColor(255, 255, 255);
-
- }
- ofDrawCircle(position, size);
-
- }
-
-
- //--------------------------------------------------------------
- float Particle::getAgeNorm() {
- return age / maxLife;
- }
-
- //--------------------------------------------------------------
- float Particle::deleteAfterLeavingSceneY() {
- return position.y < 0 || position.y > ofGetHeight();
- }
-
- //--------------------------------------------------------------
- bool Particle::deleteAfterLeavingSceneX() {
- return particleLeftScene;
- }
-
- //------------------------------------------------------------------
- void Particle::setMode(particleMode newMode) {
- mode = newMode;
- }
-
-
- //-----------------------------------
-
- float Particle::getMaxLife() {
-
- return maxLife;
- }
-
- //-----------------------------------
-
- float Particle::getAge() {
-
- return age;
- }
-
- //-----------------------------------
-
-
- void Particle::mapParticle() {
-
- /*
- Put an if Statement before it:
-
- if(borderCollission == true){mapParticle()}
-
-
- The particle will be mapped to a new position, using information about:
-
- - old position
- - velocity (direction)
- - defined borders in the projection --> globals like window size, angle between "stelen", width of stelen, etc.
-
- if the particle hits a border
-
-
- */
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|