summaryrefslogtreecommitdiff
path: root/gaunt01/src/bird.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2012-06-13 17:53:08 +0100
committerTim Redfern <tim@eclectronics.org>2012-06-13 17:53:08 +0100
commit01529fbe5dd7cffbc78bd21118e601b0a47172d4 (patch)
tree7a1a99fa53ac48dc727b923d8c3695cf6ef4f096 /gaunt01/src/bird.cpp
parente05bc2828bc213f1e78256f976284bad80722e1a (diff)
centre seeking real good
Diffstat (limited to 'gaunt01/src/bird.cpp')
-rw-r--r--gaunt01/src/bird.cpp23
1 files changed, 19 insertions, 4 deletions
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<int,player>& 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 <ofVec3f> pts;
int shnum=-1;
@@ -108,16 +115,24 @@ void bird::update(map<int,player>& 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