Page 1 of 1
Bone position during animation [SOLVED]
Posted: Sun Jun 05, 2011 8:34 am
by Senzin
I know there are many posts on this--I've spent the last hour looking through them--but none of them seem have a working solution, or are 5 years old and no longer seem to work.
I want to get the position of a bone undergoing animation. It will be used as the starting position for a special effect that will go flying to some other position which won't be attached to the skeleton or the entity's scene node in any way.
At the moment I have this:
Code: Select all
Bone* bone = mEntity->getSkeleton()->getBone("Bone_R.006");
Vector3 emitter = mNode->_getDerivedPosition() + mNode->_getDerivedOrientation() * bone->_getDerivedPosition();
If I have animation disabled, then this correctly gives me the position of the bone, as indicated by an object I place there to see it visually. However, if I let the animation run, the object's position doesn't change (yes I'm running the above code and updating the object's position every frame). So it seems this above code always returns the initial position of the bone, not the position resulting form animation. Or maybe I just don't know what I'm doing (seems likely).
Does anybody know how to do this?
Re: Bone position during animation
Posted: Mon Jun 06, 2011 6:37 am
by Jabberwocky
That code looks correct to me.
Maybe there's an error somewhere else in the code you didn't post.
Re: Bone position during animation
Posted: Tue Jun 07, 2011 5:00 am
by Senzin
I had decided early on that that code doesn't return the bone position during animation because that made since with my early results. However when you said that it looked right, making my earlier conclusion wrong, I took another look at it and discovered the error in my earlier experiments. And yes, as you said, there was an error somewhere else in the code that I didn't post.
The problem was that I was using an offset from the bone position but wasn't multiplying it by the bone's orientation, so though the bone was rotating, that wasn't being applied to the resulting position. Now I have this...
Code: Select all
Bone* bone = mEntity->getSkeleton()->getBone("Bone_R.006");
Vector3 emitter = mNode->_getDerivedPosition()
+ mNode->_getDerivedOrientation() * (bone->_getDerivedPosition() + bone->_getDerivedOrientation() * offset);
Thanks for the help!
Re: Bone position during animation [SOLVED]
Posted: Tue Jun 07, 2011 5:34 am
by Jabberwocky
Cool, glad you got it worked out.
And I always appreciate it when people post the solution they found to their problem.
Re: Bone position during animation [SOLVED]
Posted: Thu Mar 15, 2012 8:35 pm
by aspiringprogrammer
I'm having this same problem, using this code above that is supposed to "work" isn't working... Can anyone help me with returning a bone position during animation so I can hook up my collision spheres to the fists of my mesh
Re: Bone position during animation [SOLVED]
Posted: Fri Mar 16, 2012 10:39 pm
by Fedyakin
I had to solve this to set the initial position of our rag dolls. Here is how I got the location in world space of an animated bone.
Code: Select all
//=============================================================================
const Ogre::Vector3 PhysicsRagdoll::getBoneWorldPosition( const Ogre::Bone &aBone ) const
{
const Ogre::Vector3 skeletonSpacePos = aBone._getDerivedPosition();
return getOwner()->getSceneNode().convertLocalToWorldPosition(skeletonSpacePos);
}
//=============================================================================
const Ogre::Quaternion PhysicsRagdoll::getBoneWorldOrientation( const Ogre::Bone &aBone ) const
{
const Ogre::Quaternion skeletonSpaceOrient = aBone._getDerivedOrientation();
return getOwner()->getSceneNode().convertLocalToWorldOrientation(skeletonSpaceOrient);
}
The getOwner()->getSceneNode() snippet returns the scene node that the skeleton is attached to. I hope that helps...
Re: Bone position during animation [SOLVED]
Posted: Fri Mar 23, 2012 3:44 am
by aspiringprogrammer
I tried your solution, it still doesn't seem to be updating the position during the skeletal animation...
Re: Bone position during animation [SOLVED]
Posted: Thu Aug 04, 2016 2:52 am
by sdong21
I have tested, this works.
Fedyakin wrote:I had to solve this to set the initial position of our rag dolls. Here is how I got the location in world space of an animated bone.
Code: Select all
//=============================================================================
const Ogre::Vector3 PhysicsRagdoll::getBoneWorldPosition( const Ogre::Bone &aBone ) const
{
const Ogre::Vector3 skeletonSpacePos = aBone._getDerivedPosition();
return getOwner()->getSceneNode().convertLocalToWorldPosition(skeletonSpacePos);
}
//=============================================================================
const Ogre::Quaternion PhysicsRagdoll::getBoneWorldOrientation( const Ogre::Bone &aBone ) const
{
const Ogre::Quaternion skeletonSpaceOrient = aBone._getDerivedOrientation();
return getOwner()->getSceneNode().convertLocalToWorldOrientation(skeletonSpaceOrient);
}
The getOwner()->getSceneNode() snippet returns the scene node that the skeleton is attached to. I hope that helps...