diff options
| -rw-r--r-- | cvtest/cvtest.layout | 8 | ||||
| -rw-r--r-- | cvtest/src/testApp.cpp | 2 | ||||
| -rw-r--r-- | gaunt01/src/bird.cpp | 116 | ||||
| -rw-r--r-- | gaunt01/src/bird.h | 4 | ||||
| -rw-r--r-- | gaunt01/src/testApp.cpp | 4 |
5 files changed, 84 insertions, 50 deletions
diff --git a/cvtest/cvtest.layout b/cvtest/cvtest.layout index bc9e1d9..3ca279e 100644 --- a/cvtest/cvtest.layout +++ b/cvtest/cvtest.layout @@ -4,16 +4,16 @@ <File name="Makefile" open="0" top="0" tabpos="5"> <Cursor position="0" topLine="24" /> </File> - <File name="addons.make" open="1" top="0" tabpos="1"> + <File name="addons.make" open="1" top="0" tabpos="2"> <Cursor position="26" topLine="0" /> </File> <File name="config.make" open="0" top="0" tabpos="2"> <Cursor position="361" topLine="0" /> </File> - <File name="src/testApp.cpp" open="1" top="1" tabpos="3"> - <Cursor position="2817" topLine="79" /> + <File name="src/testApp.cpp" open="1" top="1" tabpos="4"> + <Cursor position="2817" topLine="75" /> </File> - <File name="src/testApp.h" open="1" top="0" tabpos="2"> + <File name="src/testApp.h" open="1" top="0" tabpos="3"> <Cursor position="1113" topLine="17" /> </File> </CodeBlocks_layout_file> diff --git a/cvtest/src/testApp.cpp b/cvtest/src/testApp.cpp index cfde019..75df6c1 100644 --- a/cvtest/src/testApp.cpp +++ b/cvtest/src/testApp.cpp @@ -25,7 +25,7 @@ void testApp::setup(){ } - vidPlayer.loadMovie("camoutput3.mov"); //cam-grass-01.mov"); // //footage/ camera needs to be the same res as opencv planes and output + vidPlayer.loadMovie("cam-grass-01.mov"); //camoutput3.mov"); //cam-grass-01.mov"); // //footage/ camera needs to be the same res as opencv planes and output vidPlayer.setLoopState(OF_LOOP_NORMAL); vidPlayer.play(); diff --git a/gaunt01/src/bird.cpp b/gaunt01/src/bird.cpp index 09e8a60..da246d1 100644 --- a/gaunt01/src/bird.cpp +++ b/gaunt01/src/bird.cpp @@ -26,7 +26,7 @@ bird::bird() position=ofVec3f(ofGetWidth()/2,ofGetHeight(),-ofGetHeight()/10); heading=-90; direction=ofVec3f(0,-1,0); //director for a heading of 0, level - velocity=ofGetWidth()/50; + velocity=1.0f/30; turnRate=20; diveRate=0; @@ -51,16 +51,13 @@ bird::~bird() } void bird::update(map<int,player>& players, float angle){ + //movement basics float time=ofGetElapsedTimef(); float timeSeg=time-lastTime; lastTime=time; - heading=heading+(turnRate*timeSeg); - while (heading>180) heading=heading-360; - while (heading <-180) heading=heading+360; - - position-=direction.rotated(heading,ofVec3f(0,0,-1))*velocity*timeSeg; //.rotate(heading,ofVec3f(0,1,0)) + //tending to straighten unless avoiding an edge //turnRate *= 0.995; @@ -130,19 +127,14 @@ void bird::update(map<int,player>& players, float angle){ while (edgeangle>180.0f) edgeangle -=360.0f; while (edgeangle<-180.0f) edgeangle +=360.0f; turnRate=(turnRate*.995)+(pow(0.002f*radius,2)*edgeangle*0.01); - - //need: a function for generating the angle between things - - - //strip it right back - //bird flying in circle //bird cruising while avoiding edges - //bird floowing people while avoiding edges + //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 ofRay relpointer=ofRay(position,-direction.rotated(heading,ofVec3f(0,0,-1))*1000.0f,false); @@ -151,47 +143,82 @@ 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; map<int,player>::iterator it; for (it=players.begin();it!=players.end();it++) { if (it->second.active) { - ofVec3f p=it->second.getWorldPosition()-position; - playang.push_back(p.angle(-direction.rotated(heading,ofVec3f(0,0,-1)))); - playdist.push_back(p.length()); - playpos.push_back(it->second.getWorldPosition()); float headif=(atan2(it->second.getWorldPosition().x-position.x,it->second.getWorldPosition().y-position.y)*RAD_TO_DEG)-heading; while (headif>180) headif=headif-360; while (headif <-180) headif=headif+360; - playhead.push_back(headif); + if (abs(headif) < 30) { //this could be based on height + playhead.push_back(headif); + ofVec3f p=it->second.getWorldPosition()-position; + playang.push_back(p.angle(-direction.rotated(heading,ofVec3f(0,0,-1)))); + playdist.push_back(p.length()); + playpos.push_back(it->second.getWorldPosition()); + //maybe all of this is unnecessary if we are only following 1 - just save it if nearer + if (p.length() < nearest) { + nearest=p.length(); + nearnum=in; + } + in++; + } } } - //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 (0) { //OutsidePolygon(border,futurepoint)) { - //if (ofVec - leaving=true; - turnRate=centrehead/5; + + //dive behaviour + if (nearnum>-1) { + //influence direction + turnRate+=playhead[nearnum]*.1; + //check if relatively high + if (position.z<-ofGetHeight()/40) { + if (diveRate<2.0f) { + //increase dive rate + diveRate+=0.2f; + } + } + else { + //low enough + if (diveRate>0.0f) { + diveRate*=0.9f; + } + } } 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 (position.z>-ofGetHeight()/10) { + //below ceiling + if (diveRate>-0.5f) { + //increase climb rate + diveRate-=0.05f; } } - if (nearest>-1) turnRate=-playhead[nearest]; + else diveRate*=0.9f; } - */ + + 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- + //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 + + heading=heading+(turnRate*timeSeg); + while (heading>180) heading=heading-360; + while (heading <-180) heading=heading+360; + position-=direction.rotated(heading,ofVec3f(0,0,-1))*(velocity*ofGetHeight()*(1.0f+diveRate))*timeSeg; //.rotate(heading,ofVec3f(0,1,0)) + position +=ofVec3f(0,0,1)*diveRate*timeSeg; } void bird::draw(){ glEnable(GL_DEPTH_TEST); @@ -221,14 +248,19 @@ void bird::drawShadow(){ ofPopMatrix(); } void bird::drawDebug(){ + /* if (leaving) ofSetHexColor(0xff0000); else ofSetHexColor(0xff00ff); ofLine(pointer.s,pointer.s+1000*pointer.t); ofSphere(edgepoint,2.0f); + */ + ofSetHexColor(0xff00ff); char numStr[64]; - sprintf(numStr, "close: %4.1f\nangle: %4.1f\nheading: %4.1f", edgelength,edgeangle,heading); + sprintf(numStr, "dive: %4.2f\nheight: %4.2f", diveRate,position.z); ofDrawBitmapString(numStr,10,10); + + } diff --git a/gaunt01/src/bird.h b/gaunt01/src/bird.h index 1bc99c5..f413911 100644 --- a/gaunt01/src/bird.h +++ b/gaunt01/src/bird.h @@ -92,9 +92,9 @@ class bird ofVec3f direction; - float velocity; //per second + float velocity; //per second relative to ofGetHeight() float turnRate; //per second - float diveRate; //per second + float diveRate; //per second relative to ofGetHeight() float lastTime; diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp index 379fb17..749f6d3 100644 --- a/gaunt01/src/testApp.cpp +++ b/gaunt01/src/testApp.cpp @@ -723,9 +723,11 @@ void testApp::draw(){ ofDrawBitmapString(numStr, sc.x, sc.y); for(int i=0;i<Bird.playpos.size();i++) { + if (abs(Bird.playhead[i])<30) ofSetHexColor(0x77ffff); + else ofSetHexColor(0x555555); ofPushMatrix(); ofRotate(cam_angle,1,0,0); - ofSetHexColor(0x77ffff); + ofLine(Bird.position,Bird.playpos[i]); ofPopMatrix(); |
