summaryrefslogtreecommitdiff
path: root/gaunt01/src/testApp.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-04-05 14:00:51 +0100
committerTim Redfern <tim@eclectronics.org>2012-04-05 14:00:51 +0100
commitf65006daf4979d82d67fd8c8a234d3913088821d (patch)
tree104d30c316ca295cd4bad1110c7f341640112738 /gaunt01/src/testApp.cpp
parent0c2a97dcc0fb370938dc0d2d3a27053c2c9cb31e (diff)
starting to implement bird
Diffstat (limited to 'gaunt01/src/testApp.cpp')
-rw-r--r--gaunt01/src/testApp.cpp72
1 files changed, 40 insertions, 32 deletions
diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp
index aebbe0b..172190f 100644
--- a/gaunt01/src/testApp.cpp
+++ b/gaunt01/src/testApp.cpp
@@ -30,11 +30,11 @@ void testApp::setup(){
grayImage.allocate(640,480);
grayBg.allocate(640,480);
grayDiff.allocate(640,480);
-
+
blobsManager.normalizePercentage = 0.7;
- blobsManager.giveLowestPossibleIDs = true;
+ blobsManager.giveLowestPossibleIDs = false;
blobsManager.maxUndetectedTime = 500;
- blobsManager.minDetectedTime = 2000;
+ blobsManager.minDetectedTime = 500;
blobsManager.debugDrawCandidates = true;
ofVec3f centre=ofVec3f(ofGetWidth()/2,0,0);
@@ -54,12 +54,12 @@ void testApp::setup(){
cam.cacheMatrices(); //stop error messages
testpts=new ofVec3f[4];
-
+
trapDoor=trapdoor(screen2plane(ofVec2f(ofGetWidth(),0)),screen2plane(ofVec2f(ofGetWidth(),ofGetHeight())),ofVec2f(30,30));
updatePlane();
mode=PLAY;
-
+
}
@@ -80,7 +80,7 @@ bool testApp::rectsCross(ofRectangle rect1,ofRectangle rect2) {
else if (rect2.x<rect1.x) {
if (rect2.x+rect2.width<rect1.x) overlap = false;
}
- if (overlap) { //still possible
+ if (overlap) { //still possible
if (rect1.y<rect2.y) {
if (rect1.y+rect1.height<rect2.y) overlap = false;
}
@@ -109,22 +109,22 @@ void testApp::updatePlane(){
ofVec2f screenCorners[4];
for (int i=0;i<corners.size();i++) {
-
+
ofNode axis;
ofNode c;
c.setParent(axis);
c.setPosition(corners[i].x,corners[i].y,0);
-
+
axis.rotate(cam_angle,1,0,0);
ofVec3f p=c.getGlobalPosition();
-
+
testpts[i]=p;
ofVec3f s=cam.worldToScreen(p);
//printf("corner %i: %f,%f,%f\n",i,s.x,s.y,s.z);
screenCorners[i]=ofVec2f(s.x,s.y);
-
+
ground.addVertex(s);
ground.addTexCoord(ofVec2f(s.x/ofGetWidth(),s.y/ofGetHeight()));
}
@@ -142,7 +142,7 @@ void testApp::updatePlane(){
float h=max(screenCorners[2].y,screenCorners[3].y)-y;
trapDoor.setBoundingRect(x,y,w,h);
-
+
}
@@ -182,7 +182,7 @@ void testApp::update(){
//hard coded size threshold of 100 pix
contourFinder.findContours(grayDiff, 200, (640*480)/3, 20, false); // don't find holes
-
+
blobsManager.update(contourFinder.blobs);
}
@@ -214,11 +214,11 @@ void testApp::draw(){
glBlendColor(1.0f,1.0f,1.0f, 0.5f);
glDisable(GL_BLEND);
*/
-
+
bindTexture(colorImg);
ground.draw();
unbindTexture(colorImg);
-
+
/*
glEnable(GL_BLEND);
glBlendFunc(GL_CONSTANT_ALPHA,GL_ONE);
@@ -236,14 +236,27 @@ void testApp::draw(){
ofVec3f v=player.getVertex(i);
player.addTexCoord(ofVec2f(v.x,v.y));
}
-
+
+ //figure out if player has stood on trap door
+ //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();
+ player.draw(); //trapdoor.getoffset());
colorImg.getTextureReference().unbind();
}
}
-
-
+
+ Bird.update(players);
+
+ ofPushMatrix();
+ ofRotate(cam_angle,1,0,0);
+ Bird.draw();
+ ofPopMatrix();
+
+
break;
case CALIBRATE:
ofFill();
@@ -271,7 +284,7 @@ void testApp::draw(){
ofVec2f pp=screen2plane(pos);
ofSphere(pp.x,pp.y,0,5);
ofPopMatrix();
-
+
ofPushMatrix();
ofRotate(cam_angle,1,0,0);
trapDoor.draw();
@@ -280,17 +293,12 @@ void testApp::draw(){
vector<ofVec3f> 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;
+ for(int i=0;i<blobsManager.blobs.size();i++){
+ ofxCvBlob blob = blobsManager.blobs.at(i);
+ ofRectangle r=blob.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;
+ blob.draw(0,0);
+ ofPoint p=blob.centroid;
ofSetHexColor(0xffff00);
char numStr[16];
sprintf(numStr, "%i", i);
@@ -304,10 +312,10 @@ void testApp::draw(){
//this is flawed: tracking boxes in a skewed axis
//how to get UV coords on the plane
//maybe rotate the camera instead of the plane
-
+
//for the bird interaction, need to get player coords in the ground axis.
//for the door interaction, need to build player outline in the screen axis
-
+
//for the door, first determine if the boundings cross - create overlay
//if the base centre is in the hole- trigger falling behaviour
@@ -319,7 +327,7 @@ void testApp::draw(){
ofBox(0,-10,0,20);
//TODO get this into plane axis
ofPopMatrix();
-
+
//
}