|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- #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) {
-
- }
-
|