diff options
Diffstat (limited to 'gaunt01/src/testApp.cpp')
| -rw-r--r-- | gaunt01/src/testApp.cpp | 204 |
1 files changed, 117 insertions, 87 deletions
diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp index 9e2a574..4047f69 100644 --- a/gaunt01/src/testApp.cpp +++ b/gaunt01/src/testApp.cpp @@ -81,6 +81,8 @@ void testApp::setup(){ cam.cacheMatrices(); //stop error messages testpts=new ofVec3f[4]; + + bounds=new ofPlane[4]; trapDoor=trapdoor(screen2plane(ofVec2f(ofGetWidth(),0)),screen2plane(ofVec2f(ofGetWidth(),ofGetHeight())),ofVec2f(30,30)); updatePlane(); @@ -127,7 +129,35 @@ bool testApp::rectsCross(ofRectangle rect1,ofRectangle rect2) { void testApp::updatePlane(){ + //setup screen for new incline angle plane.setNormal(ofVec3f(0,sin(cam_angle*DEG_TO_RAD),-cos(cam_angle*DEG_TO_RAD))); + + ofVec2f l=ofVec2f(ofGetWidth()/20,ofGetHeight()/2); + ofRay r=projector.castPixel(l.x,l.y); + ofVec3f p; + plane.intersect(r,p); + ofVec3f pn=(p-projector.getGlobalPosition()).getPerpendicular(ofVec3f(0,1,0)); + bounds[0]=ofPlane(p,pn,pn,ofVec2f(1000,1000)); + + l=ofVec2f(ofGetWidth()/2,ofGetHeight()/20); + r=projector.castPixel(l.x,l.y); + plane.intersect(r,p); + pn=(p-projector.getGlobalPosition()).getPerpendicular(ofVec3f(1,0,0)); + bounds[1]=ofPlane(p,pn,-pn,ofVec2f(1000,1000)); + + l=ofVec2f(19*ofGetWidth()/20,ofGetHeight()/2); + r=projector.castPixel(l.x,l.y); + plane.intersect(r,p); + pn=(p-projector.getGlobalPosition()).getPerpendicular(ofVec3f(0,1,0)); + bounds[2]=ofPlane(p,pn,-pn,ofVec2f(1000,1000)); + + l=ofVec2f(ofGetWidth()/2,19*ofGetHeight()/20); + r=projector.castPixel(l.x,l.y); + plane.intersect(r,p); + pn=(p-projector.getGlobalPosition()).getPerpendicular(ofVec3f(1,0,0)); + bounds[1]=ofPlane(p,pn,-pn,ofVec2f(1000,1000)); + + //create ground mesh with hole for trapdoor ground=ofMesh(); ground.addVertex(ofVec3f(0,0,0)); @@ -249,8 +279,10 @@ void testApp::update(){ //check if a key exists in a map - map::count //do we purge them or just stop drawing them? is it a problem inheriting tesselator re memory? //if we keep them we can have a 'loserboard' + set<int> ids; for(int i=0;i<blobsManager.blobs.size();i++){ ofxCvBlob blob = blobsManager.blobs.at(i); + ids.insert(blobsManager.blobs.at(i).id); ofRectangle r=blob.boundingRect; ofVec2f blobBase=ofVec2f(r.x+(r.width/2),r.y+r.height-(r.width/2)); ofVec3f pp,rp; @@ -261,105 +293,75 @@ void testApp::update(){ players[blobsManager.blobs.at(i).id].setWorldPosition(ofVec3f(rp.x,rp.y,0)); players[blobsManager.blobs.at(i).id].update(blob); //create model } + map<int,player>::iterator it; + for (it=players.begin();it!=players.end();it++) if(ids.find(it->first)==ids.end()) it->second.active=false; } if (trapDoor.checkUpdate(players)) updatePlane(); - Bird.update(players); + Bird.update(players,cam_angle); + } //-------------------------------------------------------------- void testApp::draw(){ - ofBackground(0,0,0); + + ofBackground(0,0,0); cam.begin(); + + glDisable(GL_DEPTH_TEST); - switch(mode) { - case PLAY: - glDisable(GL_DEPTH_TEST); - - ofSetHexColor(0xffffff); - ofPushMatrix(); - ofRotate(cam_angle,1,0,0); - trapDoor.draw(); - ofPopMatrix(); - - ofSetHexColor(0xffffff); - bindTexture(bgImg); - ground.draw(); - unbindTexture(bgImg); - - ofPushMatrix(); - ofRotate(cam_angle,1,0,0); - Bird.drawShadow(); - ofPopMatrix(); - - glDisable(GL_DEPTH_TEST); - ofSetHexColor(0xffffff); - ofPushMatrix(); - ofRotate(cam_angle,1,0,0); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - trapDoor.drawSplash(cam_angle); - //trapDoor.splashFrames[0].draw(ofGetWidth()/2,ofGetHeight()/2); - glDisable(GL_BLEND); - ofPopMatrix(); - - glDisable(GL_DEPTH_TEST); - ofSetHexColor(0xffffff); - colorImg.getTextureReference().bind(); - for(int i=0;i<blobsManager.blobs.size();i++){ - players[blobsManager.blobs.at(i).id].draw(); - } - colorImg.getTextureReference().unbind(); - //ofxCvBlob blob=contourFinder.blobs[i]; - //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); - for (int i=0;i<player.getNumVertices();i++) { - 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(); - - } - else { - */ + ofSetHexColor(0xffffff); + ofPushMatrix(); + ofRotate(cam_angle,1,0,0); + trapDoor.draw(); + ofPopMatrix(); + + ofSetHexColor(0xffffff); + bindTexture(bgImg); + ground.draw(); + unbindTexture(bgImg); + + ofPushMatrix(); + ofRotate(cam_angle,1,0,0); + Bird.drawShadow(); + ofPopMatrix(); + + glDisable(GL_DEPTH_TEST); + ofSetHexColor(0xffffff); + ofPushMatrix(); + ofRotate(cam_angle,1,0,0); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + trapDoor.drawSplash(cam_angle); + //trapDoor.splashFrames[0].draw(ofGetWidth()/2,ofGetHeight()/2); + glDisable(GL_BLEND); + ofPopMatrix(); + + glDisable(GL_DEPTH_TEST); + ofSetHexColor(0xffffff); + colorImg.getTextureReference().bind(); + for(int i=0;i<blobsManager.blobs.size();i++){ + players[blobsManager.blobs.at(i).id].draw(); + } + colorImg.getTextureReference().unbind(); - //draw players is in front of trap door or shadow - - - - + glEnable(GL_LIGHTING); - glEnable(GL_LIGHTING); + ofPushMatrix(); + ofRotate(cam_angle,1,0,0); + Bird.draw(); + ofPopMatrix(); + + glDisable(GL_LIGHTING); - ofPushMatrix(); - ofRotate(cam_angle,1,0,0); - Bird.draw(); - ofPopMatrix(); + switch(mode) { + case PLAY: - glDisable(GL_LIGHTING); 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()); - bgImg.draw(0,0,ofGetWidth(),ofGetHeight()); + ofSetHexColor(0xffffff); ofPushMatrix(); ofRotate(cam_angle,1,0,0); for (float i=0;i<=ofGetWidth();i+=ofGetWidth()/10) { @@ -374,15 +376,43 @@ void testApp::draw(){ } ofVec2f pp=screen2plane(pos); - ofSphere(pp.x,pp.y,0,5); + //ofSphere(pp.x,pp.y,0,5); ofPopMatrix(); ofPushMatrix(); ofRotate(cam_angle,1,0,0); - trapDoor.draw(); trapDoor.drawDebug(); ofPopMatrix(); - + + Bird.drawDebug(); + + ofSetHexColor(0x77ff77); + + + ofVec3f bp; + for (int i=0;i<4;i++) { + bounds[i].draw(); + if ( + bounds[i].intersect(Bird.pointer,bp)) { + char numStr[16]; + sprintf(numStr, "%4.1f", (bp-Bird.position.rotated(cam_angle,ofVec3f(1,0,0))).length()); + ofVec3f sc=cam.worldToScreen(bp); + ofDrawBitmapString(numStr, sc.x, sc.y); + } + } + + for(int i=0;i<Bird.playpos.size();i++) { + ofPushMatrix(); + ofRotate(cam_angle,1,0,0); + ofSetHexColor(0x77ffff); + ofLine(Bird.position,Bird.playpos[i]); + + ofPopMatrix(); + char numStr[10]; + sprintf(numStr, "%4.1f", Bird.playhead[i]); + ofVec3f sc=cam.worldToScreen(ofVec3f((Bird.position.x+Bird.playpos[i].x)/2,(Bird.position.y+Bird.playpos[i].y)/2,(Bird.position.z+Bird.playpos[i].z)/2).rotated(cam_angle,ofVec3f(1,0,0))); + ofDrawBitmapString(numStr, sc.x, sc.y); + } for(int i=0;i<blobsManager.blobs.size();i++){ @@ -402,8 +432,8 @@ void testApp::draw(){ // } - - + + break; |
