From de766399e2442fbc438123c1c8763e0ae90e6158 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Fri, 20 Apr 2012 03:36:39 +0100 Subject: numerous problems --- gaunt01/src/bird.cpp | 41 ++++-- gaunt01/src/bird.h | 7 +- gaunt01/src/main.cpp | 2 +- gaunt01/src/testApp.cpp | 334 +++++++++++++++++++++++++++++++++++++---------- gaunt01/src/testApp.h | 17 +++ gaunt01/src/trapdoor.cpp | 91 ++++--------- gaunt01/src/trapdoor.h | 19 +-- 7 files changed, 346 insertions(+), 165 deletions(-) (limited to 'gaunt01/src') 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& players, float angle){ +void bird::update(map& players, float angle,vector border){ float time=ofGetElapsedTimef(); float timeSeg=time-lastTime; lastTime=time; @@ -75,16 +77,30 @@ void bird::update(map& players, float angle){ playhead.push_back(headif); } } - //fly towards nearest visible player - int nearest=-1; - float distance=9999; - for(int i=0;i180) 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-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& players,float angle); + void update(map& players,float angle,vector 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 playang; vector playhead; @@ -67,6 +69,9 @@ class bird vector playdist; vector 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 corners=trapdoors[doornumber].getCorners(); + ofVec2f screenCorners[4]; + + for (int i=0;i 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 corners=trapdoors[0].getCorners(); + ofPolyline pol2; + for (int i=0;i corners=trapDoor.getCorners(); + vector corners=trapdoors[0].getCorners(); ofVec2f screenCorners[4]; for (int i=0;isecond.active=true; } } - if (trapDoor.checkUpdate(players)) { - if (gameState=PLAYING) { - gameState=GOTCHA; - gameStart=ofGetElapsedTimef(); + for (int i=0;itrapdoorTime) { + 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::iterator it; for(int i=0;i #include "ofMain.h" +#include "tesselator.h" #include "ofxOpenCv.h" #include "ofxRay.h" @@ -90,6 +91,22 @@ class testApp : public ofBaseApp{ //vector players; trapdoor trapDoor; ofMesh ground; + + vector groundlines; + ofTessellator tess; + + void makeGround(int doornumber); + + vector 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 trapdoor::getCorners(){ vector 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& 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& 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& players); void draw(); void drawSplash(float angle); void drawDebug(); - void start(); - void startPos(ofVec2f pos); vector 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 caught; vector caughtTime; + }; -- cgit v1.2.3