From 09fba466578c1074bf7471bbc4615a9047237d46 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 19 Apr 2012 02:14:26 +0100 Subject: bird chasing players --- gaunt01/src/testApp.cpp | 204 +++++++++++++++++++++++++++--------------------- 1 file changed, 117 insertions(+), 87 deletions(-) (limited to 'gaunt01/src/testApp.cpp') diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp index 9e2a574..4047f69 100644 --- a/gaunt01/src/testApp.cpp +++ b/gaunt01/src/testApp.cpp @@ -81,6 +81,8 @@ void testApp::setup(){ cam.cacheMatrices(); //stop error messages testpts=new ofVec3f[4]; + + bounds=new ofPlane[4]; trapDoor=trapdoor(screen2plane(ofVec2f(ofGetWidth(),0)),screen2plane(ofVec2f(ofGetWidth(),ofGetHeight())),ofVec2f(30,30)); updatePlane(); @@ -127,7 +129,35 @@ bool testApp::rectsCross(ofRectangle rect1,ofRectangle rect2) { void testApp::updatePlane(){ + //setup screen for new incline angle plane.setNormal(ofVec3f(0,sin(cam_angle*DEG_TO_RAD),-cos(cam_angle*DEG_TO_RAD))); + + ofVec2f l=ofVec2f(ofGetWidth()/20,ofGetHeight()/2); + ofRay r=projector.castPixel(l.x,l.y); + ofVec3f p; + plane.intersect(r,p); + ofVec3f pn=(p-projector.getGlobalPosition()).getPerpendicular(ofVec3f(0,1,0)); + bounds[0]=ofPlane(p,pn,pn,ofVec2f(1000,1000)); + + l=ofVec2f(ofGetWidth()/2,ofGetHeight()/20); + r=projector.castPixel(l.x,l.y); + plane.intersect(r,p); + pn=(p-projector.getGlobalPosition()).getPerpendicular(ofVec3f(1,0,0)); + bounds[1]=ofPlane(p,pn,-pn,ofVec2f(1000,1000)); + + l=ofVec2f(19*ofGetWidth()/20,ofGetHeight()/2); + r=projector.castPixel(l.x,l.y); + plane.intersect(r,p); + pn=(p-projector.getGlobalPosition()).getPerpendicular(ofVec3f(0,1,0)); + bounds[2]=ofPlane(p,pn,-pn,ofVec2f(1000,1000)); + + l=ofVec2f(ofGetWidth()/2,19*ofGetHeight()/20); + r=projector.castPixel(l.x,l.y); + plane.intersect(r,p); + pn=(p-projector.getGlobalPosition()).getPerpendicular(ofVec3f(1,0,0)); + bounds[1]=ofPlane(p,pn,-pn,ofVec2f(1000,1000)); + + //create ground mesh with hole for trapdoor ground=ofMesh(); ground.addVertex(ofVec3f(0,0,0)); @@ -249,8 +279,10 @@ void testApp::update(){ //check if a key exists in a map - map::count //do we purge them or just stop drawing them? is it a problem inheriting tesselator re memory? //if we keep them we can have a 'loserboard' + set ids; for(int i=0;i::iterator it; + for (it=players.begin();it!=players.end();it++) if(ids.find(it->first)==ids.end()) it->second.active=false; } if (trapDoor.checkUpdate(players)) updatePlane(); - Bird.update(players); + Bird.update(players,cam_angle); + } //-------------------------------------------------------------- void testApp::draw(){ - ofBackground(0,0,0); + + ofBackground(0,0,0); cam.begin(); + + glDisable(GL_DEPTH_TEST); - switch(mode) { - case PLAY: - glDisable(GL_DEPTH_TEST); - - ofSetHexColor(0xffffff); - ofPushMatrix(); - ofRotate(cam_angle,1,0,0); - trapDoor.draw(); - ofPopMatrix(); - - ofSetHexColor(0xffffff); - bindTexture(bgImg); - ground.draw(); - unbindTexture(bgImg); - - ofPushMatrix(); - ofRotate(cam_angle,1,0,0); - Bird.drawShadow(); - ofPopMatrix(); - - glDisable(GL_DEPTH_TEST); - ofSetHexColor(0xffffff); - ofPushMatrix(); - ofRotate(cam_angle,1,0,0); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - trapDoor.drawSplash(cam_angle); - //trapDoor.splashFrames[0].draw(ofGetWidth()/2,ofGetHeight()/2); - glDisable(GL_BLEND); - ofPopMatrix(); - - glDisable(GL_DEPTH_TEST); - ofSetHexColor(0xffffff); - colorImg.getTextureReference().bind(); - for(int i=0;i