diff options
| author | Tim Redfern <tim@eclectronics.org> | 2012-04-20 03:36:39 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2012-04-20 03:36:39 +0100 |
| commit | de766399e2442fbc438123c1c8763e0ae90e6158 (patch) | |
| tree | 1456a1882ead58c9ac99a74c99bde3cd11de7813 /gaunt01 | |
| parent | eaaa8f65e00d6c094206b55c06425715d80aa014 (diff) | |
numerous problems
Diffstat (limited to 'gaunt01')
| -rw-r--r-- | gaunt01/gaunt01.cbp | 6 | ||||
| -rw-r--r-- | gaunt01/src/bird.cpp | 41 | ||||
| -rw-r--r-- | gaunt01/src/bird.h | 7 | ||||
| -rw-r--r-- | gaunt01/src/main.cpp | 2 | ||||
| -rw-r--r-- | gaunt01/src/testApp.cpp | 334 | ||||
| -rw-r--r-- | gaunt01/src/testApp.h | 17 | ||||
| -rw-r--r-- | gaunt01/src/trapdoor.cpp | 91 | ||||
| -rw-r--r-- | gaunt01/src/trapdoor.h | 19 |
8 files changed, 352 insertions, 165 deletions
diff --git a/gaunt01/gaunt01.cbp b/gaunt01/gaunt01.cbp index 88aa223..daba2ed 100644 --- a/gaunt01/gaunt01.cbp +++ b/gaunt01/gaunt01.cbp @@ -111,6 +111,12 @@ <Unit filename="src/normBindTexture.h"> <Option virtualFolder="src/" /> </Unit> + <Unit filename="src/outsidePolygon.cpp"> + <Option virtualFolder="src/" /> + </Unit> + <Unit filename="src/outsidePolygon.h"> + <Option virtualFolder="src/" /> + </Unit> <Unit filename="src/player.cpp"> <Option virtualFolder="src/" /> </Unit> diff --git a/gaunt01/src/bird.cpp b/gaunt01/src/bird.cpp index 35d9020..a6dfcf8 100644 --- a/gaunt01/src/bird.cpp +++ b/gaunt01/src/bird.cpp @@ -34,6 +34,8 @@ bird::bird() fieldofview=60; lastTime=ofGetElapsedTimef(); + + centrePoint=ofVec2f(ofGetWidth()/2,600); //quick and dirty } bird::~bird() @@ -41,7 +43,7 @@ bird::~bird() //dtor } -void bird::update(map<int,player>& players, float angle){ +void bird::update(map<int,player>& players, float angle,vector<ofPoint> border){ float time=ofGetElapsedTimef(); float timeSeg=time-lastTime; lastTime=time; @@ -75,16 +77,30 @@ void bird::update(map<int,player>& players, float angle){ playhead.push_back(headif); } } - //fly towards nearest visible player - int nearest=-1; - float distance=9999; - for(int i=0;i<playhead.size();i++) { - if ((abs(playhead[i])<(fieldofview/2))&&playdist[i]<distance) { - nearest=i; - distance=playdist[i]; + //check if flying out of play + ofVec3f futurepos=position-direction.rotated(heading,ofVec3f(0,0,-1))*velocity*2.0; + ofPoint futurepoint=ofPoint(futurepos.x,futurepos.y); + 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 (ofVec + leaving=true; + turnRate=centrehead/5; + } + else { + leaving=false; + //fly towards nearest visible player + int nearest=-1; + float distance=9999; + for(int i=0;i<playhead.size();i++) { + if ((abs(playhead[i])<(fieldofview/2))&&playdist[i]<distance) { + nearest=i; + distance=playdist[i]; + } } + if (nearest>-1) turnRate=-playhead[nearest]; } - if (nearest>-1) turnRate=playhead[nearest]; } void bird::draw(){ @@ -95,7 +111,7 @@ void bird::draw(){ ofRotate(90,-1,0,0); ofRotate(heading+90,0,1,0); ofSetHexColor(0xffffff); - ofScale(.15,.15,.15); + ofScale(.25,.25,.25); bindTexture(texture); model.drawAnimated(); unbindTexture(texture); @@ -114,8 +130,9 @@ void bird::drawShadow(){ model.drawAnimated(); ofPopMatrix(); } -void bird::drawDebug(){ - ofSetHexColor(0xff00ff); +void bird::drawDebug(){ + if (leaving) ofSetHexColor(0xff0000); + else ofSetHexColor(0xff00ff); ofLine(pointer.s,pointer.s+1000*pointer.t); } diff --git a/gaunt01/src/bird.h b/gaunt01/src/bird.h index 026da72..3ab0da9 100644 --- a/gaunt01/src/bird.h +++ b/gaunt01/src/bird.h @@ -42,6 +42,7 @@ #include "morphmesh.h" #include "normBindTexture.h" #include "player.h" +#include "outsidePolygon.h" #include "ofxRay.h" @@ -50,7 +51,7 @@ class bird public: bird(); virtual ~bird(); - void update(map<int,player>& players,float angle); + void update(map<int,player>& players,float angle,vector<ofPoint> border); void draw(); void drawShadow(); void drawDebug(); @@ -60,6 +61,7 @@ class bird ofRay pointer; ofVec3f position; + ofVec2f centrePoint; //2d coords of centre of screen vector<float> playang; vector<float> playhead; @@ -67,6 +69,9 @@ class bird vector<float> playdist; vector<ofVec3f> playpos; + bool leaving; + float centrehead; + float heading; protected: diff --git a/gaunt01/src/main.cpp b/gaunt01/src/main.cpp index 7f55863..24b1857 100644 --- a/gaunt01/src/main.cpp +++ b/gaunt01/src/main.cpp @@ -6,7 +6,7 @@ int main( ){ ofAppGlutWindow window; - ofSetupOpenGL(&window, 1024,768, OF_FULLSCREEN); // <-------- setup the GL context + ofSetupOpenGL(&window, 1024,768, OF_WINDOW ); // <-------- setup the GL context // this kicks off the running of my app // can be OF_WINDOW or OF_FULLSCREEN diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp index 8a8f65d..fe8b28f 100644 --- a/gaunt01/src/testApp.cpp +++ b/gaunt01/src/testApp.cpp @@ -33,16 +33,16 @@ void testApp::setup(){ } accumImg.allocate(640,480); - + bgImg.allocate(640,480); bgImg.setUseTexture(true); -
+
colorImg.allocate(640,480); - colorImg.setUseTexture(true);
+ colorImg.setUseTexture(true);
grayImage.allocate(640,480); grayBg.allocate(640,480); - + blobsManager.normalizePercentage = 0.7; blobsManager.giveLowestPossibleIDs = false; blobsManager.maxUndetectedTime = 500; @@ -66,11 +66,17 @@ 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(35,35)); - updatePlane(); + //trapDoor=trapdoor(screen2plane(ofVec2f(ofGetWidth(),0)),screen2plane(ofVec2f(ofGetWidth(),ofGetHeight())),35); + trapdoorSize=35; + trapdoorSlotSize=50; + + + trapdoorTime=10.0; //time per trapdoor; + + mode=PLAY; @@ -94,19 +100,29 @@ void testApp::setup(){ billboards[i].setAnchorPercent(0.5,0.5); } scaleFactor=ofVec2f(ofGetWidth()/1280.0f,ofGetHeight()/768.0f); - + gameState=TITLES; - + segTimes[TITLES]=4.0; segTimes[CREDIT]=2.5; segTimes[EXPLAIN]=5.0; segTimes[PLAYING]=60.0; - segTimes[GOTCHA]=2.0; - + segTimes[GOTCHA]=4.0; + gameStart=ofGetElapsedTimef(); - + 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"); + + updatePlane(); + } ofVec2f testApp::screen2plane(ofVec2f screenpos){ @@ -137,38 +153,183 @@ bool testApp::rectsCross(ofRectangle rect1,ofRectangle rect2) { return overlap; } +void testApp::makeGround(int doornumber){ + //updates ground and makes texture coords; + /* + 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())); + } + */ + + //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.addTexCoord(ofVec2f(1,0)); + ground.addVertex(ofVec3f(ofGetWidth(),ofGetHeight(),0)); + ground.addTexCoord(ofVec2f(1,1)); + ground.addVertex(ofVec3f(0,ofGetHeight(),0)); + ground.addTexCoord(ofVec2f(0,1)); + + vector<ofVec2f> corners=trapdoors[doornumber].getCorners(); + 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())); + } + //join a quad for each side + // the 2 rear sides should always point towards the rear + for (int i=0;i<3;i++) { + ground.addTriangle(i,i+4,i+5); + ground.addTriangle(i+5,i+1,i); + } + ground.addTriangle(3,7,0); + ground.addTriangle(7,4,0); + float x=min(screenCorners[0].x,screenCorners[3].x); + float y=min(screenCorners[0].y,screenCorners[1].y); + float w=max(screenCorners[1].x,screenCorners[2].x)-x; + float h=max(screenCorners[2].y,screenCorners[3].y)-y; + //trapDoor.setBoundingRect(x,y,w,h); +} + 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))); - + + //bird intersect planes 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)); + +// vector<trapdoor> trapdoors; +// float trapdoorSize; +// float trapdoorSlotSize; +// int numtrapdoorSlots; +//create all trapdoors at once, deactivated. +//shuffle them +//at each timeout, pick the next door to activate (check if within bounds) and rebuild ground with holes +//on update, check all active doors against all players +//when a falling in sequence is over, start again + + trapdoors.clear(); + + l=ofVec2f(ofGetWidth()/2,19*ofGetHeight()/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); + //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); + + //get point at left of this line + //project back on ground + ofVec2f gb=screen2plane(ofVec2f(ofGetWidth()/8,sp.y)); + r=projector.castPixel(sp.x,sp.y); + plane.intersect(r,p); + float range=(((ofGetWidth()/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); + //randomise horizontal pos + rp.x=ofRandom(trapdoorSlotSize*5)-(trapdoorSlotSize*2.5)+(+ofGetWidth()/2); + + //gb.x=ofRandom((ofGetWidth()-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++) { + + 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); + + + + */ //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)); @@ -179,7 +340,7 @@ void testApp::updatePlane(){ ground.addVertex(ofVec3f(0,ofGetHeight(),0)); ground.addTexCoord(ofVec2f(0,1)); - vector<ofVec2f> corners=trapDoor.getCorners(); + vector<ofVec2f> corners=trapdoors[0].getCorners(); ofVec2f screenCorners[4]; for (int i=0;i<corners.size();i++) { @@ -214,9 +375,8 @@ void testApp::updatePlane(){ float y=min(screenCorners[0].y,screenCorners[1].y); float w=max(screenCorners[1].x,screenCorners[2].x)-x; float h=max(screenCorners[2].y,screenCorners[3].y)-y; - trapDoor.setBoundingRect(x,y,w,h); - - + //trapDoor.setBoundingRect(x,y,w,h); +*/ } @@ -242,11 +402,11 @@ void testApp::update(){ colorImg.setFromPixels(vidPlayer.getPixels(), 640,480); //accumImg.setFromPixels(vidPlayer.getPixels(), 640,480); } - + colorImg.updateTexture(); grayImage = colorImg; - + if (firstframe) { accumImg=grayImage; firstframe=false; @@ -256,12 +416,12 @@ void testApp::update(){ accumImg.addWeighted( grayImage, 1.0/bgnum ); //accumImg/=(1.0+(0.25/bgnum)); } - + bgImg=accumImg; bgImg.updateTexture(); - + //test the scaling - + /* grayImage.resize(ofGetWidth(),ofGetHeight()); if (bLearnBakground == true){ @@ -312,40 +472,65 @@ void testApp::update(){ else it->second.active=true; } } - if (trapDoor.checkUpdate(players)) { - if (gameState=PLAYING) { - gameState=GOTCHA; - gameStart=ofGetElapsedTimef(); + for (int i=0;i<trapdoorCounter;i++) { + if (trapdoors[i].checkUpdate(players)) { + makeGround(i); + int whichsound=(int)ofRandom(2.9999999); + doorsounds[whichsound].play(); + doorsounds[3].play(); //falling down hole + if (gameState=PLAYING) { + gameState=GOTCHA; + gameStart=ofGetElapsedTimef(); + } } - //updatePlane(); for new trapdoor } - Bird.update(players,cam_angle); + Bird.update(players,cam_angle,border); + } //-------------------------------------------------------------- void testApp::draw(){ - + glDisable(GL_LIGHTING); ofBackground(0,0,0); cam.begin(); glDisable(GL_DEPTH_TEST); ofSetHexColor(0xffffff); glDisable(GL_BLEND); - + if (gameState<PLAYING) colorImg.draw(0,0,ofGetWidth(),ofGetHeight()); - + else { - ofSetHexColor(0xffffff); - ofPushMatrix(); - ofRotate(cam_angle,1,0,0); - trapDoor.draw(); - ofPopMatrix(); + //trapdoor logic + if (ofGetElapsedTimef()-trapdoorTimer>trapdoorTime) { + if (trapdoors.size()>trapdoorCounter+1) { + trapdoorCounter++; + trapdoorTimer=ofGetElapsedTimef(); + } + 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++) { + trapdoors[i].draw(); + } + ofPopMatrix(); + + + + ofPushMatrix(); ofRotate(cam_angle,1,0,0); @@ -356,19 +541,21 @@ void testApp::draw(){ ofSetHexColor(0xffffff); ofPushMatrix(); ofRotate(cam_angle,1,0,0); - glEnable(GL_BLEND); + glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - trapDoor.drawSplash(cam_angle); - //trapDoor.splashFrames[0].draw(ofGetWidth()/2,ofGetHeight()/2); + for (int i=0;i<trapdoorCounter;i++) { + trapdoors[i].drawSplash(cam_angle); + } + glDisable(GL_BLEND); ofPopMatrix(); glDisable(GL_DEPTH_TEST); -https://twitter.com/# ofSetHexColor(0xffffff); + ofSetHexColor(0xffffff); bindTexture(colorImg); //colorImg.getTextureReference().bind(); map<int,player>::iterator it; for(int i=0;i<blobsManager.blobs.size();i++){ - if(players[blobsManager.blobs.at(i).id].active) players[blobsManager.blobs.at(i).id].draw(); + if(players[blobsManager.blobs.at(i).id].active) players[blobsManager.blobs.at(i).id].draw(); } unbindTexture(colorImg); @@ -378,12 +565,12 @@ https://twitter.com/# ofSetHexColor(0xffffff); ofRotate(cam_angle,1,0,0); Bird.draw(); ofPopMatrix(); - + glDisable(GL_LIGHTING); } float gameTime=ofGetElapsedTimef()-gameStart; - + switch(gameState) { case TITLES: case CREDIT: @@ -400,6 +587,7 @@ https://twitter.com/# ofSetHexColor(0xffffff); sounds[0].play(); gameStart=ofGetElapsedTimef(); gameTime=0.0f; + trapdoorTimer=ofGetElapsedTimef(); } break; case GOTCHA: @@ -407,15 +595,16 @@ https://twitter.com/# ofSetHexColor(0xffffff); gameState=PLAYING; gameStart=ofGetElapsedTimef(); gameTime=0.0f; + updatePlane(); //for new trapdoors } break; } - + float segElapsed=pow(gameTime/segTimes[gameState],2); - - glEnable(GL_BLEND); + + glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - switch(gameState) { + switch(gameState) { case TITLES: billboards[0].draw(ofGetWidth()/6 ,scaleFactor.y*((-billboards[0].height/2)+(billboards[0].height*pow(sin(segElapsed*PI),0.5))) @@ -444,11 +633,11 @@ https://twitter.com/# ofSetHexColor(0xffffff); break; } glDisable(GL_BLEND); - + switch(mode) { case PLAY: - + break; @@ -474,14 +663,17 @@ https://twitter.com/# ofSetHexColor(0xffffff); ofPushMatrix(); ofRotate(cam_angle,1,0,0); - trapDoor.drawDebug(); + for (int i=0;i<trapdoors.size();i++) { + trapdoors[i].drawDebug(); + } + //trapDoor.drawDebug(); ofPopMatrix(); - + Bird.drawDebug(); - + ofSetHexColor(0x77ff77); - - + + ofVec3f bp; for (int i=0;i<4;i++) { bounds[i].draw(); @@ -493,13 +685,18 @@ https://twitter.com/# ofSetHexColor(0xffffff); ofDrawBitmapString(numStr, sc.x, sc.y); } } - + ofSetHexColor(0xffff77); + char numStr[16]; + sprintf(numStr, "%4.1f", Bird.centrehead); + ofVec3f sc=cam.worldToScreen(Bird.position); + 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]); @@ -508,7 +705,7 @@ https://twitter.com/# ofSetHexColor(0xffffff); } for(int i=0;i<blobsManager.blobs.size();i++){ - + ofxCvBlob blob = blobsManager.blobs.at(i); blob.draw(0,0); ofPoint p=blob.centroid; @@ -534,8 +731,8 @@ https://twitter.com/# ofSetHexColor(0xffffff); } ofPopMatrix(); } - - + + break; @@ -629,7 +826,7 @@ void testApp::keyPressed(int key){ Bird.currentseq="attack"; } break; - /* + /* case 'y': light.setPosition(light.getX(),light.getY()-100,light.getZ()); printf("light at %f,%f,%f\n",light.getX(),light.getY(),light.getZ()); @@ -692,16 +889,11 @@ void testApp::mousePressed(int x, int y, int button){ //-------------------------------------------------------------- void testApp::mouseReleased(int x, int y, int button){ pos=ofVec2f(x,y); + ofVec2f sp=screen2plane(pos); if (drawingborder) { - border.push_back(screen2plane(pos)); - } - else { - - //if (hit) printf("ray:%i,%i hit plane:%f,%f,%f\n",x,y,pos.x,pos.y,pos.z); - //else printf("ray:%i,%i missed plane\n",x,y); - trapDoor.startPos(screen2plane(pos)); - updatePlane(); + border.push_back(sp); } + printf("ray:%i,%i hit plane:%f,%f,%f\n",x,y,sp.x,sp.y); } //-------------------------------------------------------------- diff --git a/gaunt01/src/testApp.h b/gaunt01/src/testApp.h index dd52d76..a5ee556 100644 --- a/gaunt01/src/testApp.h +++ b/gaunt01/src/testApp.h @@ -3,6 +3,7 @@ #include <set> #include "ofMain.h" +#include "tesselator.h" #include "ofxOpenCv.h" #include "ofxRay.h" @@ -90,6 +91,22 @@ class testApp : public ofBaseApp{ //vector<ofVec3f> players; trapdoor trapDoor; ofMesh ground; + + vector<ofPolyline> groundlines; + ofTessellator tess; + + void makeGround(int doornumber); + + vector<trapdoor> trapdoors; + float trapdoorSize; + float trapdoorSlotSize; + int numtrapdoorSlots; + + int trapdoorCounter; + float trapdoorTime; //time per trap door + float trapdoorTimer; + + ofSoundPlayer* doorsounds; ofVec3f* testpts; diff --git a/gaunt01/src/trapdoor.cpp b/gaunt01/src/trapdoor.cpp index 6757a04..309cda6 100644 --- a/gaunt01/src/trapdoor.cpp +++ b/gaunt01/src/trapdoor.cpp @@ -1,18 +1,12 @@ #include "trapdoor.h" -trapdoor::trapdoor(ofVec2f _boundTR,ofVec2f _boundBR,ofVec2f _doorSize) +trapdoor::trapdoor(ofVec2f pos,float _doorSize) { - surround=morphmesh("trapdoor-surround.xml"); + surround=morphmesh("trapdoor-top.xml"); lid=morphmesh("trapdoor-lid.xml"); if (!surround.isLoaded()||!lid.isLoaded()) printf("problem loading trap door mesh.\n"); texture.loadImage("TextureTrapdoor.jpg"); - - sounds=new ofSoundPlayer[4]; - sounds[0].loadSound("creeky door short1.wav"); - sounds[1].loadSound("creeky door short2.wav"); - sounds[2].loadSound("creeky door short3.wav"); - sounds[3].loadSound("voice falling down hole.wav"); splashFrames=new ofImage[3]; splashFrames[0].loadImage("Drops_1.tga"); @@ -23,49 +17,30 @@ trapdoor::trapdoor(ofVec2f _boundTR,ofVec2f _boundBR,ofVec2f _doorSize) splashFrames[i].setAnchorPercent(0.5,0.5); } - boundTR=_boundTR; - boundBR=_boundBR; size=_doorSize; - start(); -} - -trapdoor::~trapdoor() { - } - -void trapdoor::start(){ - //place trapdoor within bounds - float u=ofRandom(-0.9,0.9); //(-1 to 1) - float v=ofRandom(0.05,0.95); - float mx=ofGetWidth()/2; - - float x=mx+((boundTR.x-mx)*u*(1-v))+((boundBR.x-mx)*u*v); - float y=boundTR.y+((boundBR.y-boundTR.y)*v); - - startPos(ofVec2f(x,y)); - -} - -void trapdoor::startPos(ofVec2f pos){ caught.clear(); caughtTime.clear(); - position=pos; - setBoundingRect(pos.x, pos.y,size.x,size.y); - startTime=ofGetElapsedTimef(); doorAngle=0; doorSpeed=0; - opening=false; + position=pos; + setBoundingRect(pos.x, pos.y,size,size); + active=false; triggeredTime=-1; - //for (int i=0;i<4;i++) sounds[i].stop(); +} + +trapdoor::~trapdoor() { + for (int i=0;i<3;i++) splashFrames[i].clear(); + //delete splashFrames; } vector<ofVec2f> trapdoor::getCorners(){ vector<ofVec2f> corners; - corners.push_back(ofVec2f(position.x-(size.x/2),position.y-(size.y/2))); - corners.push_back(ofVec2f(position.x+(size.x/2),position.y-(size.y/2))); - corners.push_back(ofVec2f(position.x+(size.x/2),position.y+(size.y/2))); - corners.push_back(ofVec2f(position.x-(size.x/2),position.y+(size.y/2))); + corners.push_back(ofVec2f(position.x-(size/2),position.y-(size/2))); + corners.push_back(ofVec2f(position.x+(size/2),position.y-(size/2))); + corners.push_back(ofVec2f(position.x+(size/2),position.y+(size/2))); + corners.push_back(ofVec2f(position.x-(size/2),position.y+(size/2))); return corners; } @@ -77,21 +52,22 @@ ofRectangle trapdoor::getBoundingRect(){ } ofRectangle trapdoor::getInnerRect() { //return ofRectangle(boundingRect.x-(boundingRect.width/4),boundingRect.y-(boundingRect.height/4),boundingRect.width/2,boundingRect.height/2); - return ofRectangle(position.x-(size.x/3),position.y-(size.y/3),(2*size.x)/3,(2*size.y)/3); + return ofRectangle(position.x-(size/3),position.y-(size/3),(2*size)/3,(2*size)/3); } void trapdoor::trigger() { - triggeredTime=ofGetElapsedTimef(); - startTime=ofGetElapsedTimef()-10; + triggeredTime=ofGetElapsedTimef(); } +/* 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???? 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; return ofVec2f(u,v); } - +*/ float trapdoor::getFalldist(){ if (triggeredTime>0) return ((ofGetElapsedTimef()-triggeredTime)*.01); else return 0; @@ -111,7 +87,6 @@ bool trapdoor::checkUpdate(map<int,player>& players) { printf("caught!\n"); caught.push_back(&(it->second)); caughtTime.push_back(ofGetElapsedTimef()); - sounds[3].play(); //falling down hole } } } @@ -121,25 +96,11 @@ bool trapdoor::checkUpdate(map<int,player>& players) { } - float segTime=(ofGetElapsedTimef()-startTime); - if (segTime>10) { + float segTime=(ofGetElapsedTimef()-triggeredTime); + if (triggeredTime>0) { doorSpeed=(doorSpeed+((cos(doorAngle*0.0174532925)/ofGetFrameRate())*50))*0.95; doorAngle-=doorSpeed; - if (!opening) { - int whichsound=(int)ofRandom(2.9999999); - sounds[whichsound].play(); - //sound.play(); - opening=true; - } - } - /* - if (segTime>13) { - start(); - return true; - } - else return false; - */ - + } return gotcha; } @@ -166,15 +127,15 @@ void trapdoor::draw() { ofTranslate(ofVec3f(position.x,position.y,0)); ofPushMatrix(); ofRotate(90,-1,0,0); - ofScale(.175,.175,.175); + ofScale(size*.005,size*.005,size*.005); surround.draw(); ofPushMatrix(); - ofTranslate(90,0,0); + ofTranslate(90,0,-5); ofRotate(doorAngle,0,0,-1); lid.draw(); ofPopMatrix(); ofPushMatrix(); - ofTranslate(-90,0,0); + ofTranslate(-90,0,-5); ofRotate(180,0,1,0); ofRotate(doorAngle,0,0,-1); lid.draw(); @@ -191,7 +152,7 @@ void trapdoor::drawSplash(float angle) { ofPushMatrix(); ofTranslate(ofVec3f(position.x,position.y,0)); ofRotate(angle,-1,0,0); - ofScale(0.3,0.3,0.3); + ofScale(size*.01,size*.01,size*.01); if (splashTime<0.5) splashFrames[0].draw(0,0,0); else if (splashTime<0.7) splashFrames[1].draw(0,0,0); else if (splashTime<0.9) splashFrames[2].draw(0,0,0); diff --git a/gaunt01/src/trapdoor.h b/gaunt01/src/trapdoor.h index 6f8b509..7259d09 100644 --- a/gaunt01/src/trapdoor.h +++ b/gaunt01/src/trapdoor.h @@ -18,15 +18,13 @@ creaking sound player class trapdoor { public: - trapdoor(ofVec2f _boundTR=ofVec2f(0,0),ofVec2f _boundBR=ofVec2f(0,0),ofVec2f _doorSize=ofVec2f(10,10)); + trapdoor(ofVec2f pos=ofVec2f(0,0),float _doorSize=10); virtual ~trapdoor(); bool checkUpdate(map<int,player>& players); void draw(); void drawSplash(float angle); void drawDebug(); - void start(); - void startPos(ofVec2f pos); vector<ofVec2f> getCorners(); ofVec2f bounds2UV(ofVec2f pt); @@ -36,22 +34,17 @@ class trapdoor ofRectangle getInnerRect(); void trigger(); float getoffset(); - float getFalldist(); ofImage* splashFrames; //temp public + bool active; protected: private: morphmesh surround; morphmesh lid; ofVec2f position; - ofVec2f boundTR; - ofVec2f boundBR; - ofVec2f size; - - float startTime; - float triggerTime; //time threshold + float size; ofRectangle boundingRect; ofVec2f doorSize; @@ -61,14 +54,10 @@ class trapdoor ofImage texture; - ofSoundPlayer* sounds; - - - bool opening; - float triggeredTime; vector<player*> caught; vector<float> caughtTime; + }; |
