diff options
| author | Tim Redfern <tim@eclectronics.org> | 2012-03-28 00:42:08 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2012-03-28 00:42:08 +0100 |
| commit | a47b39541a7f60dfdda921c9598abe947e1e6ad9 (patch) | |
| tree | 34f85aa65d56793d2c42a83df5b025be7a142669 /gaunt01/src/testApp.cpp | |
| parent | 3badbcdf8d8a0005543521849694fa481dfce628 (diff) | |
rayhit still iffy. starting morpher
Diffstat (limited to 'gaunt01/src/testApp.cpp')
| -rw-r--r-- | gaunt01/src/testApp.cpp | 94 |
1 files changed, 71 insertions, 23 deletions
diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp index fdff756..00658b4 100644 --- a/gaunt01/src/testApp.cpp +++ b/gaunt01/src/testApp.cpp @@ -18,6 +18,23 @@ void testApp::setup(){ bLearnBakground = true; threshold = 80; + + ofVec3f centre=ofVec3f(ofGetWidth()/2,0,0); + ofVec3f normal=ofVec3f(0,0,-1); + ray=ofRay(); + plane=ofPlane(centre,normal); + plane.color=ofColor(255,255,255); + + projector=ofProjector(1.535f, ofVec2f(0.0f, 0.5f),ofGetWidth(),ofGetHeight()); + projector.setPosition(ofGetWidth()/2,ofGetHeight()/2,ofGetHeight()); + + cam=ofCamera(); + cam.setPosition(ofGetWidth()/2,ofGetHeight()/2,ofGetHeight()); + cam.lookAt(ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0)); + cam.setFov(54.13); + + cam_angle=0; + } //-------------------------------------------------------------- @@ -54,7 +71,7 @@ void testApp::update(){ // find contours which are between the size of 20 pixels and 1/3 the w*h pixels. // also, find holes is set to true so we will get interior contours as well.... - contourFinder.findContours(grayDiff, 20, (340*240)/3, 10, true); // find holes + contourFinder.findContours(grayDiff, 20, (340*240)/3, 10, false); // don't find holes } } @@ -62,6 +79,7 @@ void testApp::update(){ //-------------------------------------------------------------- void testApp::draw(){ + /* // draw the incoming, the grayscale, the bg and the thresholded difference ofSetHexColor(0xffffff); colorImg.draw(20,20); @@ -70,45 +88,68 @@ void testApp::draw(){ grayDiff.draw(360,280); // then draw the contours: - + */ ofFill(); ofSetHexColor(0x333333); - ofRect(360,540,320,240); - ofSetHexColor(0xffffff); + //ofRect(360,540,320,240); + ofSetHexColor(0xa0a0a0); // we could draw the whole contour finder //contourFinder.draw(360,540); - // or, instead we can draw each blob individually, - // this is how to get access to them: - for (int i = 0; i < contourFinder.nBlobs; i++){ - contourFinder.blobs[i].draw(360,540); - } - // finally, a report: - - ofSetHexColor(0xffffff); - char reportStr[1024]; - sprintf(reportStr, "bg subtraction and blob detection\npress ' ' to capture bg\nthreshold %i (press: +/-)\nnum blobs found %i, fps: %f", threshold, contourFinder.nBlobs, ofGetFrameRate()); - ofDrawBitmapString(reportStr, 20, 600); + colorImg.draw(0,0,ofGetWidth(),ofGetHeight()); - float gap=ofGetHeight()-ofGetWidth(); + cam.begin(); + ofPushMatrix(); - ofTranslate(0,ofGetHeight(),0); ofRotate(cam_angle,1,0,0); - ofTranslate(0,-ofGetHeight(),0); - for (float i=0;i<ofGetWidth();i+=ofGetWidth()/10) { + for (float i=0;i<=ofGetWidth();i+=ofGetWidth()/10) { glBegin(GL_LINES); - glVertex3f(i,gap,0); - glVertex3f(i,ofGetHeight(),0); + glVertex3f(i,0,0); + glVertex3f(i,ofGetWidth(),0); glEnd(); glBegin(GL_LINES); - glVertex3f(0,i+gap,0); - glVertex3f(ofGetWidth(),i+gap,0); + glVertex3f(0,i,0); + glVertex3f(ofGetWidth(),i,0); glEnd(); } + ofPopMatrix(); + cam.end(); + + ofSphere(pos.x,pos.y,pos.z,5); + + for (int i = 0; i < contourFinder.nBlobs; i++){ + contourFinder.blobs[i].draw(0,0); + + ofPoint p=contourFinder.blobs[i].centroid; + ofVec3f pp; + + cam.begin(); + ofPushMatrix(); + + ofRotate(cam_angle,1,0,0); + ray=projector.castPixel(p.x,(ofGetHeight()/2)-p.y); //(ofGetHeight()-y)); + bool hit = plane.intersect(ray,pp); + ofBox(pp,50); + ofPopMatrix(); + cam.end(); + + } + + + + // finally, a report: + + ofSetHexColor(0xffffff); + char reportStr[1024]; + sprintf(reportStr, "threshold %i\nnum blobs found %i, fps: %f", threshold, contourFinder.nBlobs, ofGetFrameRate()); + ofDrawBitmapString(reportStr, 10, 215); + + + } //-------------------------------------------------------------- @@ -133,6 +174,7 @@ void testApp::keyPressed(int key){ cam_angle-=1; break; } + plane.setNormal(ofVec3f(0,sin(cam_angle*0.01745329),-cos(cam_angle*0.01745329))); } //-------------------------------------------------------------- @@ -157,6 +199,12 @@ void testApp::mousePressed(int x, int y, int button){ //-------------------------------------------------------------- void testApp::mouseReleased(int x, int y, int button){ + ray=projector.castPixel(x,((3*(ofGetHeight()/2))-y)); //(ofGetHeight()-y)); + bool hit = plane.intersect(ray,pos); + //pos=ofVec3f(pos.x*2,pos.y*2,pos.z*2); + if (hit) printf("ray:%i,%i hit plane:%f,%f,%f\n",x,y,pos.x,pos.y,pos.z); + else printf("ray:%i,%i missed plane\n",x,y); + } |
