This commit is contained in:
Tobias Lindner
2019-04-09 14:07:59 +02:00
parent 8ba9ab9ab2
commit b11dec47f0
13 changed files with 894 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
#include "attractor.h"
Attractor::Attractor()
{
x = 0;
y = 0;
}
//--------------------------------------------------------------------------------------
Attractor::~Attractor()
{
}
//--------------------------------------------------------------------------------------
float Attractor::getY() {
return y;
}
float Attractor::getX() {
return x;
}
void Attractor::setX(float xNew) {
x = xNew;
}
void Attractor::setY(float yNew) {
y = yNew;
}
void Attractor::setup(float xSetup, float ySetup) {
x = xSetup;
y = ySetup;
}
+34
View File
@@ -0,0 +1,34 @@
//
// attractor.h
// particleSystem
//
#include <stdio.h>
class Attractor {
public:
Attractor();
~Attractor();
float getX();
float getY();
void setX(float x);
void setY(float y);
void setup(float x, float y);
private:
//ofVec2f direction
float x;
float y;
float force;
};
+9
View File
@@ -0,0 +1,9 @@
#include "ofMain.h"
#include "ofApp.h"
//========================================================================
int main() {
ofSetupOpenGL(1000, 1000, OF_WINDOW); // <-------- setup the GL context
ofRunApp(new ofApp());
}
+151
View File
@@ -0,0 +1,151 @@
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup() {
//Initialize 8 empty attractrs
for (int i = 0; i < 8; i++)
{
attractors.push_back(new Attractor);
}
//OSC reciever port setup
receiver.setup(PORT);
//Black background
ofSetBackgroundColor(0, 0, 0);
ofSetFrameRate(60);
birthCount = 0;
//attractors.at(0)->setup(200, 200);
}
//--------------------------------------------------------------
void ofApp::update() {
// *** OSC RECEIVER ***
while (receiver.hasWaitingMessages()) {
ofxOscMessage contourCentroids;
receiver.getNextMessage(&contourCentroids);
oscMsg = ofToString(contourCentroids);
//Get active ammount of attractors (nBlobs) and their x & y coordinates
//Exp. OSC Message: " /centroidsOfBlob ammount xValue, yValue"
if (contourCentroids.getAddress() == "/centroidsOfBlob") {
nBlobs = contourCentroids.getArgAsInt(0);
for (int i = 1; i <= nBlobs; i++) {
xOfCentroid = contourCentroids.getArgAsFloat(i * 2 - 1) * ofGetWindowWidth();
yOfCentroid = contourCentroids.getArgAsFloat(i * 2) * ofGetWindowHeight();
attractors.at(i - 1)->setup(xOfCentroid, yOfCentroid);
}
}
//Delete all Attractors on command
if (contourCentroids.getAddress() == "/checkin") {
for (int i = 0; i < 8; i++) {
attractors.at(i)->setup(0, 0);
}
}
}
// *** PARTICLE EMITTER ***
//Capture time based on FrameTime
double deltaT = ofGetLastFrameTime();
birthCount += deltaT;
//Birth control for new particles
if (birthCount > 0.001) {
for (int i = 0;i < 4;i++) {
system.push_back(new thParticle);
system.back()->setup(ofVec2f(ofGetWidth()*.5, ofGetHeight()*.5));
}
birthCount = 0;
}
for (int p = 0; p < system.size();)
{
//Upate particle system /w all active attractors
system.at(p)->update(deltaT, &attractors);
//Delete particles, that reached max Age
if (system.at(p)->getAgeNorm() > 4) {
delete system.at(p);
system.erase(system.begin() + p);
}
else {
p++;
}
}
}
//--------------------------------------------------------------
void ofApp::draw() {
//Draw particle system
for (int p = 0; p < system.size(); p++) {
system.at(p)->draw();
}
//Capture time based on FrameTime
double deltaT = ofGetLastFrameTime();
time += deltaT;
// Delete inactive attractors after 4 seconds based on Frametime
if (time > 2) {
for (int i = 0; i < 8; i++) {
//attractors.at(i)->setup(0, 0);
time = 0;
}
}
// *** DEBUG INFO ***
//All 8 Attractors with x | y coordinates
for (int i = 0; i < 8; i++) {
//string x = ofToString(attractors.at(i)->getX());
//string y = ofToString(attractors.at(i)->getY());
//ofDrawBitmapString("x: " + x + " y: " + y, 100, 100 + i * 20);
}
//Recieved OSC messages
//ofDrawBitmapString("OSC: " + ofToString(oscMsg),100, 275);
//Elapsed time since last clear of attractors
//ofDrawBitmapString("Time: " + ofToString(time),100, 300);
//Current FPS
//ofDrawBitmapString("FPS: " + ofToString(ofGetFrameRate()), 100, 325);
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key) {
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key) {
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y) {
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button) {
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button) {
}
+44
View File
@@ -0,0 +1,44 @@
#pragma once
#include "ofMain.h"
#include "particle.h"
#include "ofxOsc.h"
#include "ofxGui.h"
//OSC Reciever PORT & HOST IP
#define PORT 12345
#define HOST "172.20.10.2"
class ofApp : public ofBaseApp {
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
private:
// OSC Receiver
string oscMsg;
ofxOscReceiver receiver;
float timeSent, timeReceived;
int nBlobs;
int blobCount;
float xOfCentroid;
float yOfCentroid;
vector<thParticle*> system;
vector<Attractor*> attractors;
float birthCount;
double time;
};
BIN
View File
Binary file not shown.
+43
View File
@@ -0,0 +1,43 @@
#pragma once
#include "ofMain.h"
#include "attractor.h"
class thParticle
{
public:
thParticle();
~thParticle();
void setup(ofVec2f position);
void update(float deltaT, vector<Attractor*>* attractors);
// void update(float deltaT, ofVec2f attractor);
//Partikel wird komplett upgedated (Bewegung, Farbe, etc...)
//deltaT Zeitintervall seit letztem Update
void draw(); //Partikel anzeigen
float getAgeNorm();
float getMaxLife();
ofImage tex;
private:
int counterOfActiveAttractors;
ofVec2f vel;
ofVec2f position;
float maxLife;
float age;
float size;
float mass;
int blobCounterInParticle;
ofColor color;
};