From 0363ee4f188c735a43c6624a2b10a191f74c3029 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Sun, 1 Apr 2012 23:07:39 +0100 Subject: nearly working trap door --- gaunt01/src/testApp.cpp | 299 +++++++++++++++++++++++++++--------------------- 1 file changed, 171 insertions(+), 128 deletions(-) (limited to 'gaunt01/src/testApp.cpp') diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp index 3b81cdd..87a51c4 100644 --- a/gaunt01/src/testApp.cpp +++ b/gaunt01/src/testApp.cpp @@ -11,15 +11,23 @@ void testApp::setup(){ loadSettings("settings.xml"); - #ifdef _USE_LIVE_VIDEO + vidPlayer.loadMovie("camoutput.mov"); //footage/ camera needs to be the same res as opencv planes and output + vidPlayer.setLoopState(OF_LOOP_NORMAL); vidGrabber.setVerbose(true); - vidGrabber.initGrabber(320,240); - #else - vidPlayer.loadMovie("camoutput.wmv"); //footage/ camera needs to be the same res as opencv planes and output - vidPlayer.play(); - #endif + if (vidGrabber.initGrabber(640,480)) { + hasCamera=true; + useCamera=true; + } + else + { + hasCamera=false; + useCamera=false; + vidPlayer.play(); + } + colorImg.allocate(640,480); + colorImg.setUseTexture(true); grayImage.allocate(640,480); grayBg.allocate(640,480); grayDiff.allocate(640,480); @@ -37,11 +45,53 @@ void testApp::setup(){ cam=ofCamera(); cam.setPosition(ofGetWidth()/2,ofGetHeight()/2,-ofGetWidth()); cam.lookAt(ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0),ofVec3f(0, -1, 0)); - cam.setFov(42.0); //39.85); //53.13); + cam.setFov(41.0); //39.85); //53.13); - trapDoor=trapdoor(ofRectangle(0,ofGetHeight()/4,ofGetHeight(),ofGetHeight()),ofVec2f(20,20)); + updatePlane(); + mode=PLAY; +} + +ofVec2f testApp::screen2plane(ofVec2f screenpos){ + ofVec3f p; + ray=projector.castPixel(screenpos.x,screenpos.y); + bool hit = plane.intersect(ray,p); + return ofVec2f(p.x,pow(pow(p.y,2)+pow(p.z,2),0.5f)); +} +ofVec3f testApp::plane2world(ofVec2f planepos){ + return ofVec3f(planepos.x,planepos.y,0); +} + +void testApp::updatePlane(){ + plane.setNormal(ofVec3f(0,sin(cam_angle*0.01745329),-cos(cam_angle*0.01745329))); + trapDoor=trapdoor(screen2plane(ofVec2f(ofGetWidth(),0)),screen2plane(ofVec2f(ofGetWidth(),ofGetHeight())),ofVec2f(20,20)); + //create ground mesh with hole for trapdoor + ground=ofMesh(); + ground.addVertex(plane2world(screen2plane(ofVec2f(0,0)))); + ground.addTexCoord(ofVec2f(0,0)); + ground.addVertex(plane2world(screen2plane(ofVec2f(ofGetWidth(),0)))); + ground.addTexCoord(ofVec2f(1,0)); + ground.addVertex(plane2world(screen2plane(ofVec2f(ofGetWidth(),ofGetHeight())))); + ground.addTexCoord(ofVec2f(1,1)); + ground.addVertex(plane2world(screen2plane(ofVec2f(0,ofGetHeight())))); + ground.addTexCoord(ofVec2f(0,1)); + + ground.addTriangle(0,2,1); + ground.addTriangle(0,3,2); + + /* + vector corners=trapDoor.getCorners(); + for (int i=0;i newPlayers; - float movethresh=10; - - for (int i = 0; i < contourFinder.nBlobs; i++){ - //do some bounds checking, size threshold and overlap removal - //in order to translate blobs into players - //attempt to track players - maintain ID no - //attempt to base blobs - //TODO attempt to estimate bounds shape - //project all of this into the 3D space - ofRectangle r=contourFinder.blobs[i].boundingRect; - - ofVec2f blobBase=ofVec2f(r.x+(r.width/2),r.y+r.height-(r.width/2)); - - contourFinder.blobs[i].draw(0,0); - ofPoint p=contourFinder.blobs[i].centroid; - - ofSetHexColor(0xffff00); - - char numStr[16]; - sprintf(numStr, "%i", i); - ofDrawBitmapString(numStr, r.x, r.y); - - ofVec3f pp; - ray=projector.castPixel(blobBase.x,blobBase.y); //(ofGetHeight()-y)); - bool hit = plane.intersect(ray,pp); - + switch(mode) { + case PLAY: + glDisable(GL_DEPTH_TEST); + //must be a better way than this + colorImg.draw(0,0,ofGetWidth(),ofGetHeight()); + ofFill(); + ofSetHexColor(0x000000); + ofRect(0,0,ofGetWidth(),ofGetHeight()); + ofSetHexColor(0xffffff); + ofPushMatrix(); + ofRotate(cam_angle,1,0,0); + bindTexture(colorImg); + ground.draw(); + unbindTexture(colorImg); + trapDoor.checkUpdate(players); + trapDoor.draw(); + ofPopMatrix(); + break; + case CALIBRATE: + ofFill(); + ofSetHexColor(0x333333); + ofSetHexColor(0xa0a0a0); + // we could draw the whole contour finder + //contourFinder.draw(360,540); + //keep running background average- how do you use a custom background + ofSetHexColor(0xffffff); + colorImg.draw(0,0,ofGetWidth(),ofGetHeight()); - for (int i=0;i newPlayers; + float movethresh=10; + for (int i = 0; i < contourFinder.nBlobs; i++){ + //do some bounds checking, size threshold and overlap removal + //in order to translate blobs into players + //attempt to track players - maintain ID no + //attempt to base blobs + //TODO attempt to estimate bounds shape + //project all of this into the 3D space + ofRectangle r=contourFinder.blobs[i].boundingRect; + ofVec2f blobBase=ofVec2f(r.x+(r.width/2),r.y+r.height-(r.width/2)); + contourFinder.blobs[i].draw(0,0); + ofPoint p=contourFinder.blobs[i].centroid; + ofSetHexColor(0xffff00); + char numStr[16]; + sprintf(numStr, "%i", i); + ofDrawBitmapString(numStr, r.x, r.y); + ofVec3f pp; + ray=projector.castPixel(blobBase.x,blobBase.y); //(ofGetHeight()-y)); + bool hit = plane.intersect(ray,pp); + for (int i=0;i