From dbf9692b03ac2485f771993184222f7170e71cf2 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Mon, 14 May 2012 19:00:08 +0100 Subject: working on background segmentation --- gaunt01/src/bird.cpp | 15 ++-- gaunt01/src/main.cpp | 4 +- gaunt01/src/player.cpp | 2 +- gaunt01/src/testApp.cpp | 216 +++++++++++++++++++++++++---------------------- gaunt01/src/testApp.h | 29 ++++--- gaunt01/src/trapdoor.cpp | 22 ++--- gaunt01/src/trapdoor.h | 5 +- 7 files changed, 158 insertions(+), 135 deletions(-) (limited to 'gaunt01/src') diff --git a/gaunt01/src/bird.cpp b/gaunt01/src/bird.cpp index a6dfcf8..49567bc 100644 --- a/gaunt01/src/bird.cpp +++ b/gaunt01/src/bird.cpp @@ -30,11 +30,11 @@ bird::bird() turnRate=20; diveRate=0; - + fieldofview=60; lastTime=ofGetElapsedTimef(); - + centrePoint=ofVec2f(ofGetWidth()/2,600); //quick and dirty } @@ -52,18 +52,18 @@ void bird::update(map& players, float angle,vector border){ while (heading <-180) heading=heading+360; position-=direction.rotated(heading,ofVec3f(0,0,-1))*velocity*timeSeg; //.rotate(heading,ofVec3f(0,1,0)) - + //absolute ray pointer pointer=ofRay(position.rotated(angle,ofVec3f(1,0,0)),-direction.rotated(heading,ofVec3f(0,0,-1)).rotated(angle,ofVec3f(1,0,0))*1000.0f,false); ofRay relpointer=ofRay(position,-direction.rotated(heading,ofVec3f(0,0,-1))*1000.0f,false); - + playang.clear(); playdist.clear(); playpos.clear(); playhead.clear(); playdip.clear(); - + map::iterator it; for (it=players.begin();it!=players.end();it++) { if (it->second.active) { @@ -83,7 +83,8 @@ void bird::update(map& players, float angle,vector border){ centrehead=atan2(position.x-centrePoint.x,position.y-centrePoint.y)*RAD_TO_DEG; while (centrehead>180) centrehead=centrehead-360; while (centrehead <-180) centrehead=centrehead+360; - if (OutsidePolygon(border,futurepoint)) { + + if (0) { //OutsidePolygon(border,futurepoint)) { //if (ofVec leaving=true; turnRate=centrehead/5; @@ -101,7 +102,7 @@ void bird::update(map& players, float angle,vector border){ } if (nearest>-1) turnRate=-playhead[nearest]; } - + } void bird::draw(){ glEnable(GL_DEPTH_TEST); diff --git a/gaunt01/src/main.cpp b/gaunt01/src/main.cpp index 24b1857..1f3ac12 100644 --- a/gaunt01/src/main.cpp +++ b/gaunt01/src/main.cpp @@ -6,8 +6,8 @@ int main( ){ ofAppGlutWindow window; - ofSetupOpenGL(&window, 1024,768, OF_WINDOW ); // <-------- setup the GL context - + ofSetupOpenGL(&window, 1024,768, OF_FULLSCREEN ); // <-------- setup the GL context + printf("%ix%i on screen %ix%i\n",ofGetWidth(),ofGetHeight(),ofGetScreenWidth(),ofGetScreenHeight()); // this kicks off the running of my app // can be OF_WINDOW or OF_FULLSCREEN // pass in width and height too: diff --git a/gaunt01/src/player.cpp b/gaunt01/src/player.cpp index efcdd0a..c81881a 100644 --- a/gaunt01/src/player.cpp +++ b/gaunt01/src/player.cpp @@ -59,4 +59,4 @@ void player::caught(){ void player::setCatchTransform(ofVec3f _catchPos,ofVec3f _catchScale){ catchPos=_catchPos; catchScale=_catchScale; -} \ No newline at end of file +} diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp index fe8b28f..853a23f 100644 --- a/gaunt01/src/testApp.cpp +++ b/gaunt01/src/testApp.cpp @@ -12,6 +12,18 @@ Is this too much work for every frame? Should it be put in a seperate thread? void testApp::setup(){ + printf("setup: %ix%i on screen %ix%i\n",ofGetWidth(),ofGetHeight(),ofGetScreenWidth(),ofGetScreenHeight()); + + int windowMode = ofGetWindowMode(); + if(windowMode == OF_FULLSCREEN){ + this->windowWidth = ofGetScreenWidth(); + this->windowHeight = ofGetScreenHeight(); + } + else if(windowMode == OF_WINDOW){ + this->windowWidth = ofGetWidth(); + this->windowHeight = ofGetHeight(); + } + bLearnBakground = true; cam_angle=0; threshold = 80; @@ -49,19 +61,19 @@ void testApp::setup(){ blobsManager.minDetectedTime = 500; blobsManager.debugDrawCandidates = true; - ofVec3f centre=ofVec3f(ofGetWidth()/2,0,0); + ofVec3f centre=ofVec3f(windowWidth/2,0,0); ofVec3f normal=ofVec3f(0,0,-1); ray=ofRay(); plane=ofPlane(centre,normal); plane.color=ofColor(255,255,255); - projector=ofProjector(2.0f, ofVec2f(0.0f, 0.0f),ofGetWidth(),ofGetHeight()); //1.535f - projector.setPosition(ofGetWidth()/2,ofGetHeight()/2,-ofGetWidth()); - projector.lookAt(ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0),ofVec3f(0, -1, 0)); + projector=ofProjector(2.0f, ofVec2f(0.0f, 0.0f),windowWidth,windowHeight); //1.535f + projector.setPosition(windowWidth/2,windowHeight/2,-windowWidth); + projector.lookAt(ofVec3f(windowWidth/2,windowHeight/2,0),ofVec3f(0, -1, 0)); cam=ofCamera(); - cam.setPosition(ofGetWidth()/2,ofGetHeight()/2,-ofGetWidth()); - cam.lookAt(ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0),ofVec3f(0, -1, 0)); + cam.setPosition(windowWidth/2,windowHeight/2,-windowWidth); + cam.lookAt(ofVec3f(windowWidth/2,windowHeight/2,0),ofVec3f(0, -1, 0)); cam.setFov(41.1); //39.85); //53.13); cam.cacheMatrices(); //stop error messages @@ -69,14 +81,14 @@ void testApp::setup(){ bounds=new ofPlane[4]; - //trapDoor=trapdoor(screen2plane(ofVec2f(ofGetWidth(),0)),screen2plane(ofVec2f(ofGetWidth(),ofGetHeight())),35); + //trapDoor=trapdoor(screen2plane(ofVec2f(windowWidth,0)),screen2plane(ofVec2f(windowWidth,windowHeight)),35); trapdoorSize=35; trapdoorSlotSize=50; - - + + trapdoorTime=10.0; //time per trapdoor; - - + + mode=PLAY; @@ -85,7 +97,7 @@ void testApp::setup(){ bgnum=1000; firstframe=true; - light.setPosition(ofGetWidth(),0,ofGetHeight()); + light.setPosition(windowWidth,0,windowHeight); light.enable(); drawingborder=false; @@ -99,7 +111,7 @@ void testApp::setup(){ for (int i=0;i<4;i++) { billboards[i].setAnchorPercent(0.5,0.5); } - scaleFactor=ofVec2f(ofGetWidth()/1280.0f,ofGetHeight()/768.0f); + scaleFactor=ofVec2f(windowWidth/1280.0f,windowHeight/768.0f); gameState=TITLES; @@ -113,16 +125,19 @@ void testApp::setup(){ sounds=new ofSoundPlayer[1]; sounds[0].loadSound("arp5.mp3"); //game start - - + + doorsounds=new ofSoundPlayer[4]; doorsounds[0].loadSound("creeky door short1.wav"); doorsounds[1].loadSound("creeky door short2.wav"); doorsounds[2].loadSound("creeky door short3.wav"); doorsounds[3].loadSound("voice falling down hole.wav"); - + + cam.begin(); + cam.end(); + updatePlane(); - + } ofVec2f testApp::screen2plane(ofVec2f screenpos){ @@ -153,29 +168,54 @@ bool testApp::rectsCross(ofRectangle rect1,ofRectangle rect2) { return overlap; } -void testApp::makeGround(int doornumber){ +void testApp::tessGround(int num){ //updates ground and makes texture coords; - /* + + if (num==0) { + groundlines.clear(); + ofPolyline pol; + pol.addVertex(0,0); + pol.addVertex(windowWidth,0); + pol.addVertex(windowWidth,windowHeight); + pol.addVertex(0,windowHeight); + pol.close(); + groundlines.push_back(pol); + } + + vector corners=trapdoors[num].getCorners(); + ofPolyline pol2; + for (int i=0;i corners=trapdoors[doornumber].getCorners(); @@ -199,7 +239,7 @@ void testApp::makeGround(int doornumber){ screenCorners[i]=ofVec2f(s.x,s.y); ground.addVertex(s); - ground.addTexCoord(ofVec2f(s.x/ofGetWidth(),s.y/ofGetHeight())); + ground.addTexCoord(ofVec2f(s.x/windowWidth,s.y/windowHeight)); } //join a quad for each side // the 2 rear sides should always point towards the rear @@ -222,31 +262,31 @@ void testApp::updatePlane(){ plane.setNormal(ofVec3f(0,sin(cam_angle*DEG_TO_RAD),-cos(cam_angle*DEG_TO_RAD))); //bird intersect planes - ofVec2f l=ofVec2f(ofGetWidth()/20,ofGetHeight()/2); + ofVec2f l=ofVec2f(windowWidth/20,windowHeight/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); + l=ofVec2f(windowWidth/2,windowHeight/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); + l=ofVec2f(19*windowWidth/20,windowHeight/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); + l=ofVec2f(windowWidth/2,19*windowHeight/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)); - + // vector trapdoors; // float trapdoorSize; // float trapdoorSlotSize; @@ -260,84 +300,63 @@ void testApp::updatePlane(){ trapdoors.clear(); - l=ofVec2f(ofGetWidth()/2,19*ofGetHeight()/20); + l=ofVec2f(windowWidth/2,19*windowHeight/20); r=projector.castPixel(l.x,l.y); plane.intersect(r,p); float closestY=p.rotated(cam_angle,ofVec3f(-1,0,0)).y; numtrapdoorSlots=closestY/trapdoorSlotSize; //get middle position in the slot on the ground visible at front of screen - ofVec3f rp=ofVec3f(ofGetWidth()/2,closestY-(0.5*trapdoorSlotSize),0); + ofVec3f rp=ofVec3f(windowWidth/2,closestY-(0.5*trapdoorSlotSize),0); //translate to the screen ofVec3f sp=cam.worldToScreen(rp.rotated(cam_angle,ofVec3f(1,0,0))); - printf("front slot: %f,%f to %f,%f,%f\n",rp.x,rp.y,sp.x,sp.y,sp.z); + //printf("front slot: %f,%f to %f,%f,%f\n",rp.x,rp.y,sp.x,sp.y,sp.z); //get point at left of this line //project back on ground - ofVec2f gb=screen2plane(ofVec2f(ofGetWidth()/8,sp.y)); + ofVec2f gb=screen2plane(ofVec2f(windowWidth/8,sp.y)); r=projector.castPixel(sp.x,sp.y); plane.intersect(r,p); - float range=(((ofGetWidth()/2)-p.x)*2); + float range=(((windowWidth/2)-p.x)*2); for (int i=0;i corners=trapdoors[0].getCorners(); - ofPolyline pol2; - for (int i=0;i corners=trapdoors[0].getCorners(); @@ -361,7 +380,7 @@ void testApp::updatePlane(){ screenCorners[i]=ofVec2f(s.x,s.y); ground.addVertex(s); - ground.addTexCoord(ofVec2f(s.x/ofGetWidth(),s.y/ofGetHeight())); + ground.addTexCoord(ofVec2f(s.x/windowWidth,s.y/windowHeight)); } //join a quad for each side // the 2 rear sides should always point towards the rear @@ -423,7 +442,7 @@ void testApp::update(){ //test the scaling /* - grayImage.resize(ofGetWidth(),ofGetHeight()); + grayImage.resize(windowWidth,windowHeight); if (bLearnBakground == true){ grayBg = grayImage; // the = sign copys the pixels from grayImage into grayBg (operator overloading) bLearnBakground = false; @@ -437,7 +456,7 @@ void testApp::update(){ grayDiff.threshold(threshold); //grayDiff.adaptiveThreshold( threshold); //int blockSize, int offset=0,bool invert=false, bool gauss=false); //grayDiff.erode_3x3(); - grayDiff.resize(ofGetWidth(),ofGetHeight()); + grayDiff.resize(windowWidth,windowHeight); // 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.... @@ -474,7 +493,7 @@ void testApp::update(){ } for (int i=0;itrapdoorTime) { if (trapdoors.size()>trapdoorCounter+1) { trapdoorCounter++; trapdoorTimer=ofGetElapsedTimef(); + tessGround(trapdoorCounter); } - else updatePlane(); + //else updatePlane(); } - - - //should be in front with holes being recreated for activated trapdoors - ofSetHexColor(0xffffff); - bindTexture(bgImg); - ground.draw(); - unbindTexture(bgImg); - + ofSetHexColor(0xffffff); ofPushMatrix(); ofRotate(cam_angle,1,0,0); //trapDoor.draw(); - for (int i=0;i players; trapdoor trapDoor; ofMesh ground; - + vector groundlines; ofTessellator tess; - - void makeGround(int doornumber); - + + void tessGround(int doornum); + void makeGround(int doornum); + vector trapdoors; float trapdoorSize; float trapdoorSlotSize; int numtrapdoorSlots; - + int trapdoorCounter; float trapdoorTime; //time per trap door float trapdoorTimer; - + ofSoundPlayer* doorsounds; ofVec3f* testpts; @@ -114,22 +117,22 @@ class testApp : public ofBaseApp{ map players; bool drawStats; - + bool firstframe; //for background removal float bgnum; - + ofLight light; - + ofPlane* bounds; - + vector border; bool drawingborder; - + ofSoundPlayer* sounds; - + ofImage* billboards; ofVec2f scaleFactor; - + int gameState; float gameStart; float segTimes[5]; diff --git a/gaunt01/src/trapdoor.cpp b/gaunt01/src/trapdoor.cpp index 309cda6..f609c91 100644 --- a/gaunt01/src/trapdoor.cpp +++ b/gaunt01/src/trapdoor.cpp @@ -3,16 +3,17 @@ trapdoor::trapdoor(ofVec2f pos,float _doorSize) { surround=morphmesh("trapdoor-top.xml"); + beneath=morphmesh("trapdoor-bottom.xml"); lid=morphmesh("trapdoor-lid.xml"); if (!surround.isLoaded()||!lid.isLoaded()) printf("problem loading trap door mesh.\n"); texture.loadImage("TextureTrapdoor.jpg"); - + splashFrames=new ofImage[3]; splashFrames[0].loadImage("Drops_1.tga"); splashFrames[1].loadImage("Drops_2.tga"); splashFrames[2].loadImage("Drops_3.tga"); - + for (int i=0;i<3;i++) { splashFrames[i].setAnchorPercent(0.5,0.5); } @@ -30,7 +31,7 @@ trapdoor::trapdoor(ofVec2f pos,float _doorSize) } trapdoor::~trapdoor() { - for (int i=0;i<3;i++) splashFrames[i].clear(); + //for (int i=0;i<3;i++) splashFrames[i].clear(); //delete splashFrames; } @@ -61,7 +62,7 @@ void trapdoor::trigger() { /* ofVec2f trapdoor::bounds2UV(ofVec2f point){ //returns the 0-1 UV coords of a point on the ground plane relative to its bounds. - //this should not be in the trapdoor class???? + //this should not be in the trapdoor class???? float v=(point.y-boundTR.y)/(boundBR.y-boundTR.y); float mx=ofGetWidth()/2; float u=((point.x-mx)/(((boundTR.x-mx)*(1-v))+((boundBR.x-mx)*v)))+0.5; @@ -94,13 +95,13 @@ bool trapdoor::checkUpdate(map& players) { float sc=pow(0.2,ofGetElapsedTimef()-caughtTime[i]); caught[i]->setCatchTransform(ofVec3f(0,0,0),ofVec3f(sc,sc,sc)); } - - + + float segTime=(ofGetElapsedTimef()-triggeredTime); if (triggeredTime>0) { doorSpeed=(doorSpeed+((cos(doorAngle*0.0174532925)/ofGetFrameRate())*50))*0.95; doorAngle-=doorSpeed; - } + } return gotcha; } @@ -128,6 +129,7 @@ void trapdoor::draw() { ofPushMatrix(); ofRotate(90,-1,0,0); ofScale(size*.005,size*.005,size*.005); + beneath.draw(); surround.draw(); ofPushMatrix(); ofTranslate(90,0,-5); @@ -146,7 +148,7 @@ void trapdoor::draw() { glDisable(GL_DEPTH_TEST); } void trapdoor::drawSplash(float angle) { - for (int i=0;i0.3) { ofPushMatrix(); @@ -159,5 +161,5 @@ void trapdoor::drawSplash(float angle) { ofPopMatrix(); } } - -} \ No newline at end of file + +} diff --git a/gaunt01/src/trapdoor.h b/gaunt01/src/trapdoor.h index 7259d09..4731488 100644 --- a/gaunt01/src/trapdoor.h +++ b/gaunt01/src/trapdoor.h @@ -35,12 +35,13 @@ class trapdoor void trigger(); float getoffset(); float getFalldist(); - + ofImage* splashFrames; //temp public bool active; protected: private: morphmesh surround; + morphmesh beneath; morphmesh lid; ofVec2f position; @@ -57,7 +58,7 @@ class trapdoor float triggeredTime; vector caught; vector caughtTime; - + }; -- cgit v1.2.3