diff options
| author | Tim Redfern <tim@eclectronics.org> | 2012-03-23 01:41:25 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2012-03-23 01:41:25 +0000 |
| commit | ec078a99e2924c1709242f981651409f7ae9e940 (patch) | |
| tree | 53c9f71aa378ebaaf24aa77c9624e18803bbaeed /src/testApp.cpp | |
| parent | 79c3cd01ef47524e80bd2d242807ad60c5de1e0d (diff) | |
working with arduino
Diffstat (limited to 'src/testApp.cpp')
| -rw-r--r-- | src/testApp.cpp | 83 |
1 files changed, 68 insertions, 15 deletions
diff --git a/src/testApp.cpp b/src/testApp.cpp index 081c3e6..dff1f18 100644 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -1,6 +1,7 @@ #include "testApp.h" //-------------------------------------------------------------- testApp::~testApp(){ + ard.disconnect(); // closes the serial port connection saveSettings("settings.xml"); } //-------------------------------------------------------------- @@ -27,19 +28,25 @@ void testApp::setup(){ //model.setRotation(0, 90, 0, 1, 0); model.setPosition(model_x, model_y, model_z); + calibrator_label.loadMovie("calibrator_label.mov"); + calibrator_label.setLoopState(OF_LOOP_NORMAL); + calibrator_label.play(); //ofDisableArbTex(); mode=DISPLAY; + transTime=0; + transition=false; - - whichClip=0; + whichClip=1; //0 is black + switchClip=1; //0 is black texture.loadMovie(clips[whichClip]); texture.setLoopState(OF_LOOP_NORMAL); texture.play(); light=true; + mixAmount=1.0; camWidth = 320; // try to grab at this size. camHeight = 240; @@ -65,6 +72,10 @@ void testApp::setup(){ //-------------------------------------------------------------- void testApp::update(){ texture.idleMovie(); + calibrator_label.idleMovie(); + + //mixAmount=sin(ofGetElapsedTimef())+1.0; + doTransition(); if (mode==GRAB) { vidGrabber.grabFrame(); @@ -81,7 +92,6 @@ void testApp::update(){ videoTexture.loadData(videoInverted, camWidth,camHeight, GL_RGB); } } - updateArduino(); } @@ -109,16 +119,28 @@ void testApp::updateArduino(){ // do not send anything until the arduino has been set up if (bSetupArduino) { + + if (bSwitchArduino!=ard.getDigital(7)) { bSwitchArduino=ard.getDigital(7); printf("pin 7 %i\n",bSwitchArduino); + if (!bSwitchArduino) { + whichClip=max(1,switchClip); + transTime=ofGetElapsedTimef()+0.5; + } + else { + switchClip=whichClip; + whichClip=0; + transTime=ofGetElapsedTimef()+0.1; + } + + transition=true; } } } //-------------------------------------------------------------- void testApp::draw(){ - if (mode!=CALIBRATE&&bSetupArduino&!bSwitchArduino) return; for (int i=0;i<numViews;i++) { views[i].setLight(); } @@ -130,19 +152,32 @@ void testApp::draw(){ ofFill(); switch(mode) { case CALIBRATE: + glDisable(GL_LIGHTING); + //calibrator_label.getTextureReference().bind(); drawBoard(0,225,0); + bindTexture(calibrator_label); //texture); // + drawCylinder(26.5,200,0,225,0); ofPushMatrix(); ofRotate(90,0,1,0); - model.draw(); + //calibrator_model.draw(); + ///calibrator_label.draw(0,0); ofPopMatrix(); + unbindTexture(calibrator_label); //texture); // + //calibrator_label.getTextureReference().unbind(); break; case DISPLAY: - bindTexture(texture); + if (mixAmount<1.0f) { + glEnable(GL_BLEND); + glBlendFunc(GL_CONSTANT_ALPHA,GL_ZERO); + glBlendColor(1.0f,1.0f,1.0f, mixAmount); + } + bindTexture(texture); // ofPushMatrix(); ofRotate(90,0,1,0); model.draw(); ofPopMatrix(); - unbindTexture(texture); + unbindTexture(texture); // + glDisable(GL_BLEND); break; case GRAB: bindTex(videoTexture); @@ -191,6 +226,9 @@ void testApp::keyPressed(int key){ case '3': activeView=1; break; + case '4': + activeView=2; + break; case 'p': saveSettings("settings.xml"); break; @@ -200,24 +238,39 @@ void testApp::keyPressed(int key){ case ',': case '<': whichClip--; - if (whichClip<0) whichClip+=numClips; - texture.stop(); - texture.loadMovie(clips[whichClip]); - texture.play(); + if (whichClip<1) whichClip=numClips-1; + transTime=ofGetElapsedTimef()+1.0; + transition=true; break; case '.': case '>': - whichClip=(whichClip+1)%numClips; - texture.stop(); - texture.loadMovie(clips[whichClip]); - texture.play(); + whichClip=max(1,(whichClip+1)%numClips); + transTime=ofGetElapsedTimef()+1.0; + transition=true; break; case '/': light=!light; printf(light?"LIGHT ON\n":"LIGHT OFF\n"); break; + case '`': + ard.disconnect(); // closes the serial port connection + printf("arduino disconnected\n"); + break; } } +void testApp::doTransition(){ + if (transition) { + if (ofGetElapsedTimef()>transTime) { + texture.stop(); + texture.loadMovie(clips[whichClip]); + texture.play(); + transition=false; + } + + } + mixAmount=min(abs(ofGetElapsedTimef()-transTime),1.0f); + if (whichClip==0&&!transition) mixAmount=0; +} //-------------------------------------------------------------- void testApp::keyReleased(int key){ if (activeView<0) for (int i=0;i<numViews;i++) views[i].keyReleased(key); |
