diff options
| author | Tim Redfern <tim@eclectronics.org> | 2012-05-14 19:00:08 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2012-05-14 19:00:08 +0100 |
| commit | dbf9692b03ac2485f771993184222f7170e71cf2 (patch) | |
| tree | 9a17e44304856b5daa9d91172eb40f6e1783b1da /gaunt01 | |
| parent | e333ec0659a74899fbd75c5ed490089d0fd7d244 (diff) | |
working on background segmentation
Diffstat (limited to 'gaunt01')
| -rw-r--r-- | gaunt01/gaunt01.cbp | 56 | ||||
| -rw-r--r-- | gaunt01/src/bird.cpp | 15 | ||||
| -rw-r--r-- | gaunt01/src/main.cpp | 4 | ||||
| -rw-r--r-- | gaunt01/src/player.cpp | 2 | ||||
| -rw-r--r-- | gaunt01/src/testApp.cpp | 216 | ||||
| -rw-r--r-- | gaunt01/src/testApp.h | 29 | ||||
| -rw-r--r-- | gaunt01/src/trapdoor.cpp | 22 | ||||
| -rw-r--r-- | gaunt01/src/trapdoor.h | 5 |
8 files changed, 159 insertions, 190 deletions
diff --git a/gaunt01/gaunt01.cbp b/gaunt01/gaunt01.cbp index daba2ed..e8a613c 100644 --- a/gaunt01/gaunt01.cbp +++ b/gaunt01/gaunt01.cbp @@ -6,7 +6,7 @@ <Option makefile_is_custom="1" /> <Option pch_mode="2" /> <Option compiler="gcc" /> - <Option virtualFolders="addons/;src/;addons/ofxOpenCv/src/;build config/;" /> + <Option virtualFolders="addons/;src/;build config/;" /> <Build> <Target title="Debug"> <Option output="bin/$(PROJECT_NAME)_debug" prefix_auto="1" extension_auto="1" /> @@ -27,60 +27,6 @@ <Option projectLinkerOptionsRelation="2" /> </Target> </Build> - <Unit filename="../../../addons/ofxOpenCv/src/ofxCvBlob.h"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> - <Unit filename="../../../addons/ofxOpenCv/src/ofxCvColorImage.cpp"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> - <Unit filename="../../../addons/ofxOpenCv/src/ofxCvColorImage.h"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> - <Unit filename="../../../addons/ofxOpenCv/src/ofxCvConstants.h"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> - <Unit filename="../../../addons/ofxOpenCv/src/ofxCvContourFinder.cpp"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> - <Unit filename="../../../addons/ofxOpenCv/src/ofxCvContourFinder.h"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> - <Unit filename="../../../addons/ofxOpenCv/src/ofxCvFloatImage.cpp"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> - <Unit filename="../../../addons/ofxOpenCv/src/ofxCvFloatImage.h"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> - <Unit filename="../../../addons/ofxOpenCv/src/ofxCvGrayscaleImage.cpp"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> - <Unit filename="../../../addons/ofxOpenCv/src/ofxCvGrayscaleImage.h"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> - <Unit filename="../../../addons/ofxOpenCv/src/ofxCvHaarFinder.cpp"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> - <Unit filename="../../../addons/ofxOpenCv/src/ofxCvHaarFinder.h"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> - <Unit filename="../../../addons/ofxOpenCv/src/ofxCvImage.cpp"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> - <Unit filename="../../../addons/ofxOpenCv/src/ofxCvImage.h"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> - <Unit filename="../../../addons/ofxOpenCv/src/ofxCvMain.h"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> - <Unit filename="../../../addons/ofxOpenCv/src/ofxCvShortImage.cpp"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> - <Unit filename="../../../addons/ofxOpenCv/src/ofxCvShortImage.h"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> - <Unit filename="../../../addons/ofxOpenCv/src/ofxOpenCv.h"> - <Option virtualFolder="addons/ofxOpenCv/src" /> - </Unit> <Unit filename="Makefile"> <Option virtualFolder="build config/" /> </Unit> 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<int,player>& players, float angle,vector<ofPoint> 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<int,player>::iterator it; for (it=players.begin();it!=players.end();it++) { if (it->second.active) { @@ -83,7 +83,8 @@ void bird::update(map<int,player>& players, float angle,vector<ofPoint> 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<int,player>& players, float angle,vector<ofPoint> 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<ofVec2f> corners=trapdoors[num].getCorners(); + ofPolyline pol2; + for (int i=0;i<corners.size();i++) { + + ofVec3f cw=ofVec3f(corners[i].x,corners[i].y,0).rotated(cam_angle,ofVec3f(1,0,0)); + ofVec3f s=cam.worldToScreen(cam.worldToScreen(cw)); + //printf("corner %i: %f,%f to %f,%f,%f\n",i,corners[i].x,corners[i].y,s.x/s.z,s.y/s.z,s.z); + pol2.addVertex(s.x,s.y); + } + pol2.close(); + groundlines.push_back(pol2); + ground=ofMesh(); tess.tessellateToMesh(groundlines,OF_POLY_WINDING_ODD,ground,true); for (int i=0;i<ground.getNumVertices();i++) { ofVec3f v=ground.getVertex(i); - ground.addTexCoord(ofVec2f(v.x/ofGetWidth(),v.y/ofGetHeight())); + ground.addTexCoord(ofVec2f(v.x/windowWidth,v.y/windowHeight)); } - */ - + +} + +void testApp::makeGround(int doornumber){ //create ground mesh with hole for trapdoor - + //IS NOT WORKING!?? //it is building a hole somewhere.. whats.. the.. problem.. ground=ofMesh(); ground.addVertex(ofVec3f(0,0,0)); ground.addTexCoord(ofVec2f(0,0)); - ground.addVertex(ofVec3f(ofGetWidth(),0,0)); + ground.addVertex(ofVec3f(windowWidth,0,0)); ground.addTexCoord(ofVec2f(1,0)); - ground.addVertex(ofVec3f(ofGetWidth(),ofGetHeight(),0)); + ground.addVertex(ofVec3f(windowWidth,windowHeight,0)); ground.addTexCoord(ofVec2f(1,1)); - ground.addVertex(ofVec3f(0,ofGetHeight(),0)); + ground.addVertex(ofVec3f(0,windowHeight,0)); ground.addTexCoord(ofVec2f(0,1)); vector<ofVec2f> 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<trapdoor> 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<numtrapdoorSlots;i++) { //get middle position in the slot on the ground visible on screen - ofVec3f rp=ofVec3f(ofGetWidth()/2,closestY-((i+0.5)*trapdoorSlotSize),0); + ofVec3f rp=ofVec3f(windowWidth/2,closestY-((i+0.5)*trapdoorSlotSize),0); //randomise horizontal pos - rp.x=ofRandom(trapdoorSlotSize*5)-(trapdoorSlotSize*2.5)+(+ofGetWidth()/2); + rp.x=ofRandom(trapdoorSlotSize*5)-(trapdoorSlotSize*2.5)+(+windowWidth/2); - //gb.x=ofRandom((ofGetWidth()-gb.x)*2)+gb.x; + //gb.x=ofRandom((windowWidth-gb.x)*2)+gb.x; if (border.size()<3||!OutsidePolygon(border,ofPoint(rp.x,rp.y))) { trapdoors.push_back(trapdoor(ofVec2f(rp.x,rp.y),trapdoorSize)); } } random_shuffle ( trapdoors.begin(), trapdoors.end() ); - + trapdoorCounter=0; trapdoors[trapdoorCounter].active=true; - - makeGround(0); - - /* - groundlines.clear(); - ofPolyline pol; - pol.addVertex(0,0); - pol.addVertex(ofGetWidth(),0); - pol.addVertex(ofGetWidth(),ofGetHeight()); - pol.addVertex(0,ofGetHeight()); - pol.close(); - groundlines.push_back(pol); - vector<ofVec2f> corners=trapdoors[0].getCorners(); - ofPolyline pol2; - for (int i=0;i<corners.size();i++) { + //makeGround(0); - ofVec3f cw=ofVec3f(corners[i].x,corners[i].y,0).rotated(cam_angle,ofVec3f(1,0,0)); - ofVec3f s=cam.worldToScreen(cam.worldToScreen(cw)); - //printf("corner %i: %f,%f to %f,%f,%f\n",i,corners[i].x,corners[i].y,s.x/s.z,s.y/s.z,s.z); - pol2.addVertex(s.x,s.y); - } - pol2.close(); - groundlines.push_back(pol2); - + tessGround(0); - */ + /* //create ground mesh with hole for trapdoor - + //IS NOT WORKING!?? //it is building a hole somewhere.. whats.. the.. problem.. /* ground=ofMesh(); ground.addVertex(ofVec3f(0,0,0)); ground.addTexCoord(ofVec2f(0,0)); - ground.addVertex(ofVec3f(ofGetWidth(),0,0)); + ground.addVertex(ofVec3f(windowWidth,0,0)); ground.addTexCoord(ofVec2f(1,0)); - ground.addVertex(ofVec3f(ofGetWidth(),ofGetHeight(),0)); + ground.addVertex(ofVec3f(windowWidth,windowHeight,0)); ground.addTexCoord(ofVec2f(1,1)); - ground.addVertex(ofVec3f(0,ofGetHeight(),0)); + ground.addVertex(ofVec3f(0,windowHeight,0)); ground.addTexCoord(ofVec2f(0,1)); vector<ofVec2f> 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;i<trapdoorCounter;i++) { if (trapdoors[i].checkUpdate(players)) { - makeGround(i); + //makeGround(i); int whichsound=(int)ofRandom(2.9999999); doorsounds[whichsound].play(); doorsounds[3].play(); //falling down hole @@ -484,7 +503,7 @@ void testApp::update(){ } } } - + Bird.update(players,cam_angle,border); } @@ -499,38 +518,34 @@ void testApp::draw(){ ofSetHexColor(0xffffff); glDisable(GL_BLEND); - if (gameState<PLAYING) colorImg.draw(0,0,ofGetWidth(),ofGetHeight()); + if (gameState<PLAYING) colorImg.draw(0,0,windowWidth,windowHeight); else { - + //trapdoor logic if (ofGetElapsedTimef()-trapdoorTimer>trapdoorTime) { 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<trapdoorCounter;i++) { + for (int i=0;i<=trapdoorCounter;i++) { trapdoors[i].draw(); } ofPopMatrix(); - - - +//should be in front with holes being recreated for activated trapdoors + ofSetHexColor(0xffffff); + bindTexture(bgImg); + ground.draw(); + unbindTexture(bgImg); ofPushMatrix(); ofRotate(cam_angle,1,0,0); @@ -543,8 +558,9 @@ void testApp::draw(){ ofRotate(cam_angle,1,0,0); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - for (int i=0;i<trapdoorCounter;i++) { + for (int i=0;i<=trapdoorCounter;i++) { trapdoors[i].drawSplash(cam_angle); + } glDisable(GL_BLEND); @@ -606,19 +622,19 @@ void testApp::draw(){ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); switch(gameState) { case TITLES: - billboards[0].draw(ofGetWidth()/6 + billboards[0].draw(windowWidth/6 ,scaleFactor.y*((-billboards[0].height/2)+(billboards[0].height*pow(sin(segElapsed*PI),0.5))) ,billboards[0].width*scaleFactor.x ,billboards[0].height*scaleFactor.y); break; case CREDIT: - billboards[1].draw(ofGetWidth()/6 - ,ofGetHeight()+(scaleFactor.y*((billboards[1].height/2)-(billboards[1].height*pow(sin(segElapsed*PI),0.5)))) + billboards[1].draw(windowWidth/6 + ,windowHeight+(scaleFactor.y*((billboards[1].height/2)-(billboards[1].height*pow(sin(segElapsed*PI),0.5)))) ,billboards[1].width*scaleFactor.x ,billboards[1].height*scaleFactor.y); break; case EXPLAIN: - billboards[2].draw(ofGetWidth()/2 + billboards[2].draw(windowWidth/2 ,scaleFactor.y*((-billboards[2].height/2)+(billboards[2].height*pow(sin(segElapsed*PI),0.5))) ,billboards[2].width*scaleFactor.x ,billboards[2].height*scaleFactor.y); @@ -626,7 +642,7 @@ void testApp::draw(){ case PLAYING: break; case GOTCHA: - billboards[3].draw(ofGetWidth()/2 + billboards[3].draw(windowWidth/2 ,scaleFactor.y*((-billboards[2].height/2)+(billboards[3].height*pow(sin(segElapsed*PI),0.5))) ,billboards[3].width*scaleFactor.x ,billboards[3].height*scaleFactor.y); @@ -646,14 +662,14 @@ void testApp::draw(){ ofSetHexColor(0xffffff); ofPushMatrix(); ofRotate(cam_angle,1,0,0); - for (float i=0;i<=ofGetWidth();i+=ofGetWidth()/10) { + for (float i=0;i<=windowWidth;i+=windowWidth/10) { glBegin(GL_LINES); glVertex3f(i,0,0); - glVertex3f(i,ofGetWidth(),0); + glVertex3f(i,windowWidth,0); glEnd(); glBegin(GL_LINES); glVertex3f(0,i,0); - glVertex3f(ofGetWidth(),i,0); + glVertex3f(windowWidth,i,0); glEnd(); } @@ -741,11 +757,11 @@ void testApp::draw(){ ofSetHexColor(0xffffff); char reportStr[1024]; sprintf(reportStr, "threshold %i\nnum blobs found %i, fps: %f", threshold, contourFinder.nBlobs, ofGetFrameRate()); - ofDrawBitmapString(reportStr, 10, ofGetHeight()-40); + ofDrawBitmapString(reportStr, 10, windowHeight-40); char numStr[16]; for(int i=0;i<blobsManager.blobs.size();i++){ sprintf(numStr, "%i", blobsManager.blobs[i].id); - ofDrawBitmapString(numStr, 10+(i*30), ofGetHeight()-55); + ofDrawBitmapString(numStr, 10+(i*30), windowHeight-55); } } cam.end(); diff --git a/gaunt01/src/testApp.h b/gaunt01/src/testApp.h index a5ee556..01301de 100644 --- a/gaunt01/src/testApp.h +++ b/gaunt01/src/testApp.h @@ -46,6 +46,8 @@ class testApp : public ofBaseApp{ void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); + int windowWidth, windowHeight; + int mode; //utility functions @@ -91,21 +93,22 @@ class testApp : public ofBaseApp{ //vector<ofVec3f> players; trapdoor trapDoor; ofMesh ground; - + vector<ofPolyline> groundlines; ofTessellator tess; - - void makeGround(int doornumber); - + + void tessGround(int doornum); + void makeGround(int doornum); + vector<trapdoor> 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<int,player> players; bool drawStats; - + bool firstframe; //for background removal float bgnum; - + ofLight light; - + ofPlane* bounds; - + vector<ofPoint> 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<int,player>& 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;i<caught.size();i++) { + for (int i=0;i<caught.size();i++) { float splashTime = (ofGetElapsedTimef()-caughtTime[i]); if (splashTime>0.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<player*> caught; vector<float> caughtTime; - + }; |
