From 01529fbe5dd7cffbc78bd21118e601b0a47172d4 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Wed, 13 Jun 2012 17:53:08 +0100 Subject: centre seeking real good --- gaunt01/src/bird.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'gaunt01/src/bird.cpp') diff --git a/gaunt01/src/bird.cpp b/gaunt01/src/bird.cpp index 18f8227..09e8a60 100644 --- a/gaunt01/src/bird.cpp +++ b/gaunt01/src/bird.cpp @@ -41,6 +41,10 @@ void bird::setBounds(ofPlane* _bounds) { bounds=_bounds; } +void bird::setCentre(ofVec2f _centre) { + //in 2D on plane + centre=_centre; +} bird::~bird() { //dtor @@ -82,6 +86,9 @@ void bird::update(map& players, float angle){ 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); //intersect with bounds and find shortest distance to edge of world + // + // + /* float shortest=1000000.0f; vector pts; int shnum=-1; @@ -108,16 +115,24 @@ void bird::update(map& players, float angle){ else { printf("error: no bird bounds intersection\n"); } + */ + //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)); //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 //mayeb work out how many frames left before we crash - //turn formula max(0,90-abs(turnangle))*sign(turnangle) - //avoiding edges is a bit of a nightmare //what about a force attracting to the middle of the screen? - - turnRate=(turnRate*.99)+(0.05f*max(0.0f,1.0f-(pow(edgelength*.0100f,2.0f)))*max(0.0f,90.0f-abs(edgeangle))*sign(edgeangle)); + float radius=centre.distance(ofVec2f(position.x,position.y)); + //angle from centre to bird position + edgeangle=(180.0f+(90.0f-(atan2(position.y-centre.y,position.x-centre.x)*RAD_TO_DEG)))-heading; + 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 -- cgit v1.2.3