From ec078a99e2924c1709242f981651409f7ae9e940 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Fri, 23 Mar 2012 01:41:25 +0000 Subject: working with arduino --- bin/data/settings.xml | 7 +++-- map4.layout | 14 ++++----- src/main.cpp | 4 +-- src/mapUtils.cpp | 15 ++++++++++ src/mapUtils.h | 1 + src/testApp.cpp | 83 +++++++++++++++++++++++++++++++++++++++++---------- src/testApp.h | 49 +++++++++++++++++------------- 7 files changed, 126 insertions(+), 47 deletions(-) diff --git a/bin/data/settings.xml b/bin/data/settings.xml index 893a793..86e3759 100644 --- a/bin/data/settings.xml +++ b/bin/data/settings.xml @@ -1,11 +1,14 @@ - + - + + + + diff --git a/map4.layout b/map4.layout index f85b1ee..de269f0 100644 --- a/map4.layout +++ b/map4.layout @@ -22,20 +22,20 @@ - - + + - - + + - + - - + + diff --git a/src/main.cpp b/src/main.cpp index 209de67..5320f44 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,7 +17,7 @@ int main( ){ ofAppGlutWindow window; - ofSetupOpenGL(&window, 2048,768, OF_FULLSCREEN); // <-------- setup the GL context + ofSetupOpenGL(&window, 3840,720, OF_FULLSCREEN); // <-------- setup the GL context //ofSetupOpenGL(&window, 1024,300, OF_WINDOW); glutIgnoreKeyRepeat(1); glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF); //these don't work!!! @@ -25,7 +25,7 @@ int main( ){ // this kicks off the running of my app // can be OF_WINDOW or OF_FULLSCREEN // pass in width and height too: - window.setFrameRate(200.0f); + window.setFrameRate(50.0f); ofRunApp( new testApp()); } diff --git a/src/mapUtils.cpp b/src/mapUtils.cpp index 3dd3d7c..d250c98 100644 --- a/src/mapUtils.cpp +++ b/src/mapUtils.cpp @@ -139,3 +139,18 @@ void drawBoard(float x,float y,float z) { glEnd(); glPopMatrix(); } +void drawCylinder(float r,float h,float x,float y,float z) { + glPushMatrix(); + glTranslated(x,y,z); + glBegin(GL_QUADS); + float step=TWO_PI/50.0; + float txstep=1.0/50.0; + for (float i=0,j=0;i<=TWO_PI;i+=step,j+=txstep) { + glTexCoord2f(j,0); glVertex3f(cos(i)*r, 0, sin(i)*r); + glTexCoord2f(j,1); glVertex3f(cos(i)*r, -h, sin(i)*r); + glTexCoord2f(j+txstep,1); glVertex3f(cos(i+step)*r, -h, sin(i+step)*r); + glTexCoord2f(j+txstep,0); glVertex3f(cos(i+step)*r, 0, sin(i+step)*r); + } + glEnd(); + glPopMatrix(); +} \ No newline at end of file diff --git a/src/mapUtils.h b/src/mapUtils.h index 4c56b2d..c362e66 100644 --- a/src/mapUtils.h +++ b/src/mapUtils.h @@ -16,4 +16,5 @@ void unbindTex(ofTexture &tex); ofPoint distort(ofPoint pt,float d); void drawBox(float size); void drawBoard(float x,float y,float z); +void drawCylinder(float r,float h,float x,float y,float z); 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': - 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