From 81508e0a24b9981f08afe3752093ed626a2c51d9 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Sat, 31 Mar 2012 22:17:55 +0100 Subject: nearly working trap door --- gaunt01/src/testApp.cpp | 6 ++++-- gaunt01/src/trapdoor.cpp | 22 ++++++++++++++++------ gaunt01/src/trapdoor.h | 1 + 3 files changed, 21 insertions(+), 8 deletions(-) (limited to 'gaunt01/src') diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp index 1ab413b..3b81cdd 100644 --- a/gaunt01/src/testApp.cpp +++ b/gaunt01/src/testApp.cpp @@ -39,7 +39,9 @@ void testApp::setup(){ cam.lookAt(ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0),ofVec3f(0, -1, 0)); cam.setFov(42.0); //39.85); //53.13); - trapDoor=trapdoor(ofRectangle(0,0,ofGetWidth(),ofGetHeight()),ofVec2f(20,20)); + trapDoor=trapdoor(ofRectangle(0,ofGetHeight()/4,ofGetHeight(),ofGetHeight()),ofVec2f(20,20)); + + } @@ -114,6 +116,7 @@ void testApp::draw(){ ofPushMatrix(); ofRotate(cam_angle,1,0,0); + //cam.Rotate(cam_angle,1,0,0); for (float i=0;i<=ofGetWidth();i+=ofGetWidth()/10) { glBegin(GL_LINES); @@ -175,7 +178,6 @@ void testApp::draw(){ ofBox(0,-10,0,20); //for now, draw in this axis ofPopMatrix(); - } trapDoor.checkUpdate(players); diff --git a/gaunt01/src/trapdoor.cpp b/gaunt01/src/trapdoor.cpp index b53e30b..607c40f 100644 --- a/gaunt01/src/trapdoor.cpp +++ b/gaunt01/src/trapdoor.cpp @@ -10,6 +10,9 @@ trapdoor::trapdoor(ofRectangle _boundingRect,ofVec2f _doorSize) boundingRect=_boundingRect; doorSize=_doorSize; + + doorAngle=0; + doorSpeed=0; start(); } @@ -19,30 +22,37 @@ trapdoor::~trapdoor() {} void trapdoor::start(){ position=ofVec2f(boundingRect.x+ofRandom(boundingRect.width),boundingRect.y+ofRandom(boundingRect.height)); startTime=ofGetElapsedTimef(); + doorAngle=0; } void trapdoor::checkUpdate(const vector& players) { - if ((ofGetElapsedTimef()-startTime)>5) start(); + float segTime=(ofGetElapsedTimef()-startTime); + if (segTime>5) start(); + if (segTime>4) doorAngle-=(cos(doorAngle*0.0174532925)/ofGetFrameRate())*200; } void trapdoor::draw() { + glEnable(GL_DEPTH_TEST); bindTexture(texture); ofPushMatrix(); + ofRotate(90,-1,0,0); ofTranslate(position.x,0,position.y); + ofRotate(180,-1,0,0); //for now size =40x40 - ofScale(.2,.2,.2); + ofScale(.1,.1,.1); surround.draw(); ofPushMatrix(); - ofTranslate(-90,0,0); - ofRotate(doorAngle,1,0,0); + ofTranslate(90,0,0); + ofRotate(doorAngle,0,0,1); lid.draw(); ofPopMatrix(); ofPushMatrix(); - ofTranslate(90,0,0); + ofTranslate(-90,0,0); ofRotate(180,0,1,0); - ofRotate(doorAngle,1,0,0); + ofRotate(doorAngle,0,0,1); lid.draw(); ofPopMatrix(); ofPopMatrix(); unbindTexture(texture); + glDisable(GL_DEPTH_TEST); } diff --git a/gaunt01/src/trapdoor.h b/gaunt01/src/trapdoor.h index 16ad3b1..43121e3 100644 --- a/gaunt01/src/trapdoor.h +++ b/gaunt01/src/trapdoor.h @@ -38,6 +38,7 @@ class trapdoor ofVec2f doorSize; float doorAngle; + float doorSpeed; ofImage texture; -- cgit v1.2.3