From 1039fe7789a990eee6e00896cf85bc097e9009dc Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Fri, 6 Apr 2012 18:58:50 +0100 Subject: working track interpolation --- gaunt01/src/morphmesh.cpp | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'gaunt01/src/morphmesh.cpp') 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(0.0,2.0) ); + testrack.keys.insert( pair(1.0,4.0) ); + testrack.keys.insert( pair(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 >::iterator it=morphs.begin(); for ( int i=0;isecond); + draw(it->first); +} +void morphmesh::draw(string target){ + clearVertices(); + addVertices(morphs[target]); ofMesh::draw(); } void morphmesh::draw(const vector& targets, const vector& weights){ -- cgit v1.2.3