summaryrefslogtreecommitdiff
path: root/gaunt01/src/bird.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gaunt01/src/bird.cpp')
-rw-r--r--gaunt01/src/bird.cpp51
1 files changed, 48 insertions, 3 deletions
diff --git a/gaunt01/src/bird.cpp b/gaunt01/src/bird.cpp
index 69549e0..35d9020 100644
--- a/gaunt01/src/bird.cpp
+++ b/gaunt01/src/bird.cpp
@@ -23,13 +23,15 @@ bird::bird()
texture.loadImage("TextureBird.jpg");
//starting pos
- position=ofVec3f(ofGetWidth()/2,ofGetHeight(),-ofGetHeight()/4);
+ position=ofVec3f(ofGetWidth()/2,ofGetHeight(),-ofGetHeight()/10);
heading=-90;
direction=ofVec3f(0,-1,0); //director for a heading of 0, level
velocity=ofGetWidth()/50;
turnRate=20;
diveRate=0;
+
+ fieldofview=60;
lastTime=ofGetElapsedTimef();
}
@@ -39,13 +41,51 @@ bird::~bird()
//dtor
}
-void bird::update(const map<int,player>& players){
+void bird::update(map<int,player>& players, float angle){
float time=ofGetElapsedTimef();
float timeSeg=time-lastTime;
lastTime=time;
- heading+=turnRate*timeSeg;
+ 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))
+
+ //absolute ray pointer
+ 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);
+
+ ofRay relpointer=ofRay(position,-direction.rotated(heading,ofVec3f(0,0,-1))*1000.0f,false);
+
+ playang.clear();
+ playdist.clear();
+ playpos.clear();
+ playhead.clear();
+ playdip.clear();
+
+ 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);
+ }
+ }
+ //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 (nearest>-1) turnRate=playhead[nearest];
+
}
void bird::draw(){
glEnable(GL_DEPTH_TEST);
@@ -74,4 +114,9 @@ void bird::drawShadow(){
model.drawAnimated();
ofPopMatrix();
}
+void bird::drawDebug(){
+ ofSetHexColor(0xff00ff);
+ ofLine(pointer.s,pointer.s+1000*pointer.t);
+}
+