diff options
Diffstat (limited to 'morpher/src')
| -rw-r--r-- | morpher/src/morphmesh.cpp | 79 | ||||
| -rw-r--r-- | morpher/src/morphmesh.h | 7 | ||||
| -rw-r--r-- | morpher/src/testApp.cpp | 67 | ||||
| -rw-r--r-- | morpher/src/testApp.h | 9 |
4 files changed, 132 insertions, 30 deletions
diff --git a/morpher/src/morphmesh.cpp b/morpher/src/morphmesh.cpp index 63d58f7..9ab414a 100644 --- a/morpher/src/morphmesh.cpp +++ b/morpher/src/morphmesh.cpp @@ -26,33 +26,73 @@ sequence::sequence(string _name,float _length,float _fadeinTime,float _fadeoutTi { name=_name; length=_length; - startTime=0.0; - stopTime=0.0; + startTime=0; + stopTime=0; fadeinTime=_fadeinTime; fadeoutTime=_fadeoutTime; active=false; } +//----------------------------------------------------- +// stopTime & startTime are absolute +// +// all other time markers are relative to the sequence +// +// +void sequence::reset(){ + active=false; + fadeinTime=-1; + fadeoutTime=-1; + startTime=0; + stopTime=0; +} void sequence::start(){ + reset(); active=true; startTime=ofGetElapsedTimef(); } -void sequence::stop(){ +void sequence::startAt(float time){ + reset(); + active=true; + startTime=ofGetElapsedTimef()+time; +} +void sequence::stopAt(float time){ + reset(); + active=true; + stopTime=ofGetElapsedTimef()+time; +} +void sequence::fadeout(float time){ + if(active==true) { + reset(); + active=true; + startTime=ofGetElapsedTimef(); + fadeoutTime=0; + stopTime=ofGetElapsedTimef()+time; + } +} +void sequence::fadein(float time){ + reset(); active=true; + fadeinTime=time; + startTime=ofGetElapsedTimef(); +} +void sequence::stop(){ + reset(); } vector<morphWeight> sequence::evaluate(float time){ - float seqtime=time-startTime; - float fadeWeight=(seqtime<fadeinTime?seqtime/fadeinTime:seqtime>stopTime-fadeoutTime&&stopTime>0&&fadeoutTime>0?(seqtime-fadeoutTime)/(stopTime-fadeoutTime):1.0); - vector<morphWeight> weights; - map<string,track>::iterator i; - for( i = tracks.begin(); i != tracks.end(); i++ ) { - weights.push_back(morphWeight(i->first,(i->second.evaluate(seqtime))*fadeWeight)); - } - return weights; + float now=ofGetElapsedTimef(); + float seqtime=time-startTime; + float looptime=fmod(seqtime,length); + float fadeWeight=(seqtime<fadeinTime?seqtime/fadeinTime:seqtime>fadeoutTime&&fadeoutTime>-1?1.0-(seqtime/(stopTime-startTime)):1.0); + vector<morphWeight> weights; + map<string,track>::iterator i; + for( i = tracks.begin(); i != tracks.end(); i++ ) { + weights.push_back(morphWeight(i->first,(i->second.evaluate(looptime))*fadeWeight)); + } + return weights; } - morphmesh::morphmesh() { loaded=false; @@ -96,8 +136,6 @@ void morphmesh::draw(string target){ ofMesh::draw(); } void morphmesh::draw(const vector<morphWeight>& weights){ - morphWeight mw[2]; - for (int i=0;i<weights.size();i++) mw[i]=weights[i]; clearVertices(); //normalise weights float totalWeights=0; @@ -122,10 +160,8 @@ void morphmesh::drawAnimated(){ map<string,sequence>::iterator i; for( i = sequences.begin(); i != sequences.end(); i++ ) { if (i->second.active) { - vector<morphWeight> newWeights=i->second.evaluate(fmod(time-i->second.startTime,i->second.length)); - int nnw= newWeights.size(); //test + vector<morphWeight> newWeights=i->second.evaluate(time); weights.insert(weights.end(),newWeights.begin(),newWeights.end()); - int nw= weights.size(); //test if (i->second.stopTime>0&&time>i->second.stopTime) i->second.active=false; } } @@ -179,6 +215,15 @@ bool morphmesh::loadSeqs(string filename){ XML.popTag(); } sequences[seqnames[i]]=seq; + + printf("testing sequence: %s\n",seqnames[i].c_str()); + for (int k=0;k<targnames.size();k++) { + printf("track: %s\n",targnames[k].c_str()); + for (float l=-.2;l<=2.2;l+=0.1) { + printf("%f : %f\n",l,sequences[seqnames[i]].tracks[targnames[k]].evaluate(l)); + } + } + loaded=true; XML.popTag(); } diff --git a/morpher/src/morphmesh.h b/morpher/src/morphmesh.h index 5293f9d..bc22c3d 100644 --- a/morpher/src/morphmesh.h +++ b/morpher/src/morphmesh.h @@ -67,12 +67,17 @@ class sequence //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(string _name="",float _length=1.0,float _fadeinTime=0.0,float _fadeoutTime=0.0); + sequence(string _name="",float _length=1.0,float _fadeinTime=-2.0,float _fadeoutTime=-2.0); string name; map<string,track> tracks; vector<morphWeight> evaluate(float time); + void reset(); void start(); void stop(); + void startAt(float time); + void stopAt(float time); + void fadein(float time); + void fadeout(float time); float length; float startTime; float stopTime; diff --git a/morpher/src/testApp.cpp b/morpher/src/testApp.cpp index 31dffb4..97d57db 100644 --- a/morpher/src/testApp.cpp +++ b/morpher/src/testApp.cpp @@ -3,17 +3,20 @@ //-------------------------------------------------------------- void testApp::setup(){ //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()); + if (mesh.loadMesh("Bird-poses.xml")) printf("mesh loaded with %i vertices, %i face indices, %i targets\n",mesh.getNumVertices(),mesh.getNumIndices(),mesh.getNumTargets()); else printf("mesh XML file not parsed\n"); - if (mesh.loadSeqs("Bird-anim-test.xml")) printf("animation loaded with %i sequences\n",mesh.getNumSequences()); + if (mesh.loadSeqs("Bird-anim.xml")) printf("animation loaded with %i sequences\n",mesh.getNumSequences()); else printf("animation XML file not parsed\n"); - mesh.sequences["flap"].start(); - - texture.loadImage("texture2.jpg"); + mesh.sequences["hover"].start(); + state=HOVER; + currentseq="attack"; + + texture.loadImage("TextureBird.jpg"); - xr=yr=0; + xr=90; + yr=0; xo=yo=0; glEnable(GL_DEPTH_TEST); @@ -43,7 +46,7 @@ void testApp::draw(){ ofRotate(xr,0,1,0); ofRotate(yr,1,0,0); ofRotate(180,1,0,0); - ofScale(2.0,2.0,2.0); + ofScale(1.0,1.0,1.0); //mesh.draw(testweight); mesh.drawAnimated(); ofPopMatrix(); @@ -54,14 +57,54 @@ void testApp::draw(){ } //-------------------------------------------------------------- +/* + void start(); + void stop(); + void startAt(float time); + void fadeout(float time); +*/ void testApp::keyPressed(int key){ - + switch (key){ - case 'a': - //if (movieExporter.isRecording()) movieExporter.stop(); - //else movieExporter.record(); + case '1': + if (currentseq!="hover") { + //mesh.sequences["trans_flaphover"].stopAt(0.3); + //mesh.sequences["trans_flaphover"].start(); + mesh.sequences[currentseq].fadeout(0.5); + mesh.sequences["hover"].fadein(0.5); + currentseq="hover"; + } + break; + case '2': + if (currentseq!="flap") { + //mesh.sequences["trans_hoverflap"].stopAt(0.3); + //mesh.sequences["trans_hoverflap"].start(); + mesh.sequences[currentseq].fadeout(0.5); + mesh.sequences["flap"].fadein(0.5); + currentseq="flap"; + } + break; + case '3': + if (currentseq!="swoop") { + //mesh.sequences["trans_hoverflap"].stopAt(0.3); + //mesh.sequences["trans_hoverflap"].start(); + mesh.sequences[currentseq].fadeout(0.25); + mesh.sequences["swoop_trans"].fadein(0.25); + mesh.sequences["swoop_trans"].stopTime=ofGetElapsedTimef()+1.0; + mesh.sequences["swoop"].startAt(1.0); + currentseq="swoop"; + } break; - case 'z': + case '4': + if (currentseq!="attack") { + //mesh.sequences["trans_hoverflap"].stopAt(0.3); + //mesh.sequences["trans_hoverflap"].start(); + mesh.sequences[currentseq].fadeout(0.2); + mesh.sequences["attack_trans"].fadein(0.2); + mesh.sequences["attack_trans"].stopTime=ofGetElapsedTimef()+0.6; + mesh.sequences["attack"].startAt(0.6); + currentseq="attack"; + } break; } } diff --git a/morpher/src/testApp.h b/morpher/src/testApp.h index c0b665e..0b528ae 100644 --- a/morpher/src/testApp.h +++ b/morpher/src/testApp.h @@ -8,6 +8,11 @@ //#include "ofxMovieExporter.h" +#define HOVER 1 +#define TRANS_HOVERFLY 2 +#define FLAP 3 +#define TRANS_FLYHOVER 4 + class testApp : public ofBaseApp{ public: @@ -33,5 +38,9 @@ class testApp : public ofBaseApp{ int yo,xo; //Apex::ofxMovieExporter movieExporter; + + int state; + + string currentseq; }; |
