Projektordner für das Team Deutsches Museum (FORUM).
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 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. #include "ofApp.h"
  2. // *** GLOBALS DEFINITION *** GLOBALS DEFINITION *** GLOBALS DEFINITION *** GLOBALS DEFINITION ****
  3. //--------------------------------------------------------------
  4. void ofApp::setup() {
  5. currentImage = -1;
  6. ofDisableArbTex();
  7. ofBackground(0);
  8. //test image
  9. img.setUseTexture(false);
  10. if (!img.load("testcard.png"))
  11. {
  12. ofLogError("ofApp::setup") << "Could not load image!";
  13. return;
  14. }
  15. this->tex.enableMipmap();
  16. this->tex.loadData(img.getPixels());
  17. //scene properties
  18. sceneSize.set(1280, 800);
  19. area.set(0, 0, sceneSize.x, sceneSize.y);
  20. fbo.allocate(sceneSize.x, sceneSize.y, GL_RGBA);
  21. //clear fbo to make sure there's no scrap
  22. fbo.begin();
  23. ofClear(0);
  24. fbo.end();
  25. //load warp settings from file if present
  26. //this->warpController.loadSettings("settings.json");
  27. //if there is no file, generate warp
  28. if (this->warpController.getWarps().empty())
  29. {
  30. std::shared_ptr<ofxWarpBase> warp;
  31. warp = this->warpController.buildWarp<ofxWarpPerspective>();
  32. warp->setSize(sceneSize.x, sceneSize.y);
  33. warp->setEdges(glm::vec4(0.0f, 0.0f, 1.0f, 1.0f));
  34. }
  35. editingWarp = false;
  36. //testing stuff
  37. ofSetCircleResolution(60);
  38. ofSetBackgroundColor(0, 0, 0);
  39. //ofSetFrameRate(60);
  40. fileImageHex.loadImage("Hexagon.png");
  41. //rainIsActive = true;
  42. //int particleSystemsForStele = 7; //number of rainparticlesystems (one for single stele)
  43. //float sceneSizeForSingleParticleSystem = sceneSize.x / particleSystemsForStele; //calculate the widht for every single rainparticlesystem
  44. //for (int i = 0; i <= particleSystemsForStele - 1; i++) { //create all rainparticlesystem
  45. // rainParticleSyst.push_back(new RainParticleSystem(i * sceneSizeForSingleParticleSystem, sceneSizeForSingleParticleSystem, sceneSize.y));
  46. //}
  47. VISITOR_COUNT = 0;
  48. VISITOR_COUNT_LASTFRAME = 0;
  49. PARTICLE_COUNT = 0;
  50. // *** OSC Setup *** OSC Setup *** OSC Setup ***
  51. receiver.setup(PORT);
  52. }
  53. //--------------------------------------------------------------
  54. void ofApp::update() {
  55. // *** OSC RECEIVER *** OSC RECEIVER *** OSC RECEIVER ***
  56. /*
  57. Here the program will read and convert the information from the tracking, count them & put coordinates of people entering the ground.
  58. We have to define, how this information will affect the particleSystems!
  59. -Create message, put the stuff from the received OSC in it
  60. -duplicate the msg as string to enable onscreen supervision
  61. -There will be a global visitor count called VISITOR_COUNT
  62. -Use VISITOR_COUNT to correctly update the size of the visitors vector
  63. -Iterate trough Message-values and put information in the visitors vector
  64. */
  65. while (receiver.hasWaitingMessages()) {
  66. ofxOscMessage visitorInformations;
  67. receiver.getNextMessage(&visitorInformations);
  68. oscMsg = ofToString(visitorInformations);
  69. if (visitorInformations.getAddress() == "/centroidsOfBlob") {
  70. VISITOR_COUNT_LASTFRAME = VISITOR_COUNT;
  71. VISITOR_COUNT = visitorInformations.getArgAsInt(0); //update the number of Visitors from OSCs first Argument, which is the number of blobs (detected Contours)
  72. // *** CHECK FOR CHANGES IN THE NUMBER OF VISITORS *** CHECK FOR CHANGES IN THE NUMBER OF VISITORS *** CHECK FOR CHANGES IN THE NUMBER OF VISITORS ***
  73. // If there are MORE visitors now, add the difference to the visitors vector
  74. if (VISITOR_COUNT > VISITOR_COUNT_LASTFRAME) {
  75. for (int i = 0; i < (VISITOR_COUNT - VISITOR_COUNT_LASTFRAME); i++) {
  76. visitors.push_back(new Visitor);
  77. }
  78. }
  79. // If there are LESS visitors now, delete the difference from the visitors vector
  80. if (VISITOR_COUNT < VISITOR_COUNT_LASTFRAME) {
  81. for (int i = 0; i < (VISITOR_COUNT_LASTFRAME - VISITOR_COUNT); i++) {
  82. delete visitors.at(visitors.size()); //maybe nicht zulässig, weil fehleranfällig???
  83. //erase ergänzen!
  84. }
  85. }
  86. // *** TRANSFER TRACKING-INFORMATION INTO VISITOR-CLASS *** TRANSFER TRACKING-INFORMATION INTO VISITOR-CLASS ***
  87. for (int i = 1; i <= VISITOR_COUNT; i++) {
  88. //put Information into visitors
  89. float xOfVisitor = visitorInformations.getArgAsFloat(i * 2 - 1) * ofGetWindowWidth();
  90. float yOfVisitor = visitorInformations.getArgAsFloat(i * 2) * ofGetWindowHeight();
  91. visitors.at(i - 1)->setPosition(xOfVisitor, yOfVisitor);
  92. }
  93. } //end of .getAddress() == "/centroidsOfBlob")
  94. } //end of receiver.hasWaitingMessages
  95. // *** RFID Input *** RFID Input *** RFID Input *** RFID Input *** RFID Input ***
  96. /*
  97. Here we have to define, how the particleSystems react to RFID input.
  98. Read ID of a visitor and let the particlesystems react to it.
  99. !!! Here in ofApp.cpp there will only be the transfer of incoming information about IDs, playertypes, etc. into the update-methods of the particleSystems. !!!
  100. For example:
  101. - Tell all particleSystems about a new checkedIn-Visitor
  102. - Set the playerType of one particular particleSystem to the checked in.
  103. */
  104. // *** MAIN UPDATE PARTICLE SYSTEMS *** MAIN UPDATE PARTICLE SYSTEMS *** MAIN UPDATE PARTICLE SYSTEMS ***
  105. for (int p = 0; p < particleSystems.size();)
  106. {
  107. // Update particle systems
  108. // particleSystems.at(p)->update("xxx , xxx , xxx , .... ");
  109. }
  110. if (rainIsActive) { //Movement of the particles of the rainparticlesystems
  111. for (int i = 0; i < rainParticleSyst.size(); i++) {
  112. rainParticleSyst.at(i)->updateParticleSystem();
  113. }
  114. }
  115. else if (!rainIsActive){ //Movement of Imageparticlesystems and symbols when rain is false
  116. for (int i = 0; i < imageParticleSystems.size(); i++) {
  117. imageParticleSystems.at(i)->updateParticleSystem();
  118. }
  119. }
  120. }
  121. //--------------------------------------------------------------
  122. void ofApp::exit() {
  123. //save warp settings on exit
  124. this->warpController.saveSettings("settings.json");
  125. }
  126. //--------------------------------------------------------------
  127. void ofApp::draw() {
  128. fbo.begin();
  129. ofClear(0, 0, 0);
  130. //draw stuff here
  131. //ofDrawRectangle(0, 0, 800, 800);
  132. //ofDrawCircle(sceneSize.x *.5, sceneSize.y * .5, 300);
  133. for (int p = 0; p < particleSystems.size(); p++)
  134. {
  135. particleSystems.at(p)->draw();
  136. }
  137. if (rainIsActive) { //drawing the rainparticlesystems
  138. for (int i = 0; i < rainParticleSyst.size(); i++) {
  139. rainParticleSyst.at(i)->drawRainParticleSystem();
  140. }
  141. }
  142. else if (!rainIsActive) { //drawing the imageparticlesystems
  143. for (int i = 0; i < imageParticleSystems.size(); i++) {
  144. imageParticleSystems.at(i)->drawImageParticleSystem();
  145. }
  146. }
  147. //draw all ParticleSystems that are in the particleSystems vector
  148. fbo.end();
  149. //do not draw past this point
  150. //draw warp
  151. warpController.getWarp(0)->begin();
  152. fbo.draw(0, 0);
  153. warpController.getWarp(0)->end();
  154. }
  155. //--------------------------------------------------------------
  156. void ofApp::keyPressed(int key) {
  157. }
  158. //--------------------------------------------------------------
  159. void ofApp::keyReleased(int key) {
  160. if (key == 'f') //fullscreen
  161. {
  162. ofToggleFullscreen();
  163. }
  164. if (key == 'e') { //Mapping
  165. editingWarp = !editingWarp;
  166. warpController.getWarp(0)->setEditing(editingWarp);
  167. }
  168. //read in the single images and hand over all initial values
  169. switch (key) {
  170. case '1':
  171. imageParticleSystems.push_back(new ImageParticleSystem(sceneSize.x, sceneSize.y, fileImageHex, "PktUmweltTechnik.png"));
  172. rainIsActive = false;
  173. currentImage++;
  174. break;
  175. case '2':
  176. imageParticleSystems.push_back(new ImageParticleSystem(sceneSize.x, sceneSize.y, fileImageHex, "PktAlltagTechnikUmwelt.png"));
  177. rainIsActive = false;
  178. currentImage++;
  179. break;
  180. case '3':
  181. imageParticleSystems.push_back(new ImageParticleSystem(sceneSize.x, sceneSize.y, fileImageHex, "PktAlltagWissenschaftUmwelt.png"));
  182. rainIsActive = false;
  183. currentImage++;
  184. break;
  185. }
  186. }
  187. //--------------------------------------------------------------
  188. void ofApp::mouseMoved(int x, int y) {
  189. }
  190. //--------------------------------------------------------------
  191. void ofApp::mouseDragged(int x, int y, int button) {
  192. }
  193. //--------------------------------------------------------------
  194. void ofApp::mousePressed(int x, int y, int button) {
  195. }
  196. //--------------------------------------------------------------
  197. void ofApp::mouseReleased(int x, int y, int button) {
  198. }
  199. //--------------------------------------------------------------
  200. void ofApp::mouseEntered(int x, int y) {
  201. }
  202. //--------------------------------------------------------------
  203. void ofApp::mouseExited(int x, int y) {
  204. }
  205. //--------------------------------------------------------------
  206. void ofApp::windowResized(int w, int h) {
  207. }
  208. //--------------------------------------------------------------
  209. void ofApp::gotMessage(ofMessage msg) {
  210. }
  211. //--------------------------------------------------------------
  212. void ofApp::dragEvent(ofDragInfo dragInfo) {
  213. }
  214. //--------------------------------------------------------------