diff options
| -rw-r--r-- | gaunt01/src/outsidePolygon.cpp | 1 | ||||
| -rw-r--r-- | gaunt01/src/outsidePolygon.h | 2 | ||||
| -rw-r--r-- | gaunt01/src/testApp.cpp | 198 | ||||
| -rw-r--r-- | gaunt01/src/testApp.h | 13 |
4 files changed, 147 insertions, 67 deletions
diff --git a/gaunt01/src/outsidePolygon.cpp b/gaunt01/src/outsidePolygon.cpp index 8f9b61e..deda88f 100644 --- a/gaunt01/src/outsidePolygon.cpp +++ b/gaunt01/src/outsidePolygon.cpp @@ -2,6 +2,7 @@ bool OutsidePolygon(vector<ofPoint>& polygon,ofPoint p) +//winding rule algorithm for 2D polygon containment test //thanks to Paul Bourke //http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/ { diff --git a/gaunt01/src/outsidePolygon.h b/gaunt01/src/outsidePolygon.h index 7616241..512e98b 100644 --- a/gaunt01/src/outsidePolygon.h +++ b/gaunt01/src/outsidePolygon.h @@ -2,4 +2,4 @@ #include "ofMain.h" -bool OutsidePolygon(vector<ofPoint>& polygon,ofPoint p)
\ No newline at end of file +bool OutsidePolygon(vector<ofPoint>& polygon,ofPoint p);
\ No newline at end of file diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp index a78a690..58505b6 100644 --- a/gaunt01/src/testApp.cpp +++ b/gaunt01/src/testApp.cpp @@ -8,10 +8,6 @@ Can use a floating point image or array to accumulate the screen and generate av Is this too much work for every frame? Should it be put in a seperate thread? - - - - */ void testApp::setup(){ @@ -35,15 +31,7 @@ void testApp::setup(){ useCamera=false; vidPlayer.play(); } -
-/* - colorImg.allocate(640,480); - colorImg.setUseTexture(true); - grayImage.allocate(640,480); - grayBg.allocate(640,480); - grayDiff.allocate(640,480);
- */ - + accumImg.allocate(640,480); bgImg.allocate(640,480); @@ -54,11 +42,7 @@ void testApp::setup(){ grayImage.allocate(640,480); grayBg.allocate(640,480); - grayDiff.allocate(ofGetWidth(),ofGetHeight());
-
-
- - + blobsManager.normalizePercentage = 0.7; blobsManager.giveLowestPossibleIDs = false; blobsManager.maxUndetectedTime = 500; @@ -90,16 +74,36 @@ void testApp::setup(){ mode=PLAY; - drawStats=false; - - bgnum=1000; - firstframe=true; - - light.setPosition(ofGetWidth(),0,ofGetHeight()); - light.enable(); - - drawingborder=false; + drawStats=false; + + bgnum=1000; + firstframe=true; + + light.setPosition(ofGetWidth(),0,ofGetHeight()); + light.enable(); + + drawingborder=false; + billboards=new ofImage[4]; + billboards[0].loadImage("GUI_title.png"); + billboards[1].loadImage("GUI_nzsLogo.png"); + billboards[2].loadImage("GUI_objective.png"); + billboards[3].loadImage("GUI_gotya.png"); + + for (int i=0;i<4;i++) { + billboards[i].setAnchorPercent(0.5,0.5); + } + scaleFactor=ofVec2f(ofGetWidth()/1280.0f,ofGetHeight()/768.0f); + + gameState=TITLES; + + segTimes[TITLES]=5.0; + segTimes[CREDIT]=3.0; + segTimes[EXPLAIN]=6.0; + segTimes[PLAYING]=60.0; + segTimes[GOTCHA]=2.0; + + gameStart=ofGetElapsedTimef(); } ofVec2f testApp::screen2plane(ofVec2f screenpos){ @@ -261,6 +265,8 @@ void testApp::update(){ bLearnBakground = false; } */ + grayDiff.clear(); + grayDiff.allocate(640,480); // take the abs value of the difference between background and incoming and then threshold: grayDiff.absDiff(bgImg, grayImage); @@ -310,55 +316,115 @@ void testApp::update(){ //-------------------------------------------------------------- void testApp::draw(){ + glDisable(GL_LIGHTING); ofBackground(0,0,0); - cam.begin(); - + cam.begin(); glDisable(GL_DEPTH_TEST); - ofSetHexColor(0xffffff); - ofPushMatrix(); - ofRotate(cam_angle,1,0,0); - trapDoor.draw(); - ofPopMatrix(); + glDisable(GL_BLEND); - ofSetHexColor(0xffffff); - bindTexture(bgImg); - ground.draw(); - unbindTexture(bgImg); + if (gameState<PLAYING) colorImg.draw(0,0,ofGetWidth(),ofGetHeight()); + + 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(); + 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); + 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(); + 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(); + } + colorImg.getTextureReference().unbind(); - glDisable(GL_DEPTH_TEST); - ofSetHexColor(0xffffff); - 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(); - } - colorImg.getTextureReference().unbind(); + 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(); + float gameTime=ofGetElapsedTimef()-gameStart; + + switch(gameState) { + case TITLES: + case CREDIT: + case EXPLAIN: + if (gameTime>segTimes[gameState]) { + gameState++; + gameStart=ofGetElapsedTimef(); + } + break; + case PLAYING: + if (gameTime>segTimes[gameState]) { + gameState=TITLES; + gameStart=ofGetElapsedTimef(); + } + break; + } + + float segElapsed=gameTime/segTimes[gameState]; + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + switch(gameState) { + case TITLES: + billboards[0].draw(ofGetWidth()/6 + ,scaleFactor.y*((-billboards[0].height/2)+(billboards[0].height*sin(segElapsed*PI))) + ,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*sin(segElapsed*PI)))) + ,billboards[1].width*scaleFactor.x + ,billboards[1].height*scaleFactor.y); + break; + case EXPLAIN: + billboards[2].draw(ofGetWidth()/2 + ,scaleFactor.y*((-billboards[2].height/2)+(billboards[2].height*sin(segElapsed*PI))) + ,billboards[2].width*scaleFactor.x + ,billboards[2].height*scaleFactor.y); + break; + case PLAYING: + break; + case GOTCHA: + billboards[3].draw(ofGetWidth()/2 + ,scaleFactor.y*((-billboards[2].height/2)+(billboards[3].height*sin(segElapsed*PI))) + ,billboards[3].width*scaleFactor.x + ,billboards[3].height*scaleFactor.y); + break; + } + glDisable(GL_BLEND); - glDisable(GL_LIGHTING); switch(mode) { case PLAY: diff --git a/gaunt01/src/testApp.h b/gaunt01/src/testApp.h index 2ba60c4..4452ee0 100644 --- a/gaunt01/src/testApp.h +++ b/gaunt01/src/testApp.h @@ -21,6 +21,12 @@ #define PLAY 0 #define CALIBRATE 1 +#define TITLES 0 +#define CREDIT 1 +#define EXPLAIN 2 +#define PLAYING 3 +#define GOTCHA 4 + class testApp : public ofBaseApp{ @@ -101,6 +107,13 @@ class testApp : public ofBaseApp{ vector<ofPoint> border; bool drawingborder; + + ofImage* billboards; + ofVec2f scaleFactor; + + int gameState; + float gameStart; + float segTimes[5]; }; |
