[osg-users] osg::CoordinateSystemNode
Alex Chen
alex.xl.zhou at gmail.com
Tue Apr 26 10:13:59 PDT 2016
Hi all,
I get the same problem with BVH plug in when using CMU dataset.
Below is my minor fix to the code and it seems to work for several motions I loaded.
File attached.
Main changes:
typedef std::pair<osg::ref_ptr<osgAnimation::Bone>, std::pair<int, std::string> > JointNode;
void alterChannel( std::string name, std::pair<int, std::string>& p )
{
int& value = p.first;
std::string& str = p.second;
if ( name=="Xposition" ) value |= 0x01;
else if ( name=="Yposition" ) value |= 0x02;
else if ( name=="Zposition" ) value |= 0x04;
else if ( name=="Zrotation" ) {value |= 0x08; str.push_back('Z');}
else if ( name=="Xrotation" ) {value |= 0x10; str.push_back('X');}
else if ( name=="Yrotation" ) {value |= 0x20; str.push_back('Y');}
}
void setKeyframe( osgDB::Input& fr, int ch, const std::string& order, double time,
osgAnimation::Vec3KeyframeContainer* posKey,
osgAnimation::QuatKeyframeContainer* rotKey )
{
if ( ch&0x07 && posKey ) // Position keyframe
{
float keyValue[3] = { 0.0f };
if ( ch&0x01 ) fr.readSequence( keyValue[0] );
if ( ch&0x02 ) fr.readSequence( keyValue[1] );
if ( ch&0x04 ) fr.readSequence( keyValue[2] );
osg::Vec3 vec( keyValue[0], keyValue[1], keyValue[2] );
posKey->push_back( osgAnimation::Vec3Keyframe(time, vec) );
}
if ( ch&0x38 && rotKey ) // Rotation keyframe
{
osg::Matrix rotMat;
float keyValue[3] = { 0.0f };
for(int i = 0; i < order.size(); ++i) {
char f = order[i];
if(f == 'X') {
if ( ch&0x10 ) fr.readSequence( keyValue[0] );
rotMat = osg::Matrix::rotate(osg::DegreesToRadians(keyValue[0]), osg::Vec3(1.0,0.0,0.0)) * rotMat;
}
else if(f == 'Y') {
if ( ch&0x20 ) fr.readSequence( keyValue[1] );
rotMat = osg::Matrix::rotate(osg::DegreesToRadians(keyValue[1]), osg::Vec3(0.0,1.0,0.0)) * rotMat;
}
else if(f == 'Z') {
if ( ch&0x08 ) fr.readSequence( keyValue[2] );
rotMat = osg::Matrix::rotate(osg::DegreesToRadians(keyValue[2]), osg::Vec3(0.0,0.0,1.0)) * rotMat;
}
}
osg::Quat quat = rotMat.getRotate();
rotKey->push_back( osgAnimation::QuatKeyframe(time, quat) );
}
}
There are a few other places that can be seen by compared files.
Cheers,
Alex
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66968#66968
Attachments:
http://forum.openscenegraph.org//files/readerwriterbvh_198.cpp
More information about the osg-users
mailing list