summaryrefslogtreecommitdiff
path: root/gaunt01/src/bird.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-06-13 23:50:16 +0100
committerTim Redfern <tim@eclectronics.org>2012-06-13 23:50:16 +0100
commiteecd5a7eb92f24a1e9d3a2e6853363f23ccfccb2 (patch)
treead070ca7e75c7183b96a2e13237ca38430920a2d /gaunt01/src/bird.cpp
parent01529fbe5dd7cffbc78bd21118e601b0a47172d4 (diff)
bird starting to dive
Diffstat (limited to 'gaunt01/src/bird.cpp')
-rw-r--r--gaunt01/src/bird.cpp116
1 files changed, 74 insertions, 42 deletions
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);
+
+
}