Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_MEL_KEYFRAME_STRING_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_MBD_MEL_KEYFRAME_STRING_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_euler_angles.h>
00013
00014 #include <string>
00015 #include <sstream>
00016
00017
00018 namespace OpenTissue
00019 {
00020 namespace mbd
00021 {
00022 namespace mel
00023 {
00031 template< typename indirect_body_iterator, typename real_type_>
00032 std::string keyframe_string(indirect_body_iterator begin,indirect_body_iterator end,real_type_ const & time)
00033 {
00034 typedef typename indirect_body_iterator::value_type body_type;
00035 typedef typename body_type::vector3_type vector3_type;
00036 typedef typename body_type::quaternion_type quaternion_type;
00037 typedef typename body_type::matrix3x3_type matrix3x3_type;
00038 typedef typename body_type::real_type real_type;
00039 typedef typename body_type::value_traits value_traits;
00040
00041 std::stringstream stream;
00042
00043 for(indirect_body_iterator body=begin;body!=end;++body)
00044 {
00045
00046 if(!body->is_active())
00047 continue;
00048
00049 vector3_type r;
00050 body->get_position(r);
00051 real_type x = r(0);
00052 real_type y = r(1);
00053 real_type z = r(2);
00054
00055 quaternion_type Q;
00056 body->get_orientation(Q);
00057 matrix3x3_type R(Q);
00058
00059 real_type xangle = value_traits::zero();
00060 real_type yangle = value_traits::zero();
00061 real_type zangle = value_traits::zero();
00062
00063 OpenTissue::math::euler_angles(R,xangle,yangle,zangle);
00064
00065 xangle *= 180.0/value_traits::pi();
00066 yangle *= 180.0/value_traits::pi();
00067 zangle *= 180.0/value_traits::pi();
00068
00069 stream << "move -a -ws -xyz "
00070 << x
00071 << " "
00072 << y
00073 << " "
00074 << z
00075 << " body" << body->get_index()
00076 << ";"
00077 << std::endl;
00078 stream << "rotate -a "
00079 << xangle
00080 << " "
00081 << yangle
00082 << " "
00083 << zangle
00084 << " "
00085 << " body" << body->get_index()
00086 << ";"
00087 << std::endl;
00088 stream << "setKeyframe -t "
00089 << time
00090 << "sec "
00091 << " body" << body->get_index()
00092 << ";"
00093 << std::endl;
00094 }
00095 return stream.str();
00096 }
00097
00098 }
00099 }
00100 }
00101
00102
00103 #endif