diff options
| author | Tim Redfern <tim@eclectronics.org> | 2012-04-06 18:58:50 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2012-04-06 18:58:50 +0100 |
| commit | 1039fe7789a990eee6e00896cf85bc097e9009dc (patch) | |
| tree | bba490437c25de6572ecfa914a3d0223fda1972b /morpher | |
| parent | adc1fe0182495151eba174f7ab5b99a900e10b5e (diff) | |
working track interpolation
Diffstat (limited to 'morpher')
| -rw-r--r-- | morpher/src/morphmesh.cpp | 47 | ||||
| -rw-r--r-- | morpher/src/morphmesh.h | 62 | ||||
| -rw-r--r-- | morpher/src/testApp.cpp | 1 |
3 files changed, 90 insertions, 20 deletions
diff --git a/morpher/src/morphmesh.cpp b/morpher/src/morphmesh.cpp index 5fc7182..e68e526 100644 --- a/morpher/src/morphmesh.cpp +++ b/morpher/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/morpher/src/morphmesh.h b/morpher/src/morphmesh.h index ca1231c..18463a8 100644 --- a/morpher/src/morphmesh.h +++ b/morpher/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 diff --git a/morpher/src/testApp.cpp b/morpher/src/testApp.cpp index a55ee13..04ecd26 100644 --- a/morpher/src/testApp.cpp +++ b/morpher/src/testApp.cpp @@ -2,7 +2,6 @@ //-------------------------------------------------------------- void testApp::setup(){ - mesh=morphmesh(); //mesh.loadfile("Bird-test1.xml"); if (mesh.loadMesh("Bird-test.xml")) printf("mesh loaded with %i vertices, %i face indices, %i targets\n",mesh.getNumVertices(),mesh.getNumIndices(),mesh.getNumTargets()); else printf("XML not parsed\n"); |
