00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <fstream>
00035 #include "ani/KeyFrame/PosQuatKey.h"
00036 #include "ani/KeyFrame/KeyFramer.h"
00037 #include "gmtl/Math.h"
00038
00039 namespace ani
00040 {
00041 class KeyFramerExporter
00042 {
00043 public:
00044 KeyFramerExporter()
00045 {
00046 }
00047
00048 void execute( const char* const filename, const ani::KeyFramer<PosQuatKey>& kf )
00049 {
00050 std::ofstream frames_file( filename );
00051
00052 if (!frames_file.good())
00053 {
00054 std::cout << "WARNING: "
00055 << clrRESET
00056 << "couldn't open keyframe file: "
00057 << filename <<"\n"
00058 << std::flush;
00059 return;
00060 }
00061
00062 std::cout << "Writing keyframe(s) to file: "
00063 << filename << "\n" << std::flush;
00064
00065 std::map<float, PosQuatKey >::const_iterator it1 = kf.keys().begin();
00066 for (; it1 != kf.keys().end(); ++it1)
00067 {
00068 const PosQuatKey& key = (*it1).second;
00069 const float& time = key.time();
00070 const gmtl::Vec3f& pos = key.position();
00071 const gmtl::Quatf& quat = key.rotation();
00072 float deg;
00073 gmtl::Vec3f vec;
00074 quat.getRot( deg, vec[0], vec[1], vec[2] );
00075 deg = gmtl::Math::rad2Deg( deg );
00076 frames_file<<time<<" "<<pos[0]<<" "<<pos[1]<<" "
00077 <<pos[2]<<" "<<deg<<" "<<vec[0]<<" "
00078 <<vec[1]<<" "<<vec[2]<<"\n";
00079 }
00080 frames_file.close();
00081 }
00082 };
00083 };