diff options
| author | Tim Redfern <tim@eclectronics.org> | 2012-06-13 17:53:08 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2012-06-13 17:53:08 +0100 |
| commit | 01529fbe5dd7cffbc78bd21118e601b0a47172d4 (patch) | |
| tree | 7a1a99fa53ac48dc727b923d8c3695cf6ef4f096 /gaunt01 | |
| parent | e05bc2828bc213f1e78256f976284bad80722e1a (diff) | |
centre seeking real good
Diffstat (limited to 'gaunt01')
| -rw-r--r-- | gaunt01/src/bird.cpp | 23 | ||||
| -rw-r--r-- | gaunt01/src/bird.h | 2 | ||||
| -rw-r--r-- | gaunt01/src/testApp.cpp | 10 | ||||
| -rw-r--r-- | gaunt01/src/testApp.h | 1 |
4 files changed, 31 insertions, 5 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 diff --git a/gaunt01/src/bird.h b/gaunt01/src/bird.h index c1f3ac7..1bc99c5 100644 --- a/gaunt01/src/bird.h +++ b/gaunt01/src/bird.h @@ -59,6 +59,7 @@ class bird void drawDebug(); void setBounds(ofPlane* _bounds); + void setCentre(ofVec2f _centre); string currentseq; morphmesh model; @@ -77,6 +78,7 @@ class bird vector<ofVec3f> playpos; ofPlane* bounds; + ofVec2f centre; bool leaving; float centrehead; diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp index 6ac3d26..379fb17 100644 --- a/gaunt01/src/testApp.cpp +++ b/gaunt01/src/testApp.cpp @@ -137,7 +137,6 @@ void testApp::setup(){ cam.end(); updatePlane(); - Bird.setBounds(bounds); } @@ -291,6 +290,15 @@ 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)); // vector<trapdoor> trapdoors; diff --git a/gaunt01/src/testApp.h b/gaunt01/src/testApp.h index 01301de..ca10681 100644 --- a/gaunt01/src/testApp.h +++ b/gaunt01/src/testApp.h @@ -124,6 +124,7 @@ class testApp : public ofBaseApp{ ofLight light; ofPlane* bounds; + ofVec3f centre; vector<ofPoint> border; bool drawingborder; |
