simulating ragdoll with DirectX

mickey
Posts: 107
Joined: Fri Sep 19, 2008 6:08 pm

simulating ragdoll with DirectX

Post by mickey »

Hi

Hope someone can help me here.

I seem to have a hard time trying to simulate the rag doll with my DX model. Here's a screen shot.

Image

Before I update all the frame matrices, that is, combining the parent to child relationship to a combined matrix for rendering, I do this:

Code: Select all

// declare a few variables
D3DXQUATERNION  quat;
float yaw, pitch, roll;

// extract transformation from rigid bodies
btTransform pelvis = m_bodies[BODYPART_PELVIS]->getWorldTransform();
btTransform leftUpperLeg  = m_bodies[BODYPART_LEFT_UPPER_LEG]->getWorldTransform();

// apply transformation to the frame's transformation matrix
D3DXMatrixTransformation(  &((Frame*)m_pMesh->GetFrame( "RootFrame" ))->TransformationMatrix, NULL, NULL, NULL, 	NULL, &quat, &ConvertVector(pelvis.getOrigin()) );

// the whole transformation is only applied to the root frame, the rest i only apply orientations
leftUpperLeg.getBasis().getEulerZYX( yaw, pitch, roll );
D3DXMatrixRotationYawPitchRoll( &((Frame*)m_pMesh->GetFrame( "ThighLeftBone" ))->TransformationMatrix, yaw,pitch, roll );
But I don't seem to get the orientation right - you can see it on the screen shots.

One thing I tried is to copy the whole rigid body transformation to the left leg - and you can see the result, the leg apparently drifted apart.

I think my questions are, can I just copy the btQuaternion or extract yaw, pitch, roll just what I did above and copy it over to DX data structures and use it for transformation and expect it to work?

Do I need to apply any offsets?

I am expecting at least the leg should be aligned with the right body but is not. The rootFrame/Pelvis seems to be aligned correctly.

Please let me know if you need additional information.
mickey
Posts: 107
Joined: Fri Sep 19, 2008 6:08 pm

Re: simulating ragdoll with DirectX

Post by mickey »

I think I'm getting close. Would anyone tell me for now how I can get the orientation of the btConeTwistConstraint as quaternion?

So I can use DirectX quaternion's data structure and create a rotation matrix with it.

With the hinge constraint I simply do this:

float rightKneeHingleAngle = ((btHingeConstraint*)m_joints[JOINT_RIGHT_KNEE])->getHingeAngle();

Could not find anything similar with the btConeTwistConstraint.

Thanks.
mickey
Posts: 107
Joined: Fri Sep 19, 2008 6:08 pm

Re: simulating ragdoll with DirectX

Post by mickey »

anyone? I need to get the proper orientation so I can orient the rigid body similar to how I orent the hinge.

Thanks.
logic7error
Posts: 4
Joined: Tue Oct 21, 2008 12:59 am

Re: simulating ragdoll with DirectX

Post by logic7error »

Hey mickey,

Not sure if you are still having problems with this but we ran into a few problems when we were trying to match the physic's ragdoll to our skinned mesh.

The first was that the collision objects' (capsules) world transforms did not match up to the bones' transform in the character's neutral position. We created a local transform that would help generate the bone's world transform from the collision object's world transform. For example: We just add the ragdoll to the simulation. After we step the simulation and start to iterate through the collision objects, we take each collision object's world transform and multiply it by the bone's local transform to generate the correct world matrix for the body part's bone transform.

The second is for each body part in the mesh that is attached to a physics object, we tell it to ignore it's parent. This is because we already have a world transform for the body part from the collision object, therefore we do not need to use the parent's.

Hope some of this helps,
L7E
mickey
Posts: 107
Joined: Fri Sep 19, 2008 6:08 pm

Re: simulating ragdoll with DirectX

Post by mickey »

Hi logic7error!

I definitely haven't solved this yet and still waiting for answers. Thanks someone came!

But bear with me will you. Let me get this straight.

You don't combine any transformation matrix within your skinned mesh but instead you only use its local transformation and multiply it with the ragdoll's constrained rigid bodies individual world transformation? And this with this you were able to orient your skinned mesh properly with the ragdoll? (though i remember trying this)

My last attempt was to use the hingle constraint's angle, and apply it to the correct limb transformation and still go through normally how skinned mesh are rendered (ie, combining parent-child transformation matrix), and this works perfectly. I just got stuck that I could not find a way to get the orientation from a cone twist or a 6-dof like how the hinge constraint have a getHingleAngle method.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: simulating ragdoll with DirectX

Post by Erwin Coumans »

All rigid body parts of a Bullet ragdoll have a transform in world space. You don't need to accumulate any transforms yourself, and no need to use any constraint transform or hinge angle.

Why can't you simply copy/map the world transform for each rigid body limb to its graphics companion?
Thanks,
Erwin
mickey
Posts: 107
Joined: Fri Sep 19, 2008 6:08 pm

Re: simulating ragdoll with DirectX

Post by mickey »

Hi Erwin

Thanks for your reply. Its because the model's limbs are offset/oriented relative to the pelvis/chest, so it needs to inherit its parent bone transformation matrix and not just copy the rigid body's transformation or else it won't get aligned or positioned properly, no?

My model is one whole 3d character and not chop off into pieces, if its limbs were chop off into pieces, then I can probably just apply the rigid bodies world transformation to each of the limbs since the limbs are positioned at the origin.
logic7error
Posts: 4
Joined: Tue Oct 21, 2008 12:59 am

Re: simulating ragdoll with DirectX

Post by logic7error »

Hey mickey,

Reiterating what Erwin said: all the bodyparts of the the physics ragdoll are already in world space. After stepping/updating the simulation, the rotation and translation have already been calculated for each bodypart. Because you have the orientation in world space, you do not need to do the parent-child matrix multiplication. (This is why we tell the child to ignore the parent because it's world matrix has already been set through Bullet.)

Let's talk about the bone offset and the physics offset I mentioned earlier. In model/local space, take the upper arm collision capsule. The physics offset is at the center of the capsule (origin). The bone offset is at the tip of the capsule where the hinge is connected. Because the bone and physics offsets do not match, I need to move from the physics reference to the bone's reference. This is where that multiplication comes from that I mentioned.

The other thing that you might want to do is break the problem down into smaller parts. Because you are using a skinned mesh, take the top level parent (for us its the pelvis) and match it to the corresponding rigidbody's orientation. Then slowly work your way down the hierarchy. Don't worry about the children of the parent until you have the parent orientation worked out.

Thanks,
L7E