Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

c:/home/kevn/src/animaniac/ani/KeyFrame/process/KeySetSmoother.h

Go to the documentation of this file.
00001 #include <gmtl/Math.h>
00002 #include "ani/KeyFrame/PosQuatKey.h"
00003 #include "ani/KeyFrame/KeyFramer.h"
00004 
00005 float getDist( const ani::PosQuatKey& key1, const ani::PosQuatKey& key2 )     
00006 {
00007    kev::Vec3<float> vec = key1.position() - key2.position();
00008    return vec.length();
00009 }
00010 
00011 
00012 float getTotalDist( ani::KeyFramer<ani::PosQuatKey>& keyFramer )
00013 {
00014    std::map<float, ani::PosQuatKey>::iterator it1 = keyFramer.keys().begin();
00015    std::map<float, ani::PosQuatKey>::iterator it2 = it1;
00016    ++it2;
00017    float total_dist = 0.0f;
00018    for (; it2 != keyFramer.keys().end(); ++it1, ++it2)
00019    {
00020       ani::PosQuatKey& key1 = (*it1).second;
00021       ani::PosQuatKey& key2 = (*it2).second;
00022       total_dist += getDist( key1, key2 );
00023    }
00024    return total_dist;
00025 }
00026 
00027 
00028 void output( const ani::PosQuatKey& key )
00029 {
00030    float w, x, y, z;
00031    gmtl::getRot( key.rotation(), w, x, y, z );
00032    std::cout << "KEY "<<key.time()<<": "<<key.position()[0]<<", \t"<<key.position()[1]<<", \t"<<key.position()[2]<<", |#| "<<gmtl::Math::rad2Deg( w )<<", "<<x<<", "<<y<<", "<<z<<"\n"<<std::flush;
00033 }
00034 
00035 void smooth( ani::KeyFramer<ani::PosQuatKey>& keyFramer, float length )
00036 {
00037    float total_dist = getTotalDist( keyFramer );
00038    std::map<float, ani::PosQuatKey> workspace = keyFramer.keys();
00039    keyFramer.clear();
00040    
00041    cout<<keyFramer.keys().size()<<" "<<workspace.size()<<"\n"<<flush;
00042    
00043    float total_time_over_dist = length / total_dist;
00044    
00045    std::map<float, ani::PosQuatKey>::const_iterator it1 = workspace.begin();
00046    std::map<float, ani::PosQuatKey>::const_iterator it2 = workspace.begin();
00047    ++it2;
00048    float time_so_far = 0.0f;
00049    ani::PosQuatKey newKey = (*it1).second;
00050    newKey.time() = time_so_far;
00051    keyFramer.addkey( newKey );
00052    for (; it2 != workspace.end(); )
00053    {
00054       const ani::PosQuatKey& key1 = (*it1).second;
00055       const ani::PosQuatKey& key2 = (*it2).second;
00056       float dist = getDist( key1, key2 );
00057       float time = total_time_over_dist * dist;
00058    
00059       ani::PosQuatKey newKey1 = key1;
00060       ani::PosQuatKey newKey2 = key2;
00061       
00062       newKey1.time() = time_so_far;
00063       newKey2.time() = time_so_far + time;
00064       
00065       time_so_far += time;
00066       
00067       keyFramer.addkey( newKey2 );
00068       output( newKey1 );
00069       ++it1;
00070       ++it2;
00071    }
00072 }

Generated on Wed Jun 12 01:54:02 2002 for Animaniac by doxygen1.2.15