From e64e431b123da3afd0658375f91f50ed00910f67 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 19 Apr 2012 12:01:48 +0100 Subject: billboards etc --- gaunt01/src/testApp.cpp | 198 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 132 insertions(+), 66 deletions(-) (limited to 'gaunt01/src/testApp.cpp') 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::iterator it; + for(int i=0;i::iterator it; - for(int i=0;isegTimes[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: -- cgit v1.2.3