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 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  1. #include "ofApp.h"
  2. // *** GLOBALS DEFINITION *** GLOBALS DEFINITION *** GLOBALS DEFINITION *** GLOBALS DEFINITION ****
  3. //--------------------------------------------------------------
  4. void ofApp::setup(){
  5. // *** SETUP STUFF FOR MAPPING ***
  6. setupWarpStuff();
  7. // *** SETUP STUFF FOR PROGRAM ***
  8. sceneHeight = ofGetHeight();
  9. sceneWidth = ofGetWidth();
  10. ofSetBackgroundColor(0,0,0);
  11. COUNT_VISITORS = 0;
  12. COUNT_VISITORS_LASTFRAME = 0;
  13. COUNT_PARTICLES = 0;
  14. COUNT_PARTICLESYSTEMS = 0;
  15. COUNT_OBJECTPHYSICS = 0;
  16. COUNT_CHECKEDINVISITORS = 0;
  17. activeTypeOfView = LOGIC;
  18. currentMode = PARTICLE_MODE_DEFAULT;
  19. currentModeHasChanged = false;
  20. deltaT = ofGetLastFrameTime();
  21. logicalBackground.load("images/logicalBackground2.png");
  22. // *** OBJECT PHYSICS SETUP *** OBJECT PHYSICS SETUP *** OBJECT PHYSICS SETUP *** OBJECT PHYSICS SETUP ***
  23. //maybe xml default load?
  24. //we can generate all the fix emitters.
  25. //1 in the center
  26. //6 at the "stelen"-bottoms
  27. //6 at the "stelen"-tops
  28. // *** VERSUCH MIT ofxXmlSettings ***
  29. // cout << xmlForSetup.load("xml/setup.xml") << endl;
  30. xmlForSetup.loadFile("xml/setup.xml");
  31. centerOfScene.x = xmlForSetup.getValue("setup:center:x" , 0.0) * ofGetHeight();
  32. centerOfScene.y = xmlForSetup.getValue("setup:center:y" , 0.0) * ofGetHeight();
  33. stele1_bottom.x = xmlForSetup.getValue("setup:stele1:x" , 0.0 ) * ofGetHeight();
  34. stele1_bottom.y = xmlForSetup.getValue("setup:stele1:y" , 0.0 ) * ofGetHeight();
  35. stele2_bottom.x = xmlForSetup.getValue("setup:stele2:x" , 0.0 ) * ofGetHeight();
  36. stele2_bottom.y = xmlForSetup.getValue("setup:stele2:y" , 0.0 ) * ofGetHeight();
  37. stele3_bottom.x = xmlForSetup.getValue("setup:stele3:x" , 0.0 ) * ofGetHeight();
  38. stele3_bottom.y = xmlForSetup.getValue("setup:stele3:y" , 0.0 ) * ofGetHeight();
  39. stele4_bottom.x = xmlForSetup.getValue("setup:stele4:x" , 0.0 ) * ofGetHeight();
  40. stele4_bottom.y = xmlForSetup.getValue("setup:stele4:y" , 0.0 ) * ofGetHeight();
  41. stele5_bottom.x = xmlForSetup.getValue("setup:stele5:x" , 0.0 ) * ofGetHeight();
  42. stele5_bottom.y = xmlForSetup.getValue("setup:stele5:y" , 0.0 ) * ofGetHeight();
  43. stele6_bottom.x = xmlForSetup.getValue("setup:stele6:x" , 0.0 ) * ofGetHeight();
  44. stele6_bottom.y = xmlForSetup.getValue("setup:stele6:y" , 0.0 ) * ofGetHeight();
  45. // visitors.emplace_back(new Visitor);
  46. // visitors.emplace_back(new Visitor);
  47. // objectPhysics.emplace_back(new Attraktor(visitors.at(0)->getPosition()));
  48. // objectPhysics.emplace_back(new Attraktor(visitors.at(1)->getPosition()));
  49. objectPhysics.emplace_back(new Emitter(centerOfScene));
  50. // objectPhysics.emplace_back(new Emitter(stele1_bottom));
  51. //// objectPhysics.emplace_back(new Emitter(stele1_top));
  52. // objectPhysics.emplace_back(new Emitter(stele2_bottom));
  53. //// objectPhysics.emplace_back(new Emitter(stele2_top));
  54. // objectPhysics.emplace_back(new Emitter(stele3_bottom));
  55. //// objectPhysics.emplace_back(new Emitter(stele3_top));
  56. // objectPhysics.emplace_back(new Emitter(stele4_bottom));
  57. //// objectPhysics.emplace_back(new Emitter(stele4_top));
  58. // objectPhysics.emplace_back(new Emitter(stele5_bottom));
  59. //// objectPhysics.emplace_back(new Emitter(stele5_top));
  60. // objectPhysics.emplace_back(new Emitter(stele6_bottom));
  61. //// objectPhysics.emplace_back(new Emitter(stele6_top));
  62. ////
  63. for (int i = 0; i < particleSystems.size(); i++){
  64. }
  65. // *** OSC Setup *** OSC Setup *** OSC Setup ***
  66. receiver.setup(PORT);
  67. // std::cout << "breakpoint ofApp_1 erreicht" << std::endl;
  68. // *** TESTINGAREA *** TESTINGAREA *** TESTINGAREA *** TESTINGAREA *** TESTINGAREA ***
  69. // objectPhysics.emplace_back(new Emitter(150, 150));
  70. // objectPhysics.emplace_back(new Emitter(400, 200));
  71. //
  72. //
  73. particleSystems.emplace_back(new ParticleSystem);
  74. particleSystems.back()->setup();
  75. // objectPhysics.emplace_back(new AttraktorAufStelen( 1200 , 500));
  76. // std::cout << "breakpoint ofApp_2, ofApp setup beendet" << std::endl;
  77. }
  78. //--------------------------------------------------------------
  79. void ofApp::update(){
  80. // sceneHeight = ofGetHeight();
  81. // if(sceneHeight != sceneHeightLastFrame){
  82. // // refreshXML
  83. // }
  84. if(currentMode == PARTICLE_MODE_POLYMESH){
  85. timerAfterCheckin += deltaT;
  86. if(timerAfterCheckin >= 7){
  87. currentMode = PARTICLE_MODE_DEFAULT;
  88. timerAfterCheckin = 0;
  89. }
  90. }
  91. deltaT = ofGetLastFrameTime();
  92. // *** TESTING AREA ***
  93. // objectPhysics.front()->setPosition(visitors.at(0)->getPosition());
  94. // objectPhysics.at(1)->setPosition(visitors.at(1)->getPosition());
  95. // for(int i = 0; i < objectPhysics.size(); i++){
  96. //
  97. // objectPhysics.at(i)->update(deltaT);
  98. // if(objectPhysics.at(i)->getAge() > 4){
  99. //
  100. // delete objectPhysics.at(i);
  101. // objectPhysics.erase(objectPhysics.begin() + i);
  102. //
  103. // }
  104. // }
  105. // *** READ ATTRAKTORS FROM CHECKEDINVISITORS ***
  106. // *** OSC RECEIVER *** OSC RECEIVER *** OSC RECEIVER ***
  107. /*
  108. Here the program will read and convert the information from the tracking, count them & put coordinates of people entering the ground.
  109. We have to define, how this information will affect the particleSystems!
  110. -Create message, put the stuff from the received OSC in it
  111. -duplicate the msg as string to enable onscreen supervision
  112. -There will be a global visitor count called VISITOR_COUNT
  113. -Use VISITOR_COUNT to correctly update the size of the visitors vector
  114. -Iterate trough Message-values and put information in the visitors vector
  115. */
  116. COUNT_VISITORS_LASTFRAME = visitors.size();
  117. if(receiver.hasWaitingMessages() == false){
  118. COUNT_VISITORS = 0;
  119. }
  120. while(receiver.hasWaitingMessages()){
  121. ofxOscMessage checkinInformations;
  122. receiver.getNextMessage(&checkinInformations);
  123. oscMsg = ofToString(checkinInformations);
  124. cout << "tracking message incoming" << endl;
  125. COUNT_VISITORS = checkinInformations.getArgAsInt(0);
  126. cout << COUNT_VISITORS << endl;
  127. //Größe des visitor-vectors wird festgelegt und auf die größe der ankommenden Trackingdaten angepasst
  128. if(checkinInformations.getAddress() == "/centroidsOfBlob") {
  129. if(COUNT_VISITORS_LASTFRAME != COUNT_VISITORS){
  130. if(COUNT_VISITORS_LASTFRAME < COUNT_VISITORS){
  131. for(int i = 0; i < COUNT_VISITORS - COUNT_VISITORS_LASTFRAME; i++){
  132. visitors.emplace_back(new Visitor);
  133. objectPhysics.emplace_back(new Attraktor(visitors.back()->getPosition()));
  134. objectPhysics.back()->setIsVisitor(true);
  135. }
  136. }else{
  137. for(int i = 0; i < COUNT_VISITORS_LASTFRAME - COUNT_VISITORS; i++){
  138. delete visitors.back();
  139. visitors.pop_back();
  140. delete objectPhysics.back();
  141. objectPhysics.pop_back();
  142. }
  143. }
  144. }
  145. //Fill the visitors vector with the OSC data!
  146. for(int i = 1; i < visitors.size() +1; i++){
  147. //put Information into visitors
  148. float xOfVisitor = checkinInformations.getArgAsFloat(i * 2 - 1);
  149. float yOfVisitor = checkinInformations.getArgAsFloat(i * 2) ;
  150. visitors.at( i - 1 )->setPosition(xOfVisitor, yOfVisitor);
  151. }
  152. }
  153. if(checkinInformations.getAddress() == "/players"){
  154. stele = getSteleForCheckin(checkinInformations.getArgAsFloat(0)) + 2;
  155. playerType = getTypeForCheckin(checkinInformations.getArgAsFloat(1));
  156. // cout << oscMsg << endl;
  157. }
  158. if(checkinInformations.getAddress() == "/go"){
  159. checkedInVisitors.emplace_back(new CheckedInVisitor());
  160. checkedInVisitors.back()->setup(playerType , stele , sceneWidth, sceneHeight);
  161. if (currentMode != PARTICLE_MODE_POLYMESH){
  162. std::cout << "change of mode to DEFAULT" << std::endl;
  163. currentMode = PARTICLE_MODE_POLYMESH;
  164. currentModeHasChanged = true;
  165. }
  166. }
  167. }
  168. //
  169. // while(receiver.hasWaitingMessages()){
  170. //
  171. // ofxOscMessage visitorInformations;
  172. // receiver.getNextMessage(&visitorInformations);
  173. //
  174. // oscMsg = ofToString(visitorInformations);
  175. //
  176. // if(visitorInformations.getAddress() == "/centroidsOfBlob") {
  177. //
  178. // cout << "tracking message incoming" << endl;
  179. // COUNT_VISITORS_LASTFRAME = COUNT_VISITORS;
  180. // COUNT_VISITORS = visitorInformations.getArgAsInt(0); //first Arg of OSC-Message is number of Blobs
  181. //
  182. //
  183. //
  184. //// *** CHECK FOR CHANGES IN THE NUMBER OF VISITORS *** CHECK FOR CHANGES IN THE NUMBER OF VISITORS *** CHECK FOR CHANGES IN THE NUMBER OF VISITORS ***
  185. //
  186. //
  187. //// If there are MORE visitors now, add the difference to the visitors vector
  188. //
  189. //
  190. // if(COUNT_VISITORS > COUNT_VISITORS_LASTFRAME){
  191. //
  192. // for(int i = 0; i < (COUNT_VISITORS - COUNT_VISITORS_LASTFRAME); i++){
  193. //
  194. // visitors.emplace_back(new Visitor);
  195. // COUNT_VISITORS++;
  196. //
  197. //
  198. //
  199. // }
  200. // }
  201. //
  202. //
  203. //// If there are LESS visitors now, delete the difference from the visitors vector
  204. //
  205. //
  206. // if(COUNT_VISITORS < COUNT_VISITORS_LASTFRAME){
  207. //
  208. // for(int i = 0; i < (COUNT_VISITORS_LASTFRAME - COUNT_VISITORS); i++){
  209. //
  210. // delete visitors.at(visitors.size()); //maybe nicht zulässig, weil fehleranfällig???
  211. // //erase ergänzen!
  212. // COUNT_VISITORS--;
  213. // }
  214. //
  215. // }
  216. //
  217. //
  218. //// *** TRANSFER TRACKING-INFORMATION INTO VISITOR-CLASS *** TRANSFER TRACKING-INFORMATION INTO VISITOR-CLASS ***
  219. //
  220. //
  221. // for(int i = 1; i <= COUNT_VISITORS; i++){
  222. //
  223. // //put Information into visitors
  224. //
  225. // float xOfVisitor = visitorInformations.getArgAsFloat(i * 2 - 1) * sceneWidth;
  226. // float yOfVisitor = visitorInformations.getArgAsFloat(i * 2) * sceneHeight;
  227. //
  228. // visitors.at( i - 1 )->setPosition(xOfVisitor, yOfVisitor);
  229. //
  230. // }
  231. //
  232. // } //end of .getAddress() == "/centroidsOfBlob")
  233. //
  234. // } //end of receiver.hasWaitingMessages
  235. //
  236. // std::cout << "breakpoint ofApp_3 erreicht, OSC-Datenverarbeitung beendet" << std::endl;
  237. // *** RFID Input *** RFID Input *** RFID Input *** RFID Input *** RFID Input ***
  238. // *** GENERATE CHECKED IN VISITOR *** GENERATE CHECKED IN VISITOR *** GENERATE CHECKED IN VISITOR ***
  239. //if key 'v' is pressed, a new checkedInVisitor will be generated
  240. /*
  241. Here we have to define, how the particleSystems react to RFID input.
  242. Read ID of a visitor and let the particlesystems react to it.
  243. !!! Here in ofApp.cpp there will only be the transfer of incoming information
  244. //about IDs, playertypes, etc. into the update-methods of the particleSystems. !!!
  245. For example:
  246. - Tell all particleSystems about a new checkedIn-Visitor
  247. - Set the playerType of one particular particleSystem to the checked in.
  248. */
  249. // *** OBJECT PHYSICS UPDATE *** OBJECT PHYSICS UPDATE *** OBJECT PHYSICS UPDATE *** OBJECT PHYSICS UPDATE ***
  250. //update the objectPhysics, like creating Attractors for visitors in the default mode
  251. //get the begin in the object physics vector with visitor information, then set all remaining objectphysics
  252. int beginOfVisitorsInObjectPhysics = getBeginOfVisitorsInObjectPhysics();
  253. if(visitors.size()){
  254. refreshCoordinatesOfVisitorAttraktors(beginOfVisitorsInObjectPhysics, sceneHeight);
  255. }
  256. // int visitorIterator = 0;
  257. // for(beginOfVisitorsInObjectPhysics; beginOfVisitorsInObjectPhysics < (visitors.size()+beginOfVisitorsInObjectPhysics); beginOfVisitorsInObjectPhysics++){
  258. //
  259. // objectPhysics.at(beginOfVisitorsInObjectPhysics)->setPosition(visitors.at(visitorIterator)->getPosition());
  260. // visitorIterator++;
  261. // }
  262. // if(COUNT_VISITORS > visitors.size()){
  263. // for(int i = 0; i < (COUNT_VISITORS - COUNT_VISITORS_LASTFRAME); i++){
  264. //
  265. // objectPhysics.emplace_back(new Attraktor(visitors.at(i)->getPosition()));
  266. // objectPhysics.at(i)->setIsVisitor(true);
  267. //
  268. // }
  269. // }
  270. //
  271. // if(COUNT_VISITORS < COUNT_VISITORS_LASTFRAME){
  272. // for(int i = 0; i < (COUNT_VISITORS_LASTFRAME - COUNT_VISITORS); i++){
  273. //
  274. //
  275. // // delete objectPhysics.at(i);
  276. //
  277. // }
  278. // }
  279. //adding/killing/modifying of emitters/attractors (objectPhysics)
  280. //Following "if" will guarantee, that we only go into the switch once, if the currentModeHasChanged = true
  281. //Like this we can setup stuff in the update method, without doing it every update
  282. if(currentMode != lastMode){
  283. currentModeHasChanged = true;
  284. }
  285. if(currentModeHasChanged == true){
  286. switch (currentMode){
  287. // *** DEFAULT OBJECTPHYSICS *** DEFAULT OBJECTPHYSICS ***
  288. case PARTICLE_MODE_DEFAULT: {
  289. for(int i = 0; i < objectPhysics.size(); i++){
  290. if( (objectPhysics).at(i)->type == "emitter" ){
  291. (objectPhysics).at(i)->setEmitting(true);
  292. }
  293. }
  294. currentModeHasChanged = false;
  295. break;
  296. }
  297. // *** POLYMESH OBJECTPHYSICS *** POLYMESH OBJECTPHYSICS ***
  298. case PARTICLE_MODE_POLYMESH: {
  299. for(int i = 0; i < objectPhysics.size(); i++){
  300. if( (objectPhysics).at(i)->type == "emitter" ){
  301. (objectPhysics).at(i)->setEmitting(false);
  302. }
  303. }
  304. /*
  305. implement here: Visitors are Attraktors
  306. implement here: Visitors are Attraktors
  307. implement here: Visitors are Attraktors
  308. set every visitorrelated ObjectPhysics to attracting = true
  309. for(int i = 0; i < objectPhysics.size(); i++){
  310. if( (objectPhysics).at(i)->type == "attraktor" && objectPhysics).at(i)->isAVisitorObject == true ){
  311. (objectPhysics).at(i)->setAttracting(true);
  312. }
  313. }
  314. */
  315. currentModeHasChanged = false;
  316. break;
  317. }
  318. // *** RFID OBJECTPHYSICS & GENERATING CHECKEDINVISITORS ***
  319. case PARTICLE_MODE_RFID: {
  320. for(int i = 0; i < objectPhysics.size(); i++){
  321. if( (objectPhysics).at(i)->type == "emitter" ){
  322. (objectPhysics).at(i)->setEmitting(false);
  323. }
  324. }
  325. // checkedInVisitors.emplace_back(new CheckedInVisitor);
  326. //5 is the stele where it will be displayed, in the future this number will
  327. //depend on the input, maybe the position ! (check position.distance(stele1-stele6) and
  328. //do the setup for the closest stele, maybe this can be implemented in the setup
  329. // checkedInVisitors.back->setStele(5);
  330. // checkedInVisitors.back->setup(playerType that is transmitted by RFID);
  331. currentModeHasChanged = false;
  332. break;
  333. }
  334. default:
  335. int a = 0;
  336. }
  337. }
  338. // *** UPDATE THE CHECKEDINVISITORS *** UPDATE THE CHECKEDINVISITORS ***
  339. // int beginOfCheckedInVisitors; //returns the position in the objectPhysics-vector that is an checkedInVisitorEmitter
  340. // for(int i = 0; i < objectPhysics.size(); i++){
  341. // if(objectPhysics.at(i)->type == "emitterOnStele"){
  342. //
  343. // beginOfCheckedInVisitors = i;
  344. // break;
  345. // }
  346. // }
  347. for(int i = 0; i < checkedInVisitors.size(); i++){
  348. checkedInVisitors.at(i)->update(deltaT, sceneWidth, sceneHeight);
  349. // //delete the Emitter on the visitors bottom if the visitor gets older than 3 (number can be replaced later)
  350. if(checkedInVisitors.at(i)->getAge() > 50){
  351. delete checkedInVisitors.at(i);
  352. checkedInVisitors.erase(checkedInVisitors.begin() + i);
  353. }
  354. }
  355. // if(checkedInVisitors.at(i)->getStateOfSetup()==false){
  356. //
  357. // objectPhysics.emplace_back(new AttraktorOnStele(checkedInVisitors.at(i)->getPosition()));
  358. // checkedInVisitors.at(i)->setStateOfSetup(true);
  359. // }
  360. // else if(checkedInVisitors.at(i)->getStateOfSetup()==true){
  361. //
  362. // objectPhysics.back()->setPosition(checkedInVisitors.at(i)->getPosition());
  363. //
  364. // }
  365. //
  366. // if(checkedInVisitors.at(i)->getStateOfSetup()==false){
  367. //
  368. // for(int cv = 0; cv < checkedInVisitors.at(i)->attractingPixelsOfHexagon.size(); cv++){
  369. //
  370. // objectPhysics.emplace_back(new AttraktorOnStele(checkedInVisitors.at(i)->getPositionsOfAttractingPixels().at(cv)));
  371. // checkedInVisitors.at(i)->setStateOfSetup(true);
  372. //
  373. // }
  374. // }
  375. // *** MAIN UPDATE PARTICLE SYSTEMS *** MAIN UPDATE PARTICLE SYSTEMS *** MAIN UPDATE PARTICLE SYSTEMS ***
  376. //Trigger the TORNADO if there are more then 4 visitors and then make the effect sleep for a while
  377. tornadoTimer += deltaT;
  378. if(tornadoTimer > 30000){
  379. tornadoIsPossible = true;
  380. }
  381. if(tornadoIsPossible == true){
  382. if(COUNT_VISITORS > 4){
  383. currentMode = PARTICLE_MODE_TORNADO;
  384. tornadoIsPossible = false;
  385. tornadoTimer = 0;
  386. }
  387. }
  388. for (int p = 0; p < particleSystems.size(); p++){
  389. // Update particle systems
  390. //How to modify a specific particleSystem?
  391. //Scenario: ParticleSystem 5 should become a dot connecting system
  392. // if p=5 dann particleMode = PARTICLE_MODE_POLYMESH
  393. particleSystems.at(p)->update(deltaT, currentMode, &objectPhysics, &checkedInVisitors, sceneWidth, sceneHeight);
  394. // if( neues xml soll übergeben werden, zB taste/zeit)
  395. // particleSystems.at(p)->loadXML(&xml);
  396. }
  397. // std::cout << "breakpoint ofApp_4 erreicht, particleSystem.update beendet" << std::endl;
  398. //Zähle alle Partikel
  399. COUNT_PARTICLES = 0;
  400. for(int i = 0; i < particleSystems.size(); i++)
  401. {
  402. int particlesInThisSystem = particleSystems.at(i)->particles.size();
  403. COUNT_PARTICLES += particlesInThisSystem;
  404. }
  405. lastMode = currentMode;
  406. sceneHeightLastFrame = sceneHeight;
  407. } //end of update()
  408. //--------------------------------------------------------------
  409. void ofApp::draw(){
  410. fbo_warp.begin();
  411. ofClear(0, 0, 0);
  412. //draw all ParticleSystems that are in the particleSystems vector
  413. for(int p = 0; p < particleSystems.size(); p++)
  414. {
  415. particleSystems.at(p)->draw(activeTypeOfView);
  416. }
  417. // *** TESTING AREA DRAW *** TESTING AREA DRAW ***
  418. for(int i = 0; i < checkedInVisitors.size() ; i++){
  419. checkedInVisitors.at(i)->draw();
  420. }
  421. // drawStelen(sceneWidth, sceneHeight);
  422. // ---------------------------
  423. //Which view is active and how it will look can be found and modified here:
  424. if(activeTypeOfView == LOGIC){
  425. drawLogicalScene(ofGetWidth(), ofGetHeight());
  426. }
  427. if(activeTypeOfView == MAPPED){
  428. // drawMappedScene(ofGetWidth(), ofGetHeight());
  429. }
  430. fbo_warp.end();
  431. // FIRST WARP
  432. warpControllerCircle.getWarp(0)->begin();
  433. fbo_warp.getTexture().drawSubsection(0, 0, 3840, 1200, 0, 0, 1200, 1200);
  434. //fbo_circle.draw(0, 0);
  435. warpControllerCircle.getWarp(0)->end();
  436. // SECOND WARP
  437. warpControllerStele1.getWarp(0)->begin();
  438. fbo_warp.getTexture().drawSubsection(0, 0, 3840, 1200, 2204.444, 0, 293.3333, 1200);
  439. warpControllerStele1.getWarp(0)->end();
  440. // THIRD WARP
  441. warpControllerStele2.getWarp(0)->begin();
  442. fbo_warp.getTexture().drawSubsection(0, 0, 3840, 1200, 2631.1111, 0, 293.3333, 1200);
  443. warpControllerStele2.getWarp(0)->end();
  444. // FOURTH WARP
  445. warpControllerStele3.getWarp(0)->begin();
  446. fbo_warp.getTexture().drawSubsection(0, 0, 3840, 1200, 3057.7773, 0, 293.3333, 1200);
  447. warpControllerStele3.getWarp(0)->end();
  448. //Supervision of globals
  449. string countVisitors = ofToString(visitors.size());
  450. string countParticles = ofToString(COUNT_PARTICLES);
  451. string countParticleSystems = ofToString(particleSystems.size());
  452. string countObjectPhysics = ofToString(objectPhysics.size());
  453. string countCheckedInVisitors = ofToString(checkedInVisitors.size());
  454. ofSetColor(255,255,255);
  455. ofDrawBitmapString("framerate: " + ofToString(ofGetFrameRate()), sceneWidth*0.05, sceneHeight*0.70);
  456. ofDrawBitmapString("windowWidth: " + ofToString(ofGetWidth()), sceneWidth*0.05, sceneHeight*0.72);
  457. ofDrawBitmapString("windowHeight: " + ofToString(ofGetHeight()), sceneWidth*0.05, sceneHeight*0.74);
  458. ofDrawBitmapString("currentMode: " + ofToString(getCurrentModeAsString()), sceneWidth*0.05, sceneHeight*0.76 );
  459. ofDrawBitmapString("visitors: " + countVisitors, sceneWidth*0.05, sceneHeight*0.80);
  460. ofDrawBitmapString("checkedInVisitors: " + countCheckedInVisitors, sceneWidth*0.05, sceneHeight*0.82);
  461. ofDrawBitmapString("particleSystems: " + countParticleSystems, sceneWidth*0.05, sceneHeight*0.86);
  462. ofDrawBitmapString("particles: " + countParticles, sceneWidth*0.05, sceneHeight*0.88);
  463. ofDrawBitmapString("objectphysics: " + countObjectPhysics, sceneWidth*0.05, sceneHeight*0.9);
  464. // ofDrawBitmapString(ofToString(objectPhysics.at(0)->getPosition()), 100, 500);
  465. if(checkedInVisitors.size()){
  466. ofDrawBitmapString("oldest Visitor: " + ofToString(checkedInVisitors.at(0)->getAge()), sceneWidth*0.05, sceneHeight*0.94);
  467. }
  468. // std::cout << "breakpoint ofApp_5 erreicht, supervision globals beendet" << std::endl;
  469. //Supervision of visitors
  470. for (int i = 0; i < visitors.size(); i++) {
  471. string x = ofToString(visitors.at(i)->getX());
  472. string y = ofToString(visitors.at(i)->getY());
  473. ofDrawBitmapString("x: " + x + " y: " + y, 100, 100 + i * 20);
  474. }
  475. // std::cout << "breakpoint ofApp_6 erreicht, supervision visitors beendet" << std::endl;
  476. // std::cout << "breakpoint ofApp_7 erreicht, drawing_ofApp beendet" << std::endl;
  477. }
  478. //--------------------------------------------------------------
  479. void ofApp::drawMappedScene(float sceneWidth, float sceneHeight){
  480. float xToDrawNextRect = - (sceneWidth / 18);
  481. for(int i = 0; i < 7; i++){
  482. //draw 40/360 noFill rect and then increase the x for the next
  483. ofNoFill();
  484. ofDrawRectangle(xToDrawNextRect, 0.5*sceneHeight, sceneWidth/9, 0.5*sceneHeight);
  485. xToDrawNextRect += sceneWidth/9;
  486. ofFill();
  487. //draw 20/360 black rect and then increase the x for the next
  488. ofDrawRectangle(xToDrawNextRect, 0.5*sceneHeight, sceneWidth/18, 0.5*sceneHeight);
  489. xToDrawNextRect += sceneWidth/18;
  490. }
  491. }
  492. //--------------------------------------------------------------
  493. void ofApp::drawGrid(float sceneWidth, float sceneHeight, int rows, int columns){
  494. ofSetColor(50,50,50);
  495. //draw columns
  496. for(int i = 0; i < columns-1; i++){
  497. float xStart = (sceneWidth/columns) * (i+1);
  498. float xEnd = xStart;
  499. float yStart = 0;
  500. float yEnd = sceneHeight;
  501. ofDrawLine(xStart, yStart, xEnd, yEnd);
  502. }
  503. //draw rows
  504. for(int i = 0; i < rows-1; i++){
  505. float yStart = (sceneHeight/rows) * (i+1);
  506. float yEnd = yStart;
  507. float xStart = 0;
  508. float xEnd = sceneWidth;
  509. ofDrawLine(xStart, yStart, xEnd, yEnd);
  510. }
  511. }
  512. //--------------------------------------------------------------
  513. void ofApp::drawStelen(float sceneWidth, float sceneHeight){
  514. ofSetColor(60,60,60);
  515. float widthStele = (sceneWidth - sceneHeight) / 9;
  516. float heightStele = widthStele*3.5;
  517. float yToDraw = sceneHeight - heightStele;
  518. float xBegin = sceneHeight;
  519. //draw rectangles
  520. // for(int i = 0; i < 6; i++){
  521. //
  522. // float xToDraw = sceneHeight*0.5 + i * 1.5 * widthStele;
  523. //
  524. // ofDrawRectangle(xToDraw, 0 , widthStele, sceneHeight);
  525. //
  526. // }
  527. //draw schwarzzonen
  528. ofDrawRectangle(xBegin, 0, widthStele*0.25, sceneHeight);
  529. xBegin += 0.25*widthStele;
  530. for(int i = 0; i < 5; i++){
  531. xBegin += widthStele;
  532. ofDrawRectangle(xBegin, 0, widthStele*0.5, sceneHeight);
  533. xBegin += 0.5*widthStele;
  534. }
  535. xBegin += widthStele;
  536. ofDrawRectangle(xBegin, 0, widthStele*0.25, sceneHeight);
  537. }
  538. //--------------------------------------------------------------
  539. void ofApp::drawLogicalScene(float sceneWidth, float sceneHeight){
  540. ofNoFill();
  541. ofDrawCircle(sceneHeight/2, sceneHeight/2, sceneHeight/2);
  542. ofFill();
  543. }
  544. //--------------------------------------------------------------
  545. string ofApp::getCurrentModeAsString(){
  546. string currentModeAsString = "";
  547. if(currentMode == PARTICLE_MODE_POLYMESH){
  548. currentModeAsString = "POLYMESH";
  549. }
  550. else if(currentMode == PARTICLE_MODE_DEFAULT){
  551. currentModeAsString = "DEFAULT";
  552. }
  553. else if(currentMode == PARTICLE_MODE_RFID){
  554. currentModeAsString = "RFID";
  555. }
  556. return currentModeAsString;
  557. }
  558. //--------------------------------------------------------------
  559. int ofApp::getTypeForCheckin(float x){
  560. int numberBetween1and4;
  561. if(x < 0.25){
  562. return 1;
  563. }else if(x >= 0.25 && x < 0.5){
  564. return 2;
  565. }else if(x >= 0.5 && x < 0.75){
  566. return 3;
  567. }else{
  568. return 4;
  569. }
  570. }
  571. //--------------------------------------------------------------
  572. int ofApp::getSteleForCheckin(float x){
  573. int numberBetween1and3;
  574. if(x < 0.334){
  575. return 1;
  576. }else if(x >= 0.334 && x < 0.667){
  577. return 2;
  578. }
  579. else{
  580. return 3;
  581. }
  582. }
  583. //--------------------------------------------------------------
  584. int ofApp::getBeginOfVisitorsInObjectPhysics(){
  585. for(int i = 0; i < objectPhysics.size(); i++){
  586. if(objectPhysics.at(i)->getIsVisitorObject() == true){
  587. return i;
  588. }
  589. }
  590. }
  591. //--------------------------------------------------------------
  592. void ofApp::refreshCoordinatesOfVisitorAttraktors(int beginOfVisitorsInObjectPhysicsVector, float sceneHeight){
  593. for(int i = 0; i < visitors.size(); i++){
  594. float x = visitors.at(i)->getPosition().x * sceneHeight;
  595. float y = visitors.at(i)->getPosition().y * sceneHeight;
  596. objectPhysics.at(beginOfVisitorsInObjectPhysicsVector + i)->setPosition(x,y);
  597. }
  598. }
  599. //--------------------------------------------------------------
  600. void ofApp::keyPressed(int key){
  601. }
  602. //--------------------------------------------------------------
  603. void ofApp::keyReleased(int key){
  604. if (key == '1') {
  605. checkedInVisitors.emplace_back(new CheckedInVisitor());
  606. checkedInVisitors.back()->setup(1, 1, ofGetWidth(), ofGetHeight());
  607. if (currentMode != PARTICLE_MODE_DEFAULT){
  608. std::cout << "change of mode to DEFAULT" << std::endl;
  609. currentMode = PARTICLE_MODE_DEFAULT;
  610. currentModeHasChanged = true;
  611. }
  612. }
  613. // Here the "RFID"-Effect will be faked!
  614. // For example, pressing '1' will trigger the animation for one of the playertypes.
  615. if ( key == '2') {
  616. int randomStele = ofRandom(3,6);
  617. checkedInVisitors.emplace_back(new CheckedInVisitor());
  618. checkedInVisitors.back()->setup(2, randomStele, ofGetWidth(), ofGetHeight());
  619. if(currentMode != PARTICLE_MODE_POLYMESH){
  620. std::cout << "change of mode to POLYMESH" << std::endl;
  621. currentMode = PARTICLE_MODE_POLYMESH;
  622. currentModeHasChanged = true;
  623. timerAfterCheckin = 0;
  624. }
  625. }
  626. if (key == '3') {
  627. int randomStele = ofRandom(3,6);
  628. checkedInVisitors.emplace_back(new CheckedInVisitor());
  629. checkedInVisitors.back()->setup(1, randomStele, ofGetWidth(), ofGetHeight());
  630. if(currentMode != PARTICLE_MODE_RFID){
  631. std::cout << "change of mode to RFID" << std::endl;
  632. currentMode = PARTICLE_MODE_RFID;
  633. currentModeHasChanged = true;
  634. timerAfterCheckin = 0;
  635. //implement starting a timer here, to trigger DEFAULT_MODE after a specific time
  636. }
  637. }
  638. if (key == '4') {
  639. if(listeningForStelenInput == true){
  640. int randomStele = ofRandom(3,6);
  641. checkedInVisitors.emplace_back(new CheckedInVisitor());
  642. checkedInVisitors.back()->setup(2, randomStele, ofGetWidth(), ofGetHeight());
  643. }
  644. }
  645. if (key == '5') {
  646. if(listeningForStelenInput == true){
  647. int randomStele = ofRandom(3,6);
  648. checkedInVisitors.emplace_back(new CheckedInVisitor());
  649. checkedInVisitors.back()->setup(3, randomStele, ofGetWidth(), ofGetHeight());
  650. }
  651. }
  652. if (key == '6') {
  653. if(listeningForStelenInput == true){
  654. int randomStele = ofRandom(3,6);
  655. checkedInVisitors.emplace_back(new CheckedInVisitor());
  656. checkedInVisitors.back()->setup(4, randomStele, ofGetWidth(), ofGetHeight());
  657. }
  658. }
  659. if ( key == '7') {
  660. if( activeTypeOfView == LOGIC){
  661. activeTypeOfView = MAPPED;
  662. }else if(activeTypeOfView == MAPPED){
  663. activeTypeOfView = LOGIC;
  664. }
  665. }
  666. if ( key == 'q') {
  667. }
  668. if (key == 's') { //SAVE MAYBE warpControllerStelen
  669. warpControllerCircle.getWarp(0)->setEditing(false);
  670. warpControllerStele1.getWarp(0)->setEditing(false);
  671. warpControllerStele2.getWarp(0)->setEditing(false);
  672. warpControllerStele3.getWarp(0)->setEditing(false);
  673. }
  674. if (key == 'x') { //Mapping
  675. // editingWarp = !editingWarp;
  676. warpControllerCircle.getWarp(0)->setEditing(true);
  677. }
  678. if (key == 'c') { //Mapping
  679. // editingWarp = !editingWarp;
  680. warpControllerStele1.getWarp(0)->setEditing(true);
  681. }
  682. if (key == 'v') { //Mapping
  683. // editingWarp = !editingWarp;
  684. warpControllerStele2.getWarp(0)->setEditing(true);
  685. }
  686. if (key == 'b') { //Mapping
  687. // editingWarp = !editingWarp;
  688. warpControllerStele3.getWarp(0)->setEditing(true);
  689. }
  690. if (key == 'l') {
  691. // secondWindow.toggleHidden();
  692. }
  693. if ( key == 'w') {
  694. ofToggleFullscreen();
  695. }
  696. if ( key == 'r') {
  697. //So we can use the keys 1-6 for different functionalities.
  698. //If listeningForStelenInput == true there cannot be changes in the mode,
  699. //but it is possible to generate checkedInVisitors
  700. if( listeningForStelenInput == true){
  701. listeningForStelenInput = false;
  702. }else if(listeningForStelenInput == false){
  703. listeningForStelenInput = true;
  704. }
  705. }
  706. }
  707. //--------------------------------------------------------------
  708. void ofApp::mouseMoved(int x, int y){
  709. // if(visitors.size()){
  710. // visitors.at(0)->setup(x, y);
  711. // visitors.at(1)->setup(x + 200, y + 200);
  712. // }
  713. }
  714. //--------------------------------------------------------------
  715. void ofApp::mouseDragged(int x, int y, int button){
  716. }
  717. //--------------------------------------------------------------
  718. void ofApp::mousePressed(int x, int y, int button){
  719. }
  720. //--------------------------------------------------------------
  721. void ofApp::mouseReleased(int x, int y, int button){
  722. }
  723. //--------------------------------------------------------------
  724. void ofApp::mouseEntered(int x, int y){
  725. }
  726. //--------------------------------------------------------------
  727. void ofApp::mouseExited(int x, int y){
  728. }
  729. //--------------------------------------------------------------
  730. void ofApp::windowResized(int w, int h){
  731. }
  732. //--------------------------------------------------------------
  733. void ofApp::gotMessage(ofMessage msg){
  734. }
  735. //--------------------------------------------------------------
  736. void ofApp::dragEvent(ofDragInfo dragInfo){
  737. }
  738. //--------------------------------------------------------------
  739. void ofApp::setupWarpStuff() {
  740. ofDisableArbTex();
  741. sceneSizeWarp.set(3840, 1200);
  742. fbo_warp.allocate(sceneSizeWarp.x, sceneSizeWarp.y, GL_RGB);
  743. fbo_warp.begin();
  744. ofClear(0);
  745. fbo_warp.end();
  746. // * WARP CONTROLLING * * WARP CONTROLLING * * WARP CONTROLLING * * WARP CONTROLLING * * WARP CONTROLLING *
  747. //load warp settings from file if present
  748. //this->warpController.loadSettings("settings.json");
  749. //if there is no file, generate warp
  750. if (this->warpControllerCircle.getWarps().empty())
  751. {
  752. std::shared_ptr<ofxWarpBase> warpCircle;
  753. warpCircle = this->warpControllerCircle.buildWarp<ofxWarpPerspective>();
  754. warpCircle->setSize(sceneSizeWarp.x, sceneSizeWarp.y);
  755. // warp->setEdges(0.0f, 0.0f, 1.0f, 1.0f);
  756. warpCircle->setControlPoint(0, glm::vec2(0.0f, 0.0f));
  757. warpCircle->setControlPoint(1, glm::vec2(0.333f, 0.0f));
  758. warpCircle->setControlPoint(2, glm::vec2(0.333f, 1.0f));
  759. warpCircle->setControlPoint(3, glm::vec2(0.0f, 1.0f));
  760. }
  761. // SECOND WARP
  762. if (this->warpControllerStele1.getWarps().empty())
  763. {
  764. std::shared_ptr<ofxWarpBase> warpStele1;
  765. warpStele1 = this->warpControllerStele1.buildWarp<ofxWarpPerspective>();
  766. warpStele1->setSize(sceneSizeWarp.x, sceneSizeWarp.y);
  767. // warp_stelen->setEdges(0.0f, 0.0f, 1.0f, 1.0f);
  768. warpStele1->setControlPoint(0, glm::vec2(0.57193f, 0.0f));
  769. warpStele1->setControlPoint(1, glm::vec2(0.64637f, 0.0f));
  770. warpStele1->setControlPoint(2, glm::vec2(0.64637f, 1.0f));
  771. warpStele1->setControlPoint(3, glm::vec2(0.57193f, 1.0f));
  772. }
  773. // THIRD WARP
  774. if (this->warpControllerStele2.getWarps().empty())
  775. {
  776. std::shared_ptr<ofxWarpBase> warpStele2;
  777. warpStele2 = this->warpControllerStele2.buildWarp<ofxWarpPerspective>();
  778. warpStele2->setSize(sceneSizeWarp.x, sceneSizeWarp.y);
  779. // warp_stelen->setEdges(0.0f, 0.0f, 1.0f, 1.0f);
  780. warpStele2->setControlPoint(0, glm::vec2(0.68359f, 0.0f));
  781. warpStele2->setControlPoint(1, glm::vec2(0.75803f, 0.0f));
  782. warpStele2->setControlPoint(2, glm::vec2(0.75803f, 1.0f));
  783. warpStele2->setControlPoint(3, glm::vec2(0.68359f, 1.0f));
  784. }
  785. // FORTH WARP
  786. if (this->warpControllerStele3.getWarps().empty())
  787. {
  788. std::shared_ptr<ofxWarpBase> warpStele3;
  789. warpStele3 = this->warpControllerStele3.buildWarp<ofxWarpPerspective>();
  790. warpStele3->setSize(sceneSizeWarp.x, sceneSizeWarp.y);
  791. // warp_stelen->setEdges(0.0f, 0.0f, 1.0f, 1.0f);
  792. warpStele3->setControlPoint(0, glm::vec2(0.79525f, 0.0f));
  793. warpStele3->setControlPoint(1, glm::vec2(0.86969f, 0.0f));
  794. warpStele3->setControlPoint(2, glm::vec2(0.86969f, 1.0f));
  795. warpStele3->setControlPoint(3, glm::vec2(0.79525f, 1.0f));
  796. }
  797. }
  798. //--------------------------------------------------------------