summaryrefslogtreecommitdiff
path: root/gaunt01/src/testApp.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-04-12 21:50:39 +0100
committerTim Redfern <tim@eclectronics.org>2012-04-12 21:50:39 +0100
commitd45a554faaf557b9e9a4b7a43b73b89f03800a96 (patch)
tree6825b969ccada08fa638d5f47ac15b5515e1f8ac /gaunt01/src/testApp.cpp
parent6ddd691156f1a3a24be9045056db39e78041b8d8 (diff)
bird shadow
Diffstat (limited to 'gaunt01/src/testApp.cpp')
-rw-r--r--gaunt01/src/testApp.cpp117
1 files changed, 100 insertions, 17 deletions
diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp
index 172190f..6660103 100644
--- a/gaunt01/src/testApp.cpp
+++ b/gaunt01/src/testApp.cpp
@@ -3,6 +3,16 @@
//--------------------------------------------------------------
//units ~ 10cm
//
+/*
+Can use a floating point image or array to accumulate the screen and generate averaged background?
+
+Is this too much work for every frame? Should it be put in a seperate thread?
+
+
+
+
+
+*/
void testApp::setup(){
bLearnBakground = true;
@@ -24,12 +34,23 @@ void testApp::setup(){
useCamera=false;
vidPlayer.play();
}
-
+
+/*
colorImg.allocate(640,480);
colorImg.setUseTexture(true);
grayImage.allocate(640,480);
grayBg.allocate(640,480);
- grayDiff.allocate(640,480);
+ grayDiff.allocate(640,480);
+ */
+ colorImg.allocate(640,480);
+ colorImg.setUseTexture(true);
+
+ grayImage.allocate(ofGetWidth(),ofGetHeight());
+ grayBg.allocate(ofGetWidth(),ofGetHeight());
+ grayDiff.allocate(ofGetWidth(),ofGetHeight());
+
+
+
blobsManager.normalizePercentage = 0.7;
blobsManager.giveLowestPossibleIDs = false;
@@ -60,6 +81,7 @@ void testApp::setup(){
mode=PLAY;
+ drawStats=false;
}
@@ -167,7 +189,9 @@ void testApp::update(){
colorImg.setFromPixels(vidPlayer.getPixels(), 640,480);
}
+
grayImage = colorImg;
+ grayImage.resize(ofGetWidth(),ofGetHeight());
if (bLearnBakground == true){
grayBg = grayImage; // the = sign copys the pixels from grayImage into grayBg (operator overloading)
bLearnBakground = false;
@@ -176,6 +200,8 @@ void testApp::update(){
// take the abs value of the difference between background and incoming and then threshold:
grayDiff.absDiff(grayBg, grayImage);
grayDiff.threshold(threshold);
+ //grayDiff.adaptiveThreshold( threshold); //int blockSize, int offset=0,bool invert=false, bool gauss=false);
+ grayDiff.erode_3x3();
// 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....
@@ -219,6 +245,13 @@ void testApp::draw(){
ground.draw();
unbindTexture(colorImg);
+ Bird.update(players);
+
+ ofPushMatrix();
+ ofRotate(cam_angle,1,0,0);
+ Bird.drawShadow();
+ ofPopMatrix();
+
/*
glEnable(GL_BLEND);
glBlendFunc(GL_CONSTANT_ALPHA,GL_ONE);
@@ -228,7 +261,7 @@ void testApp::draw(){
*/
for (int i = 0; i < contourFinder.nBlobs; i++){
ofxCvBlob blob=contourFinder.blobs[i];
- if (rectsCross(blob.boundingRect,trapDoor.getBoundingRect())){
+ //if (rectsCross(blob.boundingRect,trapDoor.getBoundingRect())){ //ALWAYS draw players?
//create outline mesh
playeroutline=ofPolyline(blob.pts);
tesselator.tessellateToMesh(playeroutline,OF_POLY_WINDING_NONZERO,player,true);
@@ -241,15 +274,20 @@ void testApp::draw(){
//get screen basepoint
ofRectangle r=blob.boundingRect;
ofVec2f blobBase=ofVec2f(r.x+(r.width/2),r.y+r.height-(r.width/2));
- if (trapDoor.getInnerRect().inside(blobBase.x,blobBase.y)) trapDoor.trigger();
-
- colorImg.getTextureReference().bind();
- player.draw(); //trapdoor.getoffset());
- colorImg.getTextureReference().unbind();
+ if (trapDoor.getInnerRect().inside(blobBase.x,blobBase.y)) {
+ trapDoor.trigger();
+
+ ofPushMatrix();
+ ofTranslate(0,0,trapDoor.getFalldist()*ofGetScreenHeight());
+ colorImg.getTextureReference().bind();
+ player.draw(); //trapdoor.getoffset());
+ colorImg.getTextureReference().unbind();
+ ofPopMatrix();
+ }
}
- }
+ //}
+
- Bird.update(players);
ofPushMatrix();
ofRotate(cam_angle,1,0,0);
@@ -332,14 +370,16 @@ void testApp::draw(){
}
- // 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, ofGetHeight()-40);
+
break;
}
+ if (drawStats||mode==CALIBRATE) {
+ ofSetHexColor(0xffffff);
+ char reportStr[1024];
+ sprintf(reportStr, "threshold %i\nnum blobs found %i, fps: %f", threshold, contourFinder.nBlobs, ofGetFrameRate());
+ ofDrawBitmapString(reportStr, 10, ofGetHeight()-40);
+ }
cam.end();
}
@@ -366,15 +406,58 @@ void testApp::keyPressed(int key){
cam_angle-=1;
updatePlane();
break;
+ case 'q':
+ drawStats=!drawStats;
+ break;
case 's':
saveSettings("settings.xml");
break;
- case '1':
+ case '9':
mode=PLAY;
break;
- case '2':
+ case '0':
mode=CALIBRATE;
break;
+ case '1':
+ if (Bird.currentseq!="hover") {
+ //mesh.sequences["trans_flaphover"].stopAt(0.3);
+ //mesh.sequences["trans_flaphover"].start();
+ Bird.model.sequences[Bird.currentseq].fadeout(0.5);
+ Bird.model.sequences["hover"].fadein(0.5);
+ Bird.currentseq="hover";
+ }
+ break;
+ case '2':
+ if (Bird.currentseq!="flap") {
+ //mesh.sequences["trans_hoverflap"].stopAt(0.3);
+ //mesh.sequences["trans_hoverflap"].start();
+ Bird.model.sequences[Bird.currentseq].fadeout(0.5);
+ Bird.model.sequences["flap"].fadein(0.5);
+ Bird.currentseq="flap";
+ }
+ break;
+ case '3':
+ if (Bird.currentseq!="swoop") {
+ //mesh.sequences["trans_hoverflap"].stopAt(0.3);
+ //mesh.sequences["trans_hoverflap"].start();
+ Bird.model.sequences[Bird.currentseq].fadeout(0.25);
+ Bird.model.sequences["swoop_trans"].fadein(0.25);
+ Bird.model.sequences["swoop_trans"].stopTime=ofGetElapsedTimef()+1.0;
+ Bird.model.sequences["swoop"].startAt(1.0);
+ Bird.currentseq="swoop";
+ }
+ break;
+ case '4':
+ if (Bird.currentseq!="attack") {
+ //mesh.sequences["trans_hoverflap"].stopAt(0.3);
+ //mesh.sequences["trans_hoverflap"].start();
+ Bird.model.sequences[Bird.currentseq].fadeout(0.2);
+ Bird.model.sequences["attack_trans"].fadein(0.2);
+ Bird.model.sequences["attack_trans"].stopTime=ofGetElapsedTimef()+0.6;
+ Bird.model.sequences["attack"].startAt(0.6);
+ Bird.currentseq="attack";
+ }
+ break;
}
}