Quelcode des Partikelsystems Boden
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ofApp.cpp 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #include "ofApp.h"
  2. //--------------------------------------------------------------
  3. void ofApp::setup() {
  4. //Initialize 8 empty attractrs
  5. for (int i = 0; i < 8; i++)
  6. {
  7. attractors.push_back(new Attractor);
  8. }
  9. //OSC reciever port setup
  10. receiver.setup(PORT);
  11. //Black background
  12. ofSetBackgroundColor(0, 0, 0);
  13. ofSetFrameRate(60);
  14. birthCount = 0;
  15. //attractors.at(0)->setup(200, 200);
  16. }
  17. //--------------------------------------------------------------
  18. void ofApp::update() {
  19. // *** OSC RECEIVER ***
  20. while (receiver.hasWaitingMessages()) {
  21. ofxOscMessage contourCentroids;
  22. receiver.getNextMessage(&contourCentroids);
  23. oscMsg = ofToString(contourCentroids);
  24. //Get active ammount of attractors (nBlobs) and their x & y coordinates
  25. //Exp. OSC Message: " /centroidsOfBlob ammount xValue, yValue"
  26. if (contourCentroids.getAddress() == "/centroidsOfBlob") {
  27. nBlobs = contourCentroids.getArgAsInt(0);
  28. for (int i = 1; i <= nBlobs; i++) {
  29. xOfCentroid = contourCentroids.getArgAsFloat(i * 2 - 1) * ofGetWindowWidth();
  30. yOfCentroid = contourCentroids.getArgAsFloat(i * 2) * ofGetWindowHeight();
  31. attractors.at(i - 1)->setup(xOfCentroid, yOfCentroid);
  32. }
  33. }
  34. //Delete all Attractors on command
  35. if (contourCentroids.getAddress() == "/checkin") {
  36. for (int i = 0; i < 8; i++) {
  37. attractors.at(i)->setup(0, 0);
  38. }
  39. }
  40. }
  41. // *** PARTICLE EMITTER ***
  42. //Capture time based on FrameTime
  43. double deltaT = ofGetLastFrameTime();
  44. birthCount += deltaT;
  45. //Birth control for new particles
  46. if (birthCount > 0.001) {
  47. for (int i = 0;i < 4;i++) {
  48. system.push_back(new thParticle);
  49. system.back()->setup(ofVec2f(ofGetWidth()*.5, ofGetHeight()*.5));
  50. }
  51. birthCount = 0;
  52. }
  53. for (int p = 0; p < system.size();)
  54. {
  55. //Upate particle system /w all active attractors
  56. system.at(p)->update(deltaT, &attractors);
  57. //Delete particles, that reached max Age
  58. if (system.at(p)->getAgeNorm() > 4) {
  59. delete system.at(p);
  60. system.erase(system.begin() + p);
  61. }
  62. else {
  63. p++;
  64. }
  65. }
  66. }
  67. //--------------------------------------------------------------
  68. void ofApp::draw() {
  69. //Draw particle system
  70. for (int p = 0; p < system.size(); p++) {
  71. system.at(p)->draw();
  72. }
  73. //Capture time based on FrameTime
  74. double deltaT = ofGetLastFrameTime();
  75. time += deltaT;
  76. // Delete inactive attractors after 4 seconds based on Frametime
  77. if (time > 2) {
  78. for (int i = 0; i < 8; i++) {
  79. //attractors.at(i)->setup(0, 0);
  80. time = 0;
  81. }
  82. }
  83. // *** DEBUG INFO ***
  84. //All 8 Attractors with x | y coordinates
  85. for (int i = 0; i < 8; i++) {
  86. //string x = ofToString(attractors.at(i)->getX());
  87. //string y = ofToString(attractors.at(i)->getY());
  88. //ofDrawBitmapString("x: " + x + " y: " + y, 100, 100 + i * 20);
  89. }
  90. //Recieved OSC messages
  91. //ofDrawBitmapString("OSC: " + ofToString(oscMsg),100, 275);
  92. //Elapsed time since last clear of attractors
  93. //ofDrawBitmapString("Time: " + ofToString(time),100, 300);
  94. //Current FPS
  95. //ofDrawBitmapString("FPS: " + ofToString(ofGetFrameRate()), 100, 325);
  96. }
  97. //--------------------------------------------------------------
  98. void ofApp::keyPressed(int key) {
  99. }
  100. //--------------------------------------------------------------
  101. void ofApp::keyReleased(int key) {
  102. }
  103. //--------------------------------------------------------------
  104. void ofApp::mouseMoved(int x, int y) {
  105. }
  106. //--------------------------------------------------------------
  107. void ofApp::mousePressed(int x, int y, int button) {
  108. }
  109. //--------------------------------------------------------------
  110. void ofApp::mouseReleased(int x, int y, int button) {
  111. }