Advertisement
Guest User

ofApp.cpp

a guest
May 17th, 2014
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.51 KB | None | 0 0
  1. #include "ofApp.h"
  2.  
  3. //--------------------------------------------------------------
  4. void ofApp::setup(){
  5.    
  6.     ofSetVerticalSync(true);
  7.  
  8.     paths[0] = "THREADBARE_hair/Resources/THREADBARE_hair.mov";
  9.     paths[1] = "THREADBARE_shoes4/Resources/THREADBARE_shoes4.mov";
  10.     paths[2] = "THREADBARE_replacev52/Resources/THREADBARE_replacev52.mov";
  11.     paths[3] = "THREADBARE_shoes3/Resources/THREADBARE_shoes3.mov";
  12.     paths[4] = "THREADBARE_v9_c/Resources/THREADBARE_v9_c.mov";
  13.     paths[5] = "THREADBARE_shoes1/Resources/THREADBARE_shoes1.mov";
  14.     paths[6] = "THREADBARE_v6/Resources/THREADBARE_v6.mov";
  15.     paths[7] = "THREADBARE_v7/Resources/THREADBARE_v7.mov";
  16.     paths[8] = "THREADBARE_v6/Resources/THREADBARE_v6.mov";
  17.     paths[9] = "THREADBARE_v42/Resources/THREADBARE_v42.mov";
  18.     paths[10] = "THREABARE_v2/Resources/THREABARE_v2.mov";
  19.     paths[11] = "THREADBARE_curtain/Resources/THREADBARE_curtain.mov";
  20.  
  21.     decodeMode = OF_QTKIT_DECODE_PIXELS_AND_TEXTURE;
  22.    
  23.     for(int i = 0; i< NUM_CLIPS; i++){
  24.         videos[i].setPixelFormat(OF_PIXELS_RGBA);
  25.         videos[i].loadMovie(paths[i], decodeMode);
  26.         videos[i].setVolume(0.0f);
  27.         videos[i].play();
  28.     }
  29.    
  30. //    videoSound.loadSound("Threadbare_voiceover.mp3");
  31. //    videoSound.setVolume(0.8f);
  32. //    videoSound.play();
  33.    
  34.     fbo.allocate(ofGetWindowWidth(), ofGetWindowHeight());
  35.     fbo.begin();
  36.     ofClear(0,0,0,255);
  37.     fbo.end();
  38.  
  39.     serial.enumerateDevices();
  40.     serial.setup(0,9600);
  41.  
  42. }
  43.  
  44. //--------------------------------------------------------------
  45. void ofApp::update(){
  46.  
  47.     int bytesRequired = 5;
  48.     unsigned char bytesReturned[bytesRequired];
  49.     int bytesRemaining = bytesRequired;
  50.     int bytesPreventOverwrite = bytesRequired - bytesRemaining;
  51.     int Result = 0;
  52.  
  53.         if(serial.available() > 0){
  54.             serial.readBytes(&bytesReturned[bytesPreventOverwrite], bytesRemaining);
  55.             if(bytesReturned[4] == 'z'){
  56.                 if(bytesReturned[0] == '1'){
  57.                     firstSensor = bytesReturned[1];
  58.                     cout<<"firstSensor after1: "<<firstSensor<<endl;
  59.                
  60.                 }
  61.                 if(bytesReturned[2] == '2'){
  62.                     secondSensor = bytesReturned[3];
  63.                     cout<<"secondSensor after1: "<<secondSensor<<endl;
  64.  
  65.             }
  66.             }
  67.             serial.flush();
  68.             serial.writeByte('A');
  69.         }
  70.    
  71.     for(int i = 0; i<NUM_CLIPS; i++){
  72.         videos[i].update();
  73.     }
  74.    
  75. //    if(fmodf(ofGetElapsedTimef(), 30.0) >= 0 && fmodf(ofGetElapsedTimef(), 30.0) <= 1){
  76.  
  77.         shaderValue = triggerFunction(firstSensor, secondSensor);
  78.     cout<<"shaderValue after triggerFunction: "<<shaderValue<<endl;
  79. //    }
  80.  
  81. }
  82. //--------------------------------------------------------------
  83. void ofApp::draw(){
  84.  
  85.     float oldShaderValue = 0;
  86.     int cue = 0;
  87.  
  88.     cout<<"cue before: "<<cue<<endl;
  89.     cout<<"is this printing??"<<oldShaderValue<<endl;
  90.     cout<<"shaderValue:"<<shaderValue<<endl;
  91.    
  92.     if(oldShaderValue != shaderValue){
  93.         cout<<"oldShaderValue before being set: "<<oldShaderValue<<endl;
  94.         oldShaderValue = shaderValue;
  95.         cout<<"oldShaderValue after being set: "<<oldShaderValue<<endl;
  96.         if(oldShaderValue == 0){
  97.             cue = 0;
  98.             cout<<"HELLO??: "<<cue<<endl;
  99.             } else if(oldShaderValue == 0.08){
  100.             cue = 1;
  101.                        
  102.             cout<<"cue: "<<cue<<endl;
  103.             } else if (oldShaderValue == 0.16){
  104.             cue = 2;
  105.            
  106.             cout<<"cue: "<<cue<<endl;
  107.            
  108.             } else if (oldShaderValue == 0.24){
  109.             cue = 3;
  110.            
  111.             cout<<"cue: "<<cue<<endl;
  112.            
  113.             } else if (oldShaderValue == 0.32){
  114.             cue = 4;
  115.  
  116.             cout<<"cue: "<<cue<<endl;
  117.            
  118.             } else if (oldShaderValue == 0.4){
  119.             cue = 5;
  120.            
  121.             cout<<"cue: "<<cue<<endl;
  122.            
  123.             } else if(oldShaderValue == 0.48){
  124.             cue = 6;
  125.            
  126.             cout<<"cue: "<<cue<<endl;
  127.    
  128.             } else if (oldShaderValue == 0.56){
  129.             cue = 7;
  130.            
  131.             cout<<"cue: "<<cue<<endl;
  132.            
  133.             } else if (oldShaderValue == 0.64){
  134.             cue = 8;
  135.            
  136.             cout<<"cue: "<<cue<<endl;
  137.            
  138.             } else if (oldShaderValue == 0.72){
  139.             cue = 9;
  140.            
  141.             cout<<"cue: "<<cue<<endl;
  142.            
  143.             } else if (oldShaderValue == 0.8){
  144.             cue = 10;
  145.            
  146.             cout<<"cue: "<<cue<<endl;
  147.             } else {
  148.             cue = 11;
  149.            
  150.             cout<<"cue: "<<cue<<endl;
  151.             }
  152.             cout<<"Why is nothing happening???"<<endl;
  153.     }
  154.  
  155.     cout<<"cue after: "<<cue<<endl;
  156.  
  157.     fbo.begin();
  158.     ofClear(0, 0, 0, 0);
  159.     videos[cue].draw(0,0, ofGetWindowWidth(), ofGetWindowHeight());
  160.     fbo.end();
  161.    
  162.     fbo.draw(0,0, ofGetWindowWidth(), ofGetWindowHeight());
  163.  
  164. }
  165.  
  166. //--------------------------------------------------------------
  167. void ofApp::keyPressed(int key){
  168.     if(key == 'D'){
  169.        
  170.         ofToggleFullscreen();
  171.     }
  172. }
  173.  
  174. //--------------------------------------------------------------
  175. float ofApp::triggerFunction(int sensorValue, int sensorValue2){
  176. // WILL REPLACE THESE IF STATEMENTS WITH MODULO
  177.    
  178.     float alphaValue = 1.0;
  179.  
  180.     if(((sensorValue >= 1) && (sensorValue < 20)) || ((sensorValue2 >= 1) && (sensorValue2 < 20))){
  181.         alphaValue = 0.0;
  182.         return alphaValue;
  183.  
  184.     } else if (((sensorValue >= 20) && (sensorValue < 36)) || ((sensorValue2 >= 20) && (sensorValue2 < 36))){
  185.         alphaValue = 0.08;
  186.         return alphaValue;
  187.  
  188.     } else if (((sensorValue >= 36) && (sensorValue < 52)) || ((sensorValue2 >= 36) && (sensorValue2 < 52))){
  189.         alphaValue = 0.16;
  190.         return alphaValue;
  191.  
  192.     } else if (((sensorValue >= 52) && (sensorValue < 68)) || ((sensorValue2 >= 52) && (sensorValue2 < 68))){
  193.         alphaValue = 0.24;
  194.         return alphaValue;
  195.        
  196.     } else if (((sensorValue >= 68) && (sensorValue < 84)) || ((sensorValue2 >= 68) && (sensorValue2 < 84))){
  197.         alphaValue = 0.32;
  198.         return alphaValue;
  199.        
  200.     } else if (((sensorValue >= 84) && (sensorValue < 100)) || ((sensorValue2 >= 84) && (sensorValue2 < 100))){
  201.         alphaValue = 0.4;
  202.         return alphaValue;
  203.        
  204.     } else if (((sensorValue >= 100) && (sensorValue < 116)) || ((sensorValue2 >= 100) && (sensorValue2 < 116))){
  205.         alphaValue = 0.48;
  206.         return alphaValue;
  207.        
  208.     } else if (((sensorValue >= 116) && (sensorValue < 142)) || ((sensorValue2 >= 116) && (sensorValue2 < 142))){
  209.         alphaValue = 0.56;
  210.         return alphaValue;
  211.        
  212.     } else if (((sensorValue >= 142) && (sensorValue < 168)) || ((sensorValue2 >= 142) && (sensorValue2 < 168))){
  213.         alphaValue = 0.64;
  214.         return alphaValue;
  215.        
  216.     } else if (((sensorValue >= 168) && (sensorValue < 182)) || ((sensorValue2 >= 168) && (sensorValue2 < 182))){
  217.         alphaValue = 0.72;
  218.         return alphaValue;
  219.        
  220.     } else if (((sensorValue >= 182) && (sensorValue < 228)) || ((sensorValue2 >= 182) && (sensorValue2 < 228))){
  221.         alphaValue = 0.8;
  222.         return alphaValue;
  223.        
  224.     } else if (((sensorValue >= 228) && (sensorValue < 246)) || ((sensorValue2 >= 228) && (sensorValue2 < 246))){
  225.         alphaValue = 1.0;
  226.         return alphaValue;
  227.     } else{
  228.         return alphaValue;
  229.     }
  230.        
  231. }
  232. //--------------------------------------------------------------
  233. void ofApp::keyReleased(int key){
  234.    
  235. }
  236.  
  237. //--------------------------------------------------------------
  238. void ofApp::mouseMoved(int x, int y){
  239.    
  240. }
  241.  
  242. //--------------------------------------------------------------
  243. void ofApp::mouseDragged(int x, int y, int button){
  244.    
  245. }
  246.  
  247. //--------------------------------------------------------------
  248. void ofApp::mousePressed(int x, int y, int button){
  249.    
  250. }
  251.  
  252. //--------------------------------------------------------------
  253. void ofApp::mouseReleased(int x, int y, int button){
  254.    
  255. }
  256.  
  257. //--------------------------------------------------------------
  258. void ofApp::windowResized(int w, int h){
  259.    
  260. }
  261.  
  262. //--------------------------------------------------------------
  263. void ofApp::gotMessage(ofMessage msg){
  264.    
  265. }
  266.  
  267. //--------------------------------------------------------------
  268. void ofApp::dragEvent(ofDragInfo dragInfo){
  269.    
  270. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement