Bone position during animation [SOLVED]

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
User avatar
Senzin
Halfling
Posts: 57
Joined: Wed Apr 06, 2011 8:54 pm
x 3

Bone position during animation [SOLVED]

Post 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?
Last edited by Senzin on Tue Jun 07, 2011 5:02 am, edited 1 time in total.
User avatar
Jabberwocky
OGRE Moderator
OGRE Moderator
Posts: 2819
Joined: Mon Mar 05, 2007 11:17 pm
Location: Canada
x 218
Contact:

Re: Bone position during animation

Post by Jabberwocky »

That code looks correct to me.
Maybe there's an error somewhere else in the code you didn't post.
Image
User avatar
Senzin
Halfling
Posts: 57
Joined: Wed Apr 06, 2011 8:54 pm
x 3

Re: Bone position during animation

Post 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!
User avatar
Jabberwocky
OGRE Moderator
OGRE Moderator
Posts: 2819
Joined: Mon Mar 05, 2007 11:17 pm
Location: Canada
x 218
Contact:

Re: Bone position during animation [SOLVED]

Post by Jabberwocky »

Cool, glad you got it worked out.
And I always appreciate it when people post the solution they found to their problem.
Image
aspiringprogrammer
Gnoblar
Posts: 10
Joined: Tue Jan 24, 2012 11:07 pm

Re: Bone position during animation [SOLVED]

Post 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
Fedyakin
Halfling
Posts: 43
Joined: Thu Jul 14, 2005 6:48 pm
Contact:

Re: Bone position during animation [SOLVED]

Post 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...
aspiringprogrammer
Gnoblar
Posts: 10
Joined: Tue Jan 24, 2012 11:07 pm

Re: Bone position during animation [SOLVED]

Post by aspiringprogrammer »

I tried your solution, it still doesn't seem to be updating the position during the skeletal animation...
sdong21
Gnoblar
Posts: 7
Joined: Sat Oct 04, 2014 1:48 pm

Re: Bone position during animation [SOLVED]

Post 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...
Post Reply