# Ragdoll physics - bones transformation by rigid bodies

This topic is 2526 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello there,

I am trying to create a rag-doll physics to my skinned meshes. And, I meet some problems... Hope you can help me.

Here is how I setup rigid bodies for rag-doll:

 final_matrix = parentJoint->final_matrix; // this is bone matrix final_matrix.SetInvert(final_matrix); // invert it final_matrix = model_transformation * final_matrix; // multiplay by model transformation rigid_body->setRotation(final_matrix); // it's 3x3 matrix rigid_body->setPosition(…) // I get this by bone_pos in world + bone_length * 0.5 

all rigid bodies is in place with correct rotation (according current animation's bones)

Now the question is how to convert rigid body transformation back to joints? As I understood that is how rag doll works: skinned mesh joints are controlled by rigid bodies which are connected with physics joints. My animation code is like this:

 transform.setRotationRadians( rotVec ); transform.setTranslation( transVec ); Matrix relativeFinal( pJoint->relative ); // joint's relative matrix relativeFinal.postMultiply( transform ); if ( pJoint->parent == -1 ) pJoint->final.set( relativeFinal.getMatrix()); else { pJoint->final.set( m_pJoints[pJoint->parent].final.getMatrix()); // get parent's joint final matrix pJoint->final.postMultiply( relativeFinal ); // and multiplay it by current animation keys (translates and rotations) } 

I have these from rigid body:
rigid_body->GetRotationMatrix()
rigid_body->GetPosition()

and I guess they should be converted to bone space (because they are in world space), right?

and what about apply to bone, should this be enough: pJoint->final.set(correct_matrix_from_rigid_body); ?

What should I do with bones which doesn't have rigid body? Should they still get bone matrix from parent?

##### Share on other sites

and I guess they should be converted to bone space (because they are in world space), right?

Yup.

and what about apply to bone, should this be enough: pJoint->final.set(correct_matrix_from_rigid_body); ?

Yup.

What should I do with bones which doesn't have rigid body? Should they still get bone matrix from parent?

If it's not going to get a transform from physics, you might as well get the transform from somewhere else (i.e. whatever the anim system last returned, or the bind pose, or whatever seems best in your case).

##### Share on other sites
Oh, I just forgot to replay to this thread - yesterday, I succeeded to implement rag-dolls with skinned meshes !

Anyway, RobTheBloke - thank you! All your answers are correct, so maybe these will be helpful to someone else in the future.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633767
• Total Posts
3013734
×