Hi,

For those who need to know how to do ...


Code:

std::map\std::string,osg::Matrix> desiredMatrixs;
                osg::ref_ptr\osgAnimation::Animation> anim = 
_AnimationManager->getAnimation(name);
                if(anim.valid()){

                        osgAnimation::ChannelList channelList = 
anim->getChannels();

                        for(int i=0;i\_boneChains_index.size();i++)
                        {
                                std::string targetName = 
_boneChains_index[i].back().first;
                                std::string actualBoneName = targetName;
                                osg::Matrix desiredMatrix;

                                osg::ref_ptr\osgAnimation::Bone> actualBone = 
_AnimationManager->getSkeletonBone(actualBoneName);
                                while(actualBone->getParents().size()>0)
                                {
                                        float rotateX, rotateY, rotateZ;
                                        osg::Vec3 pos;
                                        for(int j=0;j\channelList.size();j++)
                                        {       
                                                osgAnimation::Channel* channel 
=  channelList[j];
                                                
if(!channel->getTargetName().compare(actualBoneName))
                                                {
                                                        
channel->update(channel->getStartTime(),1.0,1.0);
                                                        
if(!channel->getName().compare("translate")){
                                                                
osg::ref_ptr\osgAnimation::Vec3Target> posTarget = 
                                                                        
dynamic_cast\osgAnimation::Vec3Target*>(channel->getTarget());
                                                                pos = 
posTarget->getValue();
                                                        }
                                                        else 
if(!channel->getName().compare("rotateX")){
                                                                
osg::ref_ptr\osgAnimation::FloatTarget> xTarget = 
                                                                        
dynamic_cast\osgAnimation::FloatTarget*>(channel->getTarget());
                                                                rotateX = 
xTarget->getValue();
                                                        }
                                                        else 
if(!channel->getName().compare("rotateY")){
                                                                
osg::ref_ptr\osgAnimation::FloatTarget> yTarget = 
                                                                        
dynamic_cast\osgAnimation::FloatTarget*>(channel->getTarget());
                                                                rotateY = 
yTarget->getValue();
                                                        }
                                                        else 
if(!channel->getName().compare("rotateZ")){
                                                                
osg::ref_ptr\osgAnimation::FloatTarget> zTarget = 
                                                                        
dynamic_cast\osgAnimation::FloatTarget*>(channel->getTarget());
                                                                rotateZ = 
zTarget->getValue();
                                                                
                                                                break;
                                                        }
                                                }
                                        }
                                        osg::Quat rot(rotateZ,osg::Vec3(0,0,1), 
rotateY,osg::Vec3(0,1,0), rotateX,osg::Vec3(1,0,0));
                                        osg::Matrix 
mat(osg::Matrix::rotate(rot));
                                        mat.setTrans(pos);
                                        desiredMatrix.postMult(mat);

                                        actualBoneName = 
actualBone->getParent(0)->getName();
                                        actualBone = 
_AnimationManager->getSkeletonBone(actualBoneName);
                                        if(!actualBone.valid())
                                                break;
                                }
                                
                                desiredMatrixs[targetName] = desiredMatrix;

                        }
                }
                else
                        return;



Thank you!

Cheers,
Aitor

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





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to