123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555 |
- //
- // particle.cpp
- // emptyExample
- //
- // Created by Sebastian Holzki on 16.04.19.
- //
-
- #include "particle.hpp"
-
-
-
-
- Particle::Particle()
- {
-
- // std::cout << "partikel konstruktor" << std::endl;
- }
-
- // -----------------------------------
-
-
- Particle::Particle(ofVec2f _position)
- {
-
- position = _position;
-
-
-
- // std::cout << "partikel konstruktor überladen" << std::endl;
- }
-
- // -----------------------------------
-
- Particle::~Particle()
- {
-
-
-
-
- }
-
- // -----------------------------------
-
-
-
- void Particle::setup(ofVec2f _position, float sceneHeight){
-
- this->position = _position;
-
- velocity.set(0,0);
- age = 0.0;
- maxLife = 25.0;
-
- color.set(ofRandom(100,150),ofRandom(100,150),ofRandom(20,255));
- size = 1.5;
- mass = 100;
-
- activeSlowingDown = 0;
- factorOfSlowingDown = 0.3;
-
- activeSpeedingUp = factorOfSlowingDown;
- factorOfSpeedingUp = 1;
-
- scaleFactorPerDeltaT = 0.002;
-
- distanceToCenter = 0;
- angleToCenter = 0;
-
- aging = true;
-
- particleIsOnGround = isTheSetupPositionOnTheGround(position, sceneHeight);
-
-
-
- }
-
- // -----------------------------------
-
- void Particle::update(float deltaT, particleMode currentMode, vector<ObjectPhysics*>* objectPhysics, vector<CheckedInVisitor*>* checkedInVisitors, float _sceneWidth, float _sceneHeight){
-
-
- sceneWidth = _sceneWidth;
- sceneHeight = _sceneHeight;
-
-
- //angle and distance calculation to be able to map later
- updateAngleToCenter(sceneHeight/2, sceneHeight/2); //updates the angle of the particle in relation to the center of the logical scene
- updateDistanceToCenter(sceneHeight/2, sceneHeight/2, sceneHeight); //needs the center of the LED-Floor as reference
-
-
- switch ( currentMode ) {
-
-
- case PARTICLE_MODE_DEFAULT: {
-
-
- //what does the PARTICLE do if the mode is 'PARTICLE_MODE_DEFAULT'
-
- if(currentMode != lastMode && lastMode == PARTICLE_MODE_POLYMESH){
- activeSpeedingUp = factorOfSlowingDown;
- }
-
- if(activeSpeedingUp < factorOfSpeedingUp){
- //This is helping to make the transition from faster to slower a little smoother
- //The particle will be slowed down in every iteration until the "destination"-speed is reached
- activeSpeedingUp = activeSpeedingUp + deltaT;
- }
-
-
- attractParticle(objectPhysics, checkedInVisitors);
-
-
- position += activeSpeedingUp * (velocity * deltaT) ;
-
- aging = true;
-
- if(aging == true){
- age += deltaT;
-
-
-
- }
-
-
-
-
-
- break;
- }
-
- //------------------------
-
-
- case PARTICLE_MODE_POLYMESH: {
-
- //what does the PARTICLE do if its mode is 'PARTICLE_MODE_POLYMESH'
- if(currentMode != lastMode){
- activeSlowingDown = 1;
- }
-
- if(activeSlowingDown > factorOfSlowingDown){
- //This is helping to make the transition from faster to slower a little smoother
- //The particle will be slowed down in every iteration until the "destination"-speed is reached
- activeSlowingDown = activeSlowingDown - deltaT;
- }
-
-
- position += activeSlowingDown * (velocity * deltaT) ;
-
- aging = true;
-
- if(aging == true){
- age += deltaT;
- }
-
- break;
-
- }
-
- //------------------------
-
-
- case PARTICLE_MODE_TORNADO: {
-
-
- //what does the PARTICLE do if the mode is 'PARTICLE_MODE_TORNADO'
-
-
- break;
- }
-
- //------------------------
-
- case PARTICLE_MODE_RFID: {
-
- //what does the PARTICLE do if its mode is 'PARTICLE_MODE_RFID'
-
- if(currentMode != lastMode && lastMode == PARTICLE_MODE_POLYMESH){
- activeSpeedingUp = factorOfSlowingDown;
- }
-
- if(activeSpeedingUp < factorOfSpeedingUp){
- //This is helping to make the transition from faster to slower a little smoother
- //The particle will be slowed down in every iteration until the "destination"-speed is reached
- activeSpeedingUp = activeSpeedingUp + deltaT;
- }
-
- position += activeSpeedingUp * (velocity * deltaT) ;
-
- size += scaleFactorPerDeltaT * deltaT ;
-
- aging = true;
-
- if(aging == true){
- age += deltaT;
- }
-
-
-
- break;
- }
-
- //------------------------
-
- default: {}
-
- } //end of switch
-
-
- // *** PARTICLE MOVEMENT CONTROL AREA *** PARTICLE MOVEMENT CONTROL AREA ***
-
-
- //first we slow down the particle in their y-direction,
- if(particleIsOnGround == false){
- if(velocity.y < 0 && velocity.y > -0.4){
- velocity.y *= 0.995;
- }
- }
- if(distanceToCenter > sceneHeight/4*3){
-
- }
-
- if(particleIsOnGround == false){
- if(position.x < (sceneHeight)){
- position.x = sceneWidth;
- }
- else if(position.x >= sceneWidth){
- position.x = sceneHeight;
- }
- }
-
- size += scaleFactorPerDeltaT * age ;
-
- lastMode = currentMode;
-
- }
-
- // -----------------------------------
-
- void Particle::draw(typeOfView activeTypeOfView){
-
- updateColor();
- ofSetColor(color);
-
- ofSetCircleResolution(10);
- mapParticle(sceneWidth, sceneHeight);
- ofDrawCircle(position, size);
-
- if(activeTypeOfView == MAPPED){
- ofDrawBitmapString(distanceToCenter, position);
- }
- ofSetCircleResolution(35);
-
-
- }
-
-
- //-----------------------------------
-
-
- float Particle::getMaxLife(){
-
- return maxLife;
-
- }
-
-
- //-----------------------------------
-
- float Particle::getAngle(){
-
- return angleToCenter;
-
- }
-
- //-----------------------------------
-
- ofVec2f Particle::getPosition(){
-
- return position;
-
- }
-
- //-----------------------------------
-
- void Particle::setRandomVelocity(){
-
- velocity.set(ofRandom(-50,50), ofRandom(-50,50));
-
- }
-
- //-----------------------------------
-
- void Particle::setRandomVelocityOnlyGoingUp(){
-
- velocity.set(ofRandom(-50,50), ofRandom(-50,-1));
-
- }
-
- //-----------------------------------
-
-
- void Particle::updateColor(){
-
- if(getAgeNorm() >= 1){
- color.set(69 + getAgeNorm() * 104, 164 - getAgeNorm() * 95 , 220, (color , 0));
- }
- else{
- color.set(69 + getAgeNorm() * 104, 164 - getAgeNorm() * 95 , 220, (color, (1 - getAgeNorm()) * 255 ));
- }
- }
-
- //-----------------------------------
-
- void Particle::attractParticle(vector<ObjectPhysics*>* objectPhysics, vector<CheckedInVisitor*>* checkedInVisitors){
-
- if(particleIsOnGround == true){
-
- for(int i = 0; i < objectPhysics->size(); i++){
-
- if(( (*objectPhysics).at(i)->type == "attraktor" ) && (objectPhysics->at(i)->attracting == true)){
-
- ofVec2f force;
-
- force.set(objectPhysics->at(i)->getPosition() - position);
-
- if(force.length() < 150){
- velocity += force.getNormalized() * 40;
- }
- if(force.length() < 50){
- velocity -= force.getNormalized() * 20;
- }
-
- }
- }
-
- }
-
- if(particleIsOnGround == false){
-
- for(int i = 0; i < checkedInVisitors->size(); i++){
-
- float ageOfCheckedInVisitor = checkedInVisitors->at(i)->getAge();
-
- if(( ageOfCheckedInVisitor < 30.0 )){
-
- ofVec2f force;
- force.set(checkedInVisitors->at(i)->getBottom() - position);
- float forceLength = force.length();
-
- if(forceLength < 250){
- force = force.getNormalized()* 30 * 4/checkedInVisitors->at(i)->getAge();
- velocity += force;
- }
-
-
- }
- }
-
- }
-
- }
-
- //-----------------------------------
-
-
- float Particle::getAgeNorm(){
-
- return age/maxLife;
-
- }
-
- //-----------------------------------
-
-
- void Particle::updateAngleToCenter(float centerX, float centerY){
-
-
- //case 1 ( distance =< radius )
- ofVec2f center(centerX, centerY);
-
- ofVec2f particleToCenter = position - center;
- //Subtraction: (position of particle) - (position of floor center) = vector between center and particle
-
- ofVec2f referenceVector(0, 0.5);
-
- angleToCenter = particleToCenter.getNormalized().angle(referenceVector.getNormalized());
- angleToCenter = angleToCenter + 180;
-
- //case 2 ( distance > radius
-
-
- }
-
-
-
- //-----------------------------------
-
-
- void Particle::updateDistanceToCenter(float centerX, float centerY, float sceneHeight){
-
- distanceToCenterLastFrame = distanceToCenter;
-
- if(particleIsOnGround == true){
-
- ofVec2f centerOfFloor(centerX, centerY);
- distanceToCenter = position.distance(centerOfFloor);
-
- }
-
- if(particleIsOnGround == false){
-
- distanceToCenter = sceneHeight/2 + sceneHeight - position.y;
-
- }
-
- if(distanceToCenterLastFrame >= sceneHeight/2 && distanceToCenter < sceneHeight/2){
-
- //was passiert wenn es vorher größer als radius war, dann kleiner
- particleJumpedOnGround = true;
-
- }
-
- if(distanceToCenterLastFrame <= sceneHeight/2 && distanceToCenter > sceneHeight/2){
-
- //was passiert wenn es vorher kleiner als radius war, dann größer
- particleJumpedOffGround = true;
-
- }
-
-
- }
-
- //-----------------------------------
-
- bool Particle::isTheSetupPositionOnTheGround(ofVec2f _position, float sceneHeight){
-
-
-
- ofVec2f centerOfFloor(sceneHeight/2, sceneHeight/2);
- distanceToCenter = _position.distance(centerOfFloor);
-
- if(distanceToCenter > (sceneHeight/2)){
-
- return false;
-
- }else{
-
- return true;
-
- }
-
- }
-
- //-----------------------------------
-
-
- void Particle::mapParticle(float sceneWidth, float sceneHeight){
-
- //The mapping works with the information about the particle's distance to the center and its angle to the center (distanceToCenter, angleToCenter).
- //if the particle gets too far away from the center, it will leave the LED-Floor. Then there is a small black gap.
- //After that it will hit the "Stelen". The Stelen are represented by a 360degree circle, 40deg for every Stele, 20deg for every black gap in between.
-
-
- if(particleJumpedOffGround == true){
-
- position.y = sceneHeight - 20;
- //sceneWidth noch ändern damit es sich am kreisumfang orientiert
- position.x = (sceneHeight + angleToCenter/360 * (sceneWidth - sceneHeight));
- position.x += (sceneWidth - sceneHeight)/12 ; //so we dont have 0 deg exactly at the first pixel of the stelen
- if(position.x > sceneWidth){
-
- float difference = position.x - sceneWidth;
- position.x = sceneHeight + difference;
-
- }
-
- ofVec2f referenceVector(0.0, 1.0); //will be used to get an angle of the velocityvector
- referenceVector.getNormalized();
-
- float lotAmKreisZuAustrittspunkt;
-
- if(angleToCenter < 90){
-
- lotAmKreisZuAustrittspunkt = 270 - angleToCenter;
-
- }
- if(angleToCenter >= 90){
-
- lotAmKreisZuAustrittspunkt = angleToCenter - 90;
-
- }
-
- float velocityAngleZuReference = velocity.angle(referenceVector);
- // velocity = velocity.rotate(270 - lotAmKreisZuAustrittspunkt);
- float k = velocity.length();
- velocity.set(0, -k);
- particleJumpedOffGround = false;
-
-
-
- // cout << "particleJumpedOffGround" << endl;
- }
-
- if(particleJumpedOnGround == true){
-
-
- //Vorerst nicht implementiert
- // particleJumpedOnGround = false;
-
- }
-
-
- if(distanceToCenter > sceneHeight/2){
-
- particleIsOnGround = false;
-
- }else if(distanceToCenter <= sceneHeight/2){
-
- particleIsOnGround = true;
-
- }
-
-
-
- //setze bei übertritt einmal y auf sceneHeight
- //setze x genau auf angle/360 * sceneWidth
- //setze velocity neu mit weg über gedrehtes lot (siehe blatt)
- //führe berechnung normal weiter aus
-
-
- //correcting the velocity to the new way it is going to be displayed
-
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|