Hi,

Im trying to build a Ragdoll with Bullet and a osgAnimation skeleton.
Ive got the bullet side working and now trying to update the bones of the osg 
skeleton with the transforms. 

The problem is that I cant seem to get the conversion from worldspace to bone 
space right (every bone in bullet is in worldspace).

I set a bone up like this :



Code:
        
osg::ref_ptr<osgAnimation::Bone> bone = new osgAnimation::Bone;
        parent->insertChild(0, bone.get());
        parent->addChild(createBoneShape(transform.getTrans(), osg::Vec4(1.0f, 
1.0f, 1.0f, 1.0f)));

         osg::ref_ptr<RagdollBoneUpdater> updater = new 
RagdollBoneUpdater(motionState, name);

         bone->setUpdateCallback(updater.get());
         
bone->setMatrixInSkeletonSpace(osg::Matrix::translate(transform.getTrans()) * 
bone->getMatrixInSkeletonSpace());
         bone->setName(name);





And use the updater to get the worldtransform from the btMotionstate:

Code:


class RagdollBoneUpdater : public osgAnimation::UpdateBone
{
public:
         RagdollBoneUpdater(BoneMotionState* motionState, const std::string& 
name) : m_motionState(motionState), UpdateBone(name)
         {

         }

         /** Callback method called by the NodeVisitor when visiting a node.*/
         void operator()(osg::Node* node, osg::NodeVisitor* nv)
         {
         if (nv && nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
         {
                        osgAnimation::Bone* b = 
dynamic_cast<osgAnimation::Bone*>(node);

                        btTransform transform = 
m_motionState->getLocalTransform();
                        const osg::Matrix& matrix = 
Conversion::asOsgMatrix(transform);
                        b->setMatrix(matrix);

                        osgAnimation::Bone* parent = b->getBoneParent();
                        if (parent)
                                        
b->setMatrixInSkeletonSpace(b->getMatrixInBoneSpace() * 
parent->getMatrixInSkeletonSpace());
                        else
                                        
b->setMatrixInSkeletonSpace(b->getMatrixInBoneSpace());
                }
                traverse(node, nv);
         }
private:
         BoneMotionState *m_motionState;
};




I implemented the m_motionState->getLocalTransform() by calculating the offset 
to the parent, but Im no sure if this is the right way:


Code:


         btTransform ModelBone::getLocalTransform(btTransform worldTransform)
         {
                if (m_parent != nullptr)
                {
                        btVector3 parentToChild = 
m_parent->m_worldTransform.getOrigin() - worldTransform.getOrigin() ;
                        btQuaternion parentToChildQuat = 
m_parent->m_worldTransform.getRotation() * 
worldTransform.getRotation().inverse();
                        return btTransform(parentToChildQuat, parentToChild);
                }
                else
                        return worldTransform;
         }





Note that the transforms look right, when the ragdoll doesnt move, so initial 
transforms are right, it seems to be the rotations which are off.

Hope anyone can help.

Cheers,
Max

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=59053#59053





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to