summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-03-23 01:41:25 +0000
committerTim Redfern <tim@eclectronics.org>2012-03-23 01:41:25 +0000
commitec078a99e2924c1709242f981651409f7ae9e940 (patch)
tree53c9f71aa378ebaaf24aa77c9624e18803bbaeed
parent79c3cd01ef47524e80bd2d242807ad60c5de1e0d (diff)
working with arduino
-rw-r--r--bin/data/settings.xml7
-rw-r--r--map4.layout14
-rw-r--r--src/main.cpp4
-rw-r--r--src/mapUtils.cpp15
-rw-r--r--src/mapUtils.h1
-rw-r--r--src/testApp.cpp83
-rw-r--r--src/testApp.h49
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,12 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<map4 model="bottle-strongbow-lid.3DS" x="0" y="117" z="0">
<view>
- <settings x="0.000000" y="0.000000" w="0.500000" h="1.000000" distort="0.000000" fov="17.25" roll="90.0" targX="0" targY="100.0" targZ="0.0" lat="6.219387" lng="-74.018013" dolly="600.0" />
+ <settings x="0.000000" y="0.000000" w="0.500000" h="1.000000" distort="0.000000" fov="17.250000" roll="90.000000" targX="0.000000" targY="100.000000" targZ="0.000000" lat="50.352390" lng="-74.018013" dolly="662.707520" />
</view>
<view>
- <settings x="0.500000" y="0.000000" w="0.500000" h="1.000000" distort="0.000000" fov="17.25" roll="90.0" targX="0" targY="100.0" targZ="0.0" lat="10.471071" lng="32.265820" dolly="600.0" />
+ <settings x="0.500000" y="0.000000" w="0.500000" h="1.000000" distort="0.000000" fov="17.250000" roll="90.000000" targX="0.000000" targY="100.000000" targZ="0.000000" lat="54.604073" lng="32.265820" dolly="647.777954" />
</view>
<clip>
+ <settings file="black.mov" />
+ </clip>
+ <clip>
<settings file="strongbow/Still_image.mov" />
</clip>
<clip>
diff --git a/map4.layout b/map4.layout
index f85b1ee..de269f0 100644
--- a/map4.layout
+++ b/map4.layout
@@ -22,20 +22,20 @@
<File name="src/keyVar.h" open="0" top="0" tabpos="8">
<Cursor position="0" topLine="0" />
</File>
- <File name="src/main.cpp" open="0" top="0" tabpos="5">
- <Cursor position="275" topLine="0" />
+ <File name="src/main.cpp" open="1" top="0" tabpos="3">
+ <Cursor position="833" topLine="0" />
</File>
- <File name="src/mapUtils.cpp" open="0" top="0" tabpos="7">
- <Cursor position="0" topLine="8" />
+ <File name="src/mapUtils.cpp" open="1" top="0" tabpos="4">
+ <Cursor position="5495" topLine="107" />
</File>
<File name="src/mapUtils.h" open="0" top="0" tabpos="6">
<Cursor position="165" topLine="0" />
</File>
<File name="src/testApp.cpp" open="1" top="1" tabpos="2">
- <Cursor position="3281" topLine="95" />
+ <Cursor position="2116" topLine="39" />
</File>
- <File name="src/testApp.h" open="0" top="0" tabpos="1">
- <Cursor position="1267" topLine="33" />
+ <File name="src/testApp.h" open="1" top="0" tabpos="5">
+ <Cursor position="1337" topLine="17" />
</File>
<File name="src/viewpoint.cpp" open="0" top="0" tabpos="4">
<Cursor position="566" topLine="0" />
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;
};