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 | |
| parent | 79c3cd01ef47524e80bd2d242807ad60c5de1e0d (diff) | |
working with arduino
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cpp | 4 | ||||
| -rw-r--r-- | src/mapUtils.cpp | 15 | ||||
| -rw-r--r-- | src/mapUtils.h | 1 | ||||
| -rw-r--r-- | src/testApp.cpp | 83 | ||||
| -rw-r--r-- | src/testApp.h | 49 |
5 files changed, 114 insertions, 38 deletions
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<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); diff --git a/src/testApp.h b/src/testApp.h index 17ba87d..293b6fd 100644 --- a/src/testApp.h +++ b/src/testApp.h @@ -53,40 +53,47 @@ class testApp : public ofBaseApp{ void windowResized(int w, int h); void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); + + void doTransition(); + float transTime; + bool transition; - string model_name; - float model_x; - float model_y; - float model_z; + string model_name; + float model_x; + float model_y; + float model_z; ofx3DModelLoader model; - + ofVideoPlayer calibrator_label; ofVideoPlayer texture; string* clips; int numClips; int whichClip; + int switchClip; viewpoint* views; - int activeView; //receives keypresses + int activeView; //receives keypresses int numViews; - int mode; + int mode; + + ofxXmlSettings XML; + + bool light; - ofxXmlSettings XML; + float mixAmount; - bool light; + ofVideoGrabber vidGrabber; + unsigned char * videoInverted; + ofTexture videoTexture; + int camWidth; + int camHeight; + bool grabberAvailable; - ofVideoGrabber vidGrabber; - unsigned char * videoInverted; - ofTexture videoTexture; - int camWidth; - int camHeight; - bool grabberAvailable; - - void setupArduino(const int & version); - void updateArduino(); - ofArduino ard; - bool bSetupArduino; // flag variable for setting up arduino once - int bSwitchArduino; + void setupArduino(const int & version); + void updateArduino(); + ofArduino ard; + bool bSetupArduino; // flag variable for setting up arduino once + int bSwitchArduino; }; |
