Jump to content
  • Advertisement
Sign in to follow this  
Eter

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
Share on other sites
Oh, I just forgot to replay to this thread - yesterday, I succeeded to implement rag-dolls with skinned meshes ! smile.png

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!