diff options
| author | Tim Redfern <tim@eclectronics.org> | 2012-07-09 20:36:05 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2012-07-09 20:36:05 +0100 |
| commit | cae8be229004e32ce76b38e207ea24a02434b18d (patch) | |
| tree | 41bda9fc65dcdee9393851bb943321e2945cc8d8 | |
| parent | 8e22cdc4203dc04e7fdfdd607f27c6b2a61f458b (diff) | |
version 1.2
| -rw-r--r-- | gaunt01/bin/data/settings.xml | 2 | ||||
| -rw-r--r-- | gaunt01/gaunt01.cbp | 6 | ||||
| -rw-r--r-- | gaunt01/notes.txt | 1 | ||||
| -rw-r--r-- | gaunt01/src/bird.cpp | 48 | ||||
| -rw-r--r-- | gaunt01/src/testApp.cpp | 154 | ||||
| -rw-r--r-- | gaunt01/src/testApp.h | 25 |
6 files changed, 122 insertions, 114 deletions
diff --git a/gaunt01/bin/data/settings.xml b/gaunt01/bin/data/settings.xml index 925e199..df7427c 100644 --- a/gaunt01/bin/data/settings.xml +++ b/gaunt01/bin/data/settings.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<gauntlet cam_angle="-55" threshold="30" keyChannel="6" learningRate="0.001" /> +<gauntlet cam_angle="-55" threshold="24" keyChannel="6" learningRate="0.001" remove_shadows="0" /> <bounds> <vertex x="664.309" y="866.4"></vertex> <vertex x="844.015" y="425.757"></vertex> diff --git a/gaunt01/gaunt01.cbp b/gaunt01/gaunt01.cbp index e8a613c..25fe540 100644 --- a/gaunt01/gaunt01.cbp +++ b/gaunt01/gaunt01.cbp @@ -33,9 +33,15 @@ <Unit filename="addons.make"> <Option virtualFolder="build config/" /> </Unit> + <Unit filename="bin/data/settings.xml"> + <Option virtualFolder="build config/" /> + </Unit> <Unit filename="config.make"> <Option virtualFolder="build config" /> </Unit> + <Unit filename="notes.txt"> + <Option virtualFolder="build config/" /> + </Unit> <Unit filename="src/bird.cpp"> <Option virtualFolder="src/" /> </Unit> diff --git a/gaunt01/notes.txt b/gaunt01/notes.txt new file mode 100644 index 0000000..e9cb0aa --- /dev/null +++ b/gaunt01/notes.txt @@ -0,0 +1 @@ +bird slowdown faster when in attack mode: get actually blocked diff --git a/gaunt01/src/bird.cpp b/gaunt01/src/bird.cpp index fe6bf17..b451c65 100644 --- a/gaunt01/src/bird.cpp +++ b/gaunt01/src/bird.cpp @@ -18,10 +18,10 @@ bird::bird() else printf("animation XML file not parsed\n"); model.sequences["swoop"].start(); - + //how to track state/ bring animation in and out state=SWOOPING; - + aggressives=new ofSoundPlayer[2]; aggressives[0].loadSound("aggressive1.wav"); aggressives[1].loadSound("aggressive2.wav"); @@ -32,7 +32,7 @@ bird::bird() rattles[0].loadSound("rattle1.wav"); rattles[1].loadSound("rattle2.wav"); rattles[2].loadSound("rattle3.wav"); - + //emit a rattle when the bird becomes vsisible and when it switches back to scanning //emit a chirp when it switches to swooping //emit an aggressive noise when it attacks @@ -69,13 +69,13 @@ bird::~bird() } void bird::update(map<int,player>& players, float angle){ - + //movement basics float time=ofGetElapsedTimef(); float timeSeg=time-lastTime; lastTime=time; - + //this is causing the bird to go off the screen at the start.. maybe not a problem.. 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); @@ -112,7 +112,7 @@ void bird::update(map<int,player>& players, float angle){ } */ //avoiding edges is a bit of a nightmare - //turnRate=(turnRate*.99)+(0.05f*max(0.0f,1.0f-(pow(edgelength*.0100f,2.0f)))*max(0.0f,90.0f-abs(edgeangle))*sign(edgeangle)); + //turnRate=(turnRate*.99)+(0.05f*max(0.0f,1.0f-(pow(edgelength*.0100f,2.0f)))*max(0.0f,90.0f-abs(edgeangle))*sign(edgeangle)); //decide whether we are running out of space and if so, which way to turn# //turning tendency is more acute when we are more perpendicular, and closer, to the edge @@ -130,7 +130,7 @@ void bird::update(map<int,player>& players, float angle){ //bird floowing people while staying on screen //bird changing height //morph targets - + //make a list of players within view and decide which one is the best target //1sr draw lines and visualise @@ -141,7 +141,7 @@ void bird::update(map<int,player>& players, float angle){ playpos.clear(); playhead.clear(); playdip.clear(); - + float nearest=1000000.0f; int nearnum=-1; int in=0; @@ -172,7 +172,7 @@ void bird::update(map<int,player>& players, float angle){ } } } - + //dive behaviour if (nearnum>-1) { //influence direction @@ -199,11 +199,11 @@ void bird::update(map<int,player>& players, float angle){ diveRate-=0.05f; } } - else diveRate*=0.9f; + else diveRate*=0.9f; } - - float neardist=ofGetWidth()/12.0f; - + + float neardist=ofGetWidth()/20.0f; + if ((state==SCANNING||state==SWOOPING)&&nearnum>-1) { if (playdist[nearnum]<neardist) { model.sequences["flap"].fadeout(0.5); @@ -214,7 +214,7 @@ void bird::update(map<int,player>& players, float angle){ aggressives[whichsound].play(); } } - + velocity *=(1.0f+(diveRate*.01)); //leave mode switch switch (state) { @@ -249,31 +249,31 @@ void bird::update(map<int,player>& players, float angle){ whistles[whichsound].play(); } if (nearnum>-1) { - velocity*=(19+(playdist[nearnum]/neardist))*.05; //slow down + velocity*=(9+(playdist[nearnum]/neardist))*.1; //slow down } break; } - + if (diveRate<0.0f) setSpeed(1.0f-diveRate); else setSpeed(1.0f); - + //if (sign(turnRate)) turnRate=min(2.0f,turnRate); //else turnRate=max(-2.0f,turnRate); - + //if high and target is in sight, swoop to gain speed //if low and no narget is near, climb to gain a view - + //for now, when the bird hits the target they both blink and the board comes down? - //initially, get the bird to connect with players- + //initially, get the bird to connect with players- //integrate new keying //interface - update info - save data //do the documentation //go back to the bird - watch out for dead players (from trap doors) - bird is going out of play - just retrieve it for now? //flap faster while climbing + swoop //bird noises - + //increase angle of view and allow more extreme turn angles - + heading=heading+(turnRate*timeSeg); while (heading>180) heading=heading-360; while (heading <-180) heading=heading+360; @@ -322,8 +322,8 @@ void bird::drawDebug(){ sprintf(numStr, "dive: %4.2f\nheight: %4.2f\n%s\n%4.2f,%4.2f,%4.2f", diveRate,position.z,state==1?"SCANNING":state==2?"SWOOPING":"ATTACKING",position.x,position.y,position.z); ofDrawBitmapString(numStr,10,10); } - - + + } void bird::setSpeed(float speed){ diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp index 6522f91..8e3487a 100644 --- a/gaunt01/src/testApp.cpp +++ b/gaunt01/src/testApp.cpp @@ -23,7 +23,7 @@ void testApp::setup(){ this->windowWidth = ofGetWidth(); this->windowHeight = ofGetHeight(); } - + mirror=true; bLearnBakground = true; @@ -52,12 +52,12 @@ void testApp::setup(){ bgImg.allocate(640,480); bgImg.setUseTexture(true); -
+
grayImage.allocate(640,480); grayBg.allocate(640,480); */ - + colorImg.allocate(640,480); colorImg.setUseTexture(true); currentFrame.allocate(CAM_WIDTH_FG, CAM_HEIGHT_FG); @@ -67,16 +67,16 @@ void testApp::setup(){ grayFrame.allocate(CAM_WIDTH_FG, CAM_HEIGHT_FG); grayBg.allocate(CAM_WIDTH_FG, CAM_HEIGHT_FG); grayDiff.allocate(CAM_WIDTH_FG, CAM_HEIGHT_FG); - + mogoutput.allocate(CAM_WIDTH_FG, CAM_HEIGHT_FG); learningRate = 0.01f; bFirstFrame=true; - + diffchannel=chan_V; hsvback = cvCreateImage(cvGetSize(currentFrame.getCvImage()), currentFrame.getCvImage()->depth, currentFrame.getCvImage()->nChannels); //backchan = cvCreateImage(cvGetSize(currentFrame.getCvImage()), 8, 1); - + removeShadows=false; shadowThreshold=10; //////////////////////////// @@ -128,14 +128,13 @@ void testApp::setup(){ drawingborder=false; - billboards=new ofImage[5]; + 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"); - billboards[4].loadImage("GUI_instructions.png"); + billboards[1].loadImage("GUI_objective.png"); + billboards[2].loadImage("GUI_gotya.png"); + billboards[3].loadImage("GUI_instructions.png"); - for (int i=0;i<5;i++) { + for (int i=0;i<4;i++) { billboards[i].setAnchorPercent(0.5,0.5); } scaleFactor=ofVec2f(windowWidth/1280.0f,windowHeight/768.0f); @@ -143,7 +142,6 @@ void testApp::setup(){ gameState=TITLES; //PLAYING; //TITLES; // segTimes[TITLES]=4.0; - segTimes[CREDIT]=2.5; segTimes[EXPLAIN]=5.0; segTimes[PLAYING]=60.0; segTimes[GOTCHA]=4.0; @@ -317,13 +315,13 @@ void testApp::updatePlane(){ else printf("bound plane 4 not found\n"); pn=(p-projector.getGlobalPosition()).getPerpendicular(ofVec3f(-1,0,0)); bounds[3]=ofPlane(p,pn); //,-pn,ofVec2f(1000,1000)); - + l=ofVec2f(windowWidth/2,windowHeight/2); r=projector.castPixel(l.x,l.y); if (plane.intersect(r,centre)) printf("found centre point at %f,%f,%f\n",centre.x,centre.y,centre.z); else printf("centre point not found\n"); ofVec3f c=centre.rotated(cam_angle,ofVec3f(-1,0,0)); - + Bird.setBounds(bounds); Bird.setCentre(ofVec2f(c.x,c.y)); @@ -462,11 +460,11 @@ void testApp::update(){ colorImg.setFromPixels(vidPlayer.getPixels(), 640,480); //accumImg.setFromPixels(vidPlayer.getPixels(), 640,480); } - + if (mirror) colorImg.mirror(false,true); colorImg.updateTexture(); - + /* grayImage = colorImg; @@ -499,42 +497,42 @@ void testApp::update(){ //hard coded size threshold of 100 pix contourFinder.findContours(grayDiff, 200, (640*480)/3, 20, false); // don't find holes - + */ - + cv::Mat img = colorImg.getCvImage(); - + //if (frameno%1==0) { //I THINK THIS APPROACH IS OK to attempt to lower cpu hit from accumulating? - + //cv::Rect roi(0, 0, 32, 32); //doesn't seem that easy to apply the ROI weighted and you still have to convert a whole image each frame? - + //cv::Mat imgroi = img(roi); - + if (bFirstFrame) { img.convertTo(accumulator, CV_32FC3); bFirstFrame=false; } - + cv::Mat im3; img.convertTo(im3, CV_32FC3); - + //accumulator; accumulateWeighted(im3, accumulator, max(1.0f/(ofGetElapsedTimef()*30.0f),learningRate)); accumulator.convertTo(outmat,CV_8UC3); - + IplImage* tmp = new IplImage(outmat); background=tmp; background.updateTexture(); - + //printf("tmp: %ix%i channels: %i depth:%i\n",tmp->width,tmp->height,tmp->nChannels,tmp->depth); - - + + //get correct channel into backchan - + vector<cv::Mat> chans; - + //to remove shadows, need hsv of foreground and background if (diffchannel>chan_B||removeShadows) cvtColor(outmat, hsvback, CV_BGR2HSV); switch (diffchannel) { @@ -563,64 +561,64 @@ void testApp::update(){ chans[2].copyTo(backchan); break; } - + tmp = new IplImage(backchan); grayBg = tmp; - + //} //first, optionally remove shadows from FG //possibly use 1/4 screen res? - + //to remove shadows, need hsv of foreground and background if (diffchannel>chan_B||removeShadows) cvtColor(img, hsvfront, CV_BGR2HSV); - + cv::Mat outimg; - + if (removeShadows) { vector<cv::Mat> slicesFront, slicesBack; cv::Mat valFront, valBack, satFront, satBack; - + // split image to H,S and V images split(hsvfront, slicesFront); split(hsvback, slicesBack); - + slicesFront[2].copyTo(valFront); // get the value channel slicesFront[1].copyTo(satFront); // get the sat channel - + slicesBack[2].copyTo(valBack); // get the value channel slicesBack[1].copyTo(satBack); // get the sat channel - + int x,y; for(x=0; x<currentFrame.getWidth(); ++x) { for(y=0; y<currentFrame.getHeight(); ++y) { bool sat = ((satFront.at<cv::Vec3b>(y,x)[0] > satBack.at<cv::Vec3b>(y,x)[0]-shadowThreshold) && (satFront.at<cv::Vec3b>(y,x)[0] < satBack.at<cv::Vec3b>(y,x)[0]+shadowThreshold)); - + if(sat && (valFront.at<cv::Vec3b>(y,x)[0] < valBack.at<cv::Vec3b>(y,x)[0])) { - hsvfront.at<cv::Vec3b>(y,x)[0]= hsvback.at<cv::Vec3b>(y,x)[0]; - hsvfront.at<cv::Vec3b>(y,x)[1]= hsvback.at<cv::Vec3b>(y,x)[1]; + hsvfront.at<cv::Vec3b>(y,x)[0]= hsvback.at<cv::Vec3b>(y,x)[0]; + hsvfront.at<cv::Vec3b>(y,x)[1]= hsvback.at<cv::Vec3b>(y,x)[1]; hsvfront.at<cv::Vec3b>(y,x)[2]= hsvback.at<cv::Vec3b>(y,x)[2]; } - + } } //convert back into RGB if necessary - + if (diffchannel<chan_H) cvtColor(hsvfront, outimg, CV_HSV2BGR); else outimg=hsvfront; - + }else { outimg=img; - } + } + - //select correct channel for comparison and put into grayFrame - + //vector<cv::Mat> chans; split(outimg,chans); - + switch (diffchannel) { case chan_R: chans[0].copyTo(frontchan); @@ -641,14 +639,14 @@ void testApp::update(){ chans[2].copyTo(frontchan); break; } - + //IplImage* tmp = new IplImage(outmat); tmp = new IplImage(frontchan); grayFrame = tmp; - + grayDiff.clear(); grayDiff.allocate(640,480); - + // take the abs value of the difference between background and incoming and then threshold: grayDiff.absDiff(grayBg, grayFrame); grayDiff.threshold(threshold); @@ -659,14 +657,14 @@ void testApp::update(){ /* //MOG mog(img, outmat, mogf); - + // Complement the image //cv::threshold(outmat, output, threshold, 255, cv::THRESH_BINARY_INV); IplImage* tmp1 = new IplImage(outmat); //printf("tmp: %ix%i channels: %i depth:%i\n",tmp->width,tmp->height,tmp->nChannels,tmp->depth); //printf("grayDiff: %ix%i channels: %i depth:%i\n",grayDiff.getCvImage()->width,grayDiff.getCvImage()->height,grayDiff.getCvImage()->nChannels,grayDiff.getCvImage()->depth); grayDiff=tmp1; //copy to ofx -*/ +*/ grayDiff.resize(windowWidth,windowHeight); //wasteful?? @@ -775,7 +773,7 @@ void testApp::draw(){ glDisable(GL_BLEND); ofPopMatrix(); - + glDisable(GL_DEPTH_TEST); ofSetHexColor(0xffffff); bindTexture(colorImg); //colorImg.getTextureReference().bind(); @@ -799,7 +797,6 @@ void testApp::draw(){ switch(gameState) { case TITLES: - case CREDIT: case EXPLAIN: if (gameTime>segTimes[gameState]) { gameState++; @@ -837,25 +834,27 @@ void testApp::draw(){ ,billboards[0].width*scaleFactor.x ,billboards[0].height*scaleFactor.y); break; + /* case CREDIT: billboards[1].draw(windowWidth/6 ,windowHeight+(scaleFactor.y*((billboards[1].height/2)-(billboards[1].height*pow(sin(segElapsed*PI),0.4)))) ,billboards[1].width*scaleFactor.x ,billboards[1].height*scaleFactor.y); break; + */ case EXPLAIN: - billboards[2].draw(windowWidth/2 - ,scaleFactor.y*((-billboards[2].height/2)+(billboards[2].height*pow(sin(segElapsed*PI),0.4))) - ,billboards[2].width*scaleFactor.x - ,billboards[2].height*scaleFactor.y); + billboards[1].draw(windowWidth/2 + ,scaleFactor.y*((-billboards[1].height/2)+(billboards[1].height*pow(sin(segElapsed*PI),0.4))) + ,billboards[1].width*scaleFactor.x + ,billboards[1].height*scaleFactor.y); break; case PLAYING: break; case GOTCHA: - billboards[3].draw(windowWidth/2 - ,scaleFactor.y*((-billboards[2].height/2)+(billboards[3].height*pow(sin(segElapsed*PI),0.4))) - ,billboards[3].width*scaleFactor.x - ,billboards[3].height*scaleFactor.y); + billboards[2].draw(windowWidth/2 + ,scaleFactor.y*((-billboards[2].height/2)+(billboards[2].height*pow(sin(segElapsed*PI),0.4))) + ,billboards[2].width*scaleFactor.x + ,billboards[2].height*scaleFactor.y); break; } glDisable(GL_BLEND); @@ -923,7 +922,7 @@ void testApp::draw(){ else ofSetHexColor(0x555555); ofPushMatrix(); ofRotate(cam_angle,1,0,0); - + ofLine(Bird.position,Bird.playpos[i]); ofPopMatrix(); @@ -942,7 +941,7 @@ void testApp::draw(){ char numStr[16]; sprintf(numStr, "%i", blobsManager.blobs[i].id); ofDrawBitmapString(numStr, blob.boundingRect.x, blob.boundingRect.y); - + /* ofPushMatrix(); ofRotate(cam_angle,1,0,0); @@ -972,7 +971,7 @@ void testApp::draw(){ if (drawStats||mode==CALIBRATE) { ofSetHexColor(0xffffff); char reportStr[1024]; - sprintf(reportStr, "threshold %i",threshold); //\nnum blobs found %i, fps: %f", threshold, contourFinder.nBlobs, ofGetFrameRate()); + sprintf(reportStr, "threshold %i\nfps: %3.1f",threshold,ofGetFrameRate()); //\nnum blobs found %i, fps: %f", threshold, contourFinder.nBlobs, ofGetFrameRate()); ofDrawBitmapString(reportStr, 10, windowHeight-30); /* char numStr[16]; @@ -986,7 +985,7 @@ void testApp::draw(){ if (drawInstructions) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - billboards[4].draw(windowWidth/2,windowHeight/2); + billboards[3].draw(windowWidth/2,windowHeight/2); glDisable(GL_BLEND); } } @@ -1034,7 +1033,7 @@ void testApp::keyPressed(int key){ case '0': mode=CALIBRATE; break; - + case '1': diffchannel = chan_R; break; @@ -1053,14 +1052,15 @@ void testApp::keyPressed(int key){ case '6': diffchannel = chan_V; break; - - /* - case 's': + + + case 'r': + case 'R': removeShadows=!removeShadows; printf(removeShadows?"removing shadows\n":"not removing shadows\n"); break; - - + +/* case '1': if (Bird.currentseq!="hover") { //mesh.sequences["trans_flaphover"].stopAt(0.3); @@ -1139,7 +1139,7 @@ void testApp::keyPressed(int key){ gameState=(gameState+1)%4; gameStart=ofGetElapsedTimef(); break; - + */ } } @@ -1197,6 +1197,7 @@ void testApp::loadSettings(string filename){ threshold=ofToInt(XML.getAttribute("gauntlet","threshold","none",0)); diffchannel=ofToInt(XML.getAttribute("gauntlet","keyChannel","none",0)); learningRate=ofToFloat(XML.getAttribute("gauntlet","learningRate","none",0)); + removeShadows=ofToInt(XML.getAttribute("gauntlet","remove_shadows","none",0))==1; if(XML.pushTag("bounds")) { for (int i=0;i<XML.getNumTags("vertex");i++){ border.push_back(ofVec2f(ofToFloat(XML.getAttribute("vertex","x","0",i)),ofToFloat(XML.getAttribute("vertex","y","0",i)))); @@ -1211,6 +1212,7 @@ void testApp::saveSettings(string filename){ XML.setAttribute("gauntlet","cam_angle",ofToString(cam_angle),0); XML.setAttribute("gauntlet","threshold",ofToString(threshold),0); XML.setAttribute("gauntlet","keyChannel",ofToString(diffchannel),0); + XML.setAttribute("gauntlet","remove_shadows",ofToString(removeShadows),0); if (XML.tagExists("bounds")) XML.removeTag("bounds"); XML.addTag("bounds"); if(XML.pushTag("bounds")) { diff --git a/gaunt01/src/testApp.h b/gaunt01/src/testApp.h index 4fa679e..7c95e6e 100644 --- a/gaunt01/src/testApp.h +++ b/gaunt01/src/testApp.h @@ -23,10 +23,9 @@ #define CALIBRATE 1 #define TITLES 0 -#define CREDIT 1 -#define EXPLAIN 2 -#define PLAYING 3 -#define GOTCHA 4 +#define EXPLAIN 1 +#define PLAYING 2 +#define GOTCHA 3 #define CAM_WIDTH_FG 640 #define CAM_HEIGHT_FG 480 @@ -78,27 +77,27 @@ class testApp : public ofBaseApp{ ofVideoPlayer vidPlayer; ofxCvColorImage colorImg; - + int diffchannel; - + cv::Mat accumulator,outmat,hsvback,hsvfront,backchan,frontchan,output; // background accumulation - + ofxCvColorImage currentFrame; ofxCvColorImage background; - + ofxCvColorImage mogoutput; - + ofxCvGrayscaleImage grayFrame; ofxCvGrayscaleImage grayBg; ofxCvGrayscaleImage grayDiff; - + float learningRate; bool bFirstFrame; - + //cv::BackgroundSubtractorMOG mog; - + float mogf; - + bool removeShadows; int shadowThreshold; /*
|
