diff options
Diffstat (limited to 'gaunt01')
| -rw-r--r-- | gaunt01/src/bird.cpp | 9 | ||||
| -rw-r--r-- | gaunt01/src/morphmesh.cpp | 47 | ||||
| -rw-r--r-- | gaunt01/src/morphmesh.h | 62 |
3 files changed, 99 insertions, 19 deletions
diff --git a/gaunt01/src/bird.cpp b/gaunt01/src/bird.cpp index 388d7af..9418b65 100644 --- a/gaunt01/src/bird.cpp +++ b/gaunt01/src/bird.cpp @@ -1,5 +1,14 @@ #include "bird.h" +/* +keep track of the high-level properties of the bird here + +activate and control sequences of targets in the morphmesh + +finally drawAnimated() + +*/ + bird::bird() { model.loadMesh("Bird-test.xml"); diff --git a/gaunt01/src/morphmesh.cpp b/gaunt01/src/morphmesh.cpp index 5fc7182..e68e526 100644 --- a/gaunt01/src/morphmesh.cpp +++ b/gaunt01/src/morphmesh.cpp @@ -1,8 +1,44 @@ #include "morphmesh.h" +sequence::sequence() +{ +} + +track::track() +{ +} + +/* +void track::addKey(float time,float weight) +{ + keys.push_back(key(time,weight)); +} +*/ + +float track::evaluate(float time) +{ + //interpolate key track + if (time<=keys.begin()->first) return keys.begin()->second; + if (time>keys.rbegin()->first) return keys.rbegin()->second; + multimap< float,float >::iterator key2=keys.upper_bound( time ); + multimap< float,float >::iterator key1=key2--; + float interval=key2->first-key1->first; + return (((1.0-((key2->first-time)/interval))*key2->second)+((1.0-((time-key1->first)/interval))*key1->second)); +} + morphmesh::morphmesh() { loaded=false; + /* + //testing track function + track testrack; + testrack.keys.insert( pair<float,float>(0.0,2.0) ); + testrack.keys.insert( pair<float,float>(1.0,4.0) ); + testrack.keys.insert( pair<float,float>(0.5,10.0) ); + for (float f=-0.4;f<1.4;f+=0.1) { + printf("%f : %f\n",f,testrack.evaluate(f)); + } + */ } morphmesh::morphmesh(string filename) @@ -11,10 +47,6 @@ morphmesh::morphmesh(string filename) loadMesh(filename); } -morphmesh::~morphmesh() -{ - //dtor -} int morphmesh::getNumTargets(){ return morphs.size(); @@ -23,10 +55,13 @@ void morphmesh::draw() { draw(0); } void morphmesh::draw(int target){ - clearVertices(); map<string,vector<ofVec3f> >::iterator it=morphs.begin(); for ( int i=0;i<target;i++ ) it++; - addVertices(it->second); + draw(it->first); +} +void morphmesh::draw(string target){ + clearVertices(); + addVertices(morphs[target]); ofMesh::draw(); } void morphmesh::draw(const vector<string>& targets, const vector<float>& weights){ diff --git a/gaunt01/src/morphmesh.h b/gaunt01/src/morphmesh.h index ca1231c..18463a8 100644 --- a/gaunt01/src/morphmesh.h +++ b/gaunt01/src/morphmesh.h @@ -34,15 +34,48 @@ behaviours are triggered by things like spotting people or avoiding the wall. These could be parameterised on top of the rest? */ +struct morphWeight +{ + string name; + float weight; +}; +struct key +{ + key(float _val,float _time) {value=_val;time=_time;} + float value; + float time; +}; + +class track +{ + //a single morph channel. keys a single morph target within a single sequence + public: + track(); + string target; + multimap<float,float> keys; + float evaluate(float time); + +}; class sequence { - //stores a morph sequence: an animation cycle or transition + //tracks a morph sequence: an animation cycle or transition + //targets are named keys + //animation consists of time,value pairs for any number of named tracks + //the sequence knows the time (absolute seconds) it was started + //sequencer keeps track of playback time and start/stop of sequences + //tracks is a map of time,value pairs - built in interpolation via multimap public: sequence(); - virtual ~sequence(); - + map<string,track> tracks; + vector<morphWeight> evaluate(); + private: + float length; + float startTime; + float fadeinTime; + float fadeoutTime; + bool loop,active; }; @@ -50,18 +83,21 @@ class morphmesh : public ofMesh { public: morphmesh(); - morphmesh(string filename); - virtual ~morphmesh(); - bool loadMesh(string filename); - bool isLoaded(); - void draw(); - void draw(int target); - void draw(const vector<string>& targets, const vector<float>& weights); - int getNumTargets(); + morphmesh(string filename); + bool loadMesh(string filename); + bool loadSeqs(string filename); + bool isLoaded(); + void draw(); + void draw(int target); + void draw(string target); + void draw(const vector<string>& targets, const vector<float>& weights); + void drawAnimated(); //evaluates all active sequences via iterator and builds a collection of targets and weights for above + int getNumTargets(); + map< string,sequence > sequences; //public for direct access protected: private: - map< string,vector<ofVec3f> > morphs; - bool loaded; + map< string,vector<ofVec3f> > morphs; + bool loaded; }; #endif // MORPHMESH_H |
