From f65006daf4979d82d67fd8c8a234d3913088821d Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 5 Apr 2012 14:00:51 +0100 Subject: starting to implement bird --- gaunt01/gaunt01.cbp | 6 ++++ gaunt01/gaunt01_win.cbp | 7 ++++- gaunt01/src/bird.cpp | 42 +++++++++++++++++++++++++++ gaunt01/src/bird.h | 57 +++++++++++++++++++++++++++++++++++++ gaunt01/src/morphmesh.cpp | 20 ++++++------- gaunt01/src/morphmesh.h | 13 ++++++++- gaunt01/src/testApp.cpp | 72 ++++++++++++++++++++++++++--------------------- gaunt01/src/testApp.h | 17 ++++++----- gaunt01/src/trapdoor.cpp | 16 +++++++---- gaunt01/src/trapdoor.h | 3 ++ 10 files changed, 197 insertions(+), 56 deletions(-) create mode 100644 gaunt01/src/bird.cpp create mode 100644 gaunt01/src/bird.h (limited to 'gaunt01') diff --git a/gaunt01/gaunt01.cbp b/gaunt01/gaunt01.cbp index f3278b2..c474946 100644 --- a/gaunt01/gaunt01.cbp +++ b/gaunt01/gaunt01.cbp @@ -90,6 +90,12 @@ + + + + diff --git a/gaunt01/gaunt01_win.cbp b/gaunt01/gaunt01_win.cbp index 0263561..4b7a79f 100644 --- a/gaunt01/gaunt01_win.cbp +++ b/gaunt01/gaunt01_win.cbp @@ -100,6 +100,7 @@ + @@ -152,7 +153,7 @@ - + @@ -183,6 +184,10 @@ + + + + diff --git a/gaunt01/src/bird.cpp b/gaunt01/src/bird.cpp new file mode 100644 index 0000000..204bf6e --- /dev/null +++ b/gaunt01/src/bird.cpp @@ -0,0 +1,42 @@ +#include "bird.h" + +bird::bird() +{ + model.loadMesh("Bird-test.xml"); + texture.loadImage("TextureBird.jpg"); + + //starting pos + position=ofVec3f(ofGetWidth()/2,ofGetHeight()/3,ofGetHeight()/2); + heading=ofVec3f(-1,0,0); + direction=ofVec3f(-1,0,0); + velocity=ofGetWidth()/100; + + turnAngle=0; + diveAngle=0; + + lastTime=ofGetElapsedTimef(); +} + +bird::~bird() +{ + //dtor +} + +void bird::update(const vector& players){ + float time=ofGetElapsedTimef(); + float timeSeg=time-lastTime; + lastTime=time; + position+=direction*velocity*timeSeg; +} +void bird::draw(){ + ofPushMatrix(); + ofTranslate(position); + //ofRotate(direction); + ofRotate(90,0,-1,0); + //ofRotate(180,1,0,0); + bindTexture(texture); + model.draw(); + unbindTexture(texture); + ofPopMatrix(); +} + diff --git a/gaunt01/src/bird.h b/gaunt01/src/bird.h new file mode 100644 index 0000000..4114ad3 --- /dev/null +++ b/gaunt01/src/bird.h @@ -0,0 +1,57 @@ +#ifndef BIRD_H +#define BIRD_H + +/* + Hostile bird character for 'Run the gauntlet' game + + Tim Redfern April 2012 + + ??how to manage visibility + Bird should automatically stay within viewing volume of camera + + from the birds POV, The visible area is a frustrum extending down from the camera + + 1) like opensteer, extend the birds heading and decide whether this will hit the edge + 2) have an actual model of the volume and work within it + + 3) how do we make the bird aware of players in front of it + + --> this all implies being able to take a sightline from the bird and determine + -visibility of objects + -distance to obstructions + + -build basic of time/speed/heading update/draw + -basic anim cycle + +*/ + +#include "ofMain.h" +#include "morphmesh.h" +#include "normBindTexture.h" + + +class bird +{ + public: + bird(); + virtual ~bird(); + void update(const vector& players); + void draw(); + protected: + private: + + ofVec3f position; + ofVec3f heading; + ofVec3f direction; + + float velocity; //per second + float turnAngle; //per second + float diveAngle; //per second + + float lastTime; + + morphmesh model; + ofImage texture; +}; + +#endif // BIRD_H diff --git a/gaunt01/src/morphmesh.cpp b/gaunt01/src/morphmesh.cpp index 64bc24e..475f93b 100644 --- a/gaunt01/src/morphmesh.cpp +++ b/gaunt01/src/morphmesh.cpp @@ -4,11 +4,11 @@ morphmesh::morphmesh() { loaded=false; } - + morphmesh::morphmesh(string filename) { morphmesh(); - loadfile(filename); + loadMesh(filename); } morphmesh::~morphmesh() @@ -47,7 +47,7 @@ void morphmesh::draw(const vector& targets, const vector& weights){ ofMesh::draw(); } -bool morphmesh::loadfile(string filename){ +bool morphmesh::loadMesh(string filename){ loaded=false; ofxXmlSettings XML; if( !XML.loadFile(filename) ){ @@ -60,7 +60,7 @@ bool morphmesh::loadfile(string filename){ XML.pushTag("Mesh",i); if (XML.pushTag("AttributeList")) { vector verts; - + string vertstring=XML.getAttribute("Attribute","Data","none",0); stringstream ss(vertstring); istream_iterator begin(ss); @@ -70,10 +70,10 @@ bool morphmesh::loadfile(string filename){ verts.push_back(ofVec3f(ofToFloat(vstrings[j]),ofToFloat(vstrings[j+1]),ofToFloat(vstrings[j+2]))); } morphs.push_back(verts); - + if (i==0) { addVertices(verts); - + vector norms; string normstring=XML.getAttribute("Attribute","Data","none",1); stringstream ns(normstring); @@ -84,7 +84,7 @@ bool morphmesh::loadfile(string filename){ norms.push_back(ofVec3f(ofToFloat(nstrings[j]),ofToFloat(nstrings[j+1]),ofToFloat(nstrings[j+2]))); } addNormals(norms); - + vector texcords; string texstring=XML.getAttribute("Attribute","Data","none",2); stringstream ts(texstring); @@ -95,9 +95,9 @@ bool morphmesh::loadfile(string filename){ texcords.push_back(ofVec2f(ofToFloat(tstrings[j]),ofToFloat(tstrings[j+1]))); } addTexCoords(texcords); - + XML.popTag(); - + if (XML.pushTag("IndexList")) { vector faces; string facestring=XML.getAttribute("Index","Data","none",0); @@ -130,4 +130,4 @@ bool morphmesh::loadfile(string filename){ bool morphmesh::isLoaded() { return loaded; -} \ No newline at end of file +} diff --git a/gaunt01/src/morphmesh.h b/gaunt01/src/morphmesh.h index 91a8f17..76a6063 100644 --- a/gaunt01/src/morphmesh.h +++ b/gaunt01/src/morphmesh.h @@ -21,13 +21,24 @@ Coords are absolute */ +class sequence +{ + //stores a morph sequence: an animation cycle or transition + public: + sequence(); + virtual ~sequence(); + + +}; + + class morphmesh : public ofMesh { public: morphmesh(); morphmesh(string filename); virtual ~morphmesh(); - bool loadfile(string filename); + bool loadMesh(string filename); bool isLoaded(); void draw(); void draw(int target); diff --git a/gaunt01/src/testApp.cpp b/gaunt01/src/testApp.cpp index aebbe0b..172190f 100644 --- a/gaunt01/src/testApp.cpp +++ b/gaunt01/src/testApp.cpp @@ -30,11 +30,11 @@ void testApp::setup(){ grayImage.allocate(640,480); grayBg.allocate(640,480); grayDiff.allocate(640,480); - + blobsManager.normalizePercentage = 0.7; - blobsManager.giveLowestPossibleIDs = true; + blobsManager.giveLowestPossibleIDs = false; blobsManager.maxUndetectedTime = 500; - blobsManager.minDetectedTime = 2000; + blobsManager.minDetectedTime = 500; blobsManager.debugDrawCandidates = true; ofVec3f centre=ofVec3f(ofGetWidth()/2,0,0); @@ -54,12 +54,12 @@ void testApp::setup(){ cam.cacheMatrices(); //stop error messages testpts=new ofVec3f[4]; - + trapDoor=trapdoor(screen2plane(ofVec2f(ofGetWidth(),0)),screen2plane(ofVec2f(ofGetWidth(),ofGetHeight())),ofVec2f(30,30)); updatePlane(); mode=PLAY; - + } @@ -80,7 +80,7 @@ bool testApp::rectsCross(ofRectangle rect1,ofRectangle rect2) { else if (rect2.x newPlayers; float movethresh=10; - for (int i = 0; i < contourFinder.nBlobs; i++){ - //do some bounds checking, size threshold and overlap removal - //in order to translate blobs into players - //attempt to track players - maintain ID no - //attempt to base blobs - //TODO attempt to estimate bounds shape - //project all of this into the 3D space - ofRectangle r=contourFinder.blobs[i].boundingRect; + for(int i=0;i players; trapdoor trapDoor; ofMesh ground; - + ofVec3f* testpts; - + ofTessellator tesselator; ofMesh player; ofPolyline playeroutline; + bird Bird; + }; diff --git a/gaunt01/src/trapdoor.cpp b/gaunt01/src/trapdoor.cpp index d1f436e..e1c37ec 100644 --- a/gaunt01/src/trapdoor.cpp +++ b/gaunt01/src/trapdoor.cpp @@ -2,7 +2,7 @@ trapdoor::trapdoor(ofVec2f _boundTR,ofVec2f _boundBR,ofVec2f _doorSize) { - surround=morphmesh("trapdoor-surround.xml"); + surround=morphmesh("trapdoor-surround.xml"); lid=morphmesh("trapdoor-lid.xml"); if (!surround.isLoaded()||!lid.isLoaded()) printf("problem loading trap door mesh.\n"); @@ -33,7 +33,7 @@ void trapdoor::start(){ float x=mx+((boundTR.x-mx)*u*(1-v))+((boundBR.x-mx)*u*v); float y=boundTR.y+((boundBR.y-boundTR.y)*v); - + startPos(ofVec2f(x,y)); } @@ -44,7 +44,7 @@ void trapdoor::startPos(ofVec2f pos){ doorSpeed=0; opening=false; //for (int i=0;i<4;i++) sounds[i].stop(); - + } vector trapdoor::getCorners(){ @@ -62,6 +62,12 @@ void trapdoor::setBoundingRect(float x,float y, float width,float height){ ofRectangle trapdoor::getBoundingRect(){ return boundingRect; } +ofRectangle trapdoor::getInnerRect() { + return ofRectangle(boundingRect.x+(boundingRect.width/4),boundingRect.y+(boundingRect.height/4),boundingRect.width/2,boundingRect.height/2); +} +void trapdoor::trigger() { + startTime=ofGetElapsedTimef()-10; +} ofVec2f trapdoor::bounds2UV(ofVec2f point){ //returns the 0-1 UV coords of a point on the ground plane relative to its bounds. @@ -73,7 +79,7 @@ ofVec2f trapdoor::bounds2UV(ofVec2f point){ bool trapdoor::checkUpdate(const vector& players) { float segTime=(ofGetElapsedTimef()-startTime); - if (segTime>3) { + if (segTime>10) { doorSpeed=(doorSpeed+((cos(doorAngle*0.0174532925)/ofGetFrameRate())*50))*0.95; doorAngle-=doorSpeed; if (!opening) { @@ -83,7 +89,7 @@ bool trapdoor::checkUpdate(const vector& players) { opening=true; } } - if (segTime>6) { + if (segTime>13) { start(); return true; } diff --git a/gaunt01/src/trapdoor.h b/gaunt01/src/trapdoor.h index 5975498..389e4ad 100644 --- a/gaunt01/src/trapdoor.h +++ b/gaunt01/src/trapdoor.h @@ -30,6 +30,9 @@ class trapdoor void setBoundingRect(float x,float y, float width,float height); ofRectangle getBoundingRect(); + ofRectangle getInnerRect(); + void trigger(); + float getoffset(); protected: private: -- cgit v1.2.3