Map PhysicsBones to ModelBones for Ragdoll (PhysX and DirectX)

Started by
2 comments, last by TheGoozah 11 years ago

Hey gamedev,

for a college project I need to create a ragdoll using DirectX and PhysX.
I'm still in the first phase of laying out the structure for this ragdoll. At this moment I'm trying to map
actors to the bones that are imported together with mesh data. The problem I have at this moment is
that I can move my actor to the position of the bone (all offsets + world = worldmatrix).
But when I want it to follow the animation, my bone gets translated and rotated (axis) correctly, but my shape
doesn't rotate. Only the axis changes.

This engine is an engine written by some teachers, so I can't share it here. Also, the architecture is still
rough. Here are some snippets of where the issue is.

I hope this is a know issue and someone can help me with this one! It is pretty important for my project.

Thank you in advance guys/girls!!


void PhysxBone::MapToBone(MeshFilter* pMeshFilter)
{
       //........................
	m_matModelSpace *= m_pBone->Offset;

       //..................
	D3DXMATRIX world;
	D3DXMatrixIdentity(&world);
	m_matWorldSpace = m_matModelSpace * world;
}

void PhysxBone::Update(D3DXMATRIX matKeyTransform)
{
	m_matWorldSpace = matKeyTransform * m_matModelSpace;

	NxMat34 nPos;
	PhysicsManager::GetInstance()->DMatToNMat(nPos, m_matWorldSpace);
	m_pActor->setGlobalPose(nPos);
}

void PhysicsManager::DMatToNMat(NxMat34& NxMat, const D3DXMATRIX& D3DMat)
{
	NxVec3 vTmp;

	vTmp = NxVec3(D3DMat._11, D3DMat._21, D3DMat._31);
	NxMat.M.setRow(0, vTmp);

	vTmp = NxVec3(D3DMat._12, D3DMat._22, D3DMat._32);
	NxMat.M.setRow(1, vTmp);

	vTmp = NxVec3(D3DMat._13, D3DMat._23, D3DMat._33);
	NxMat.M.setRow(2, vTmp);

	NxMat.t.set(D3DMat._41, D3DMat._42, D3DMat._43);
}

Advertisement

There are usually two scenarios:

1) The animation system is driving the physics

- All actors should be kinematic and you pass the target transforms. PhysX will compute the linear and angular velocities to reach the target transforms. There are other options which involve motors, but the version I mentioned is the easiest

2) The physic system is driving the bones.

- There are some gotchas here. The easiest case is when you have 1 : 1 mapping. This means every bone is associated with one rigid body. In this case you simply copy over the rigid body transforms to your bones. You must make sure you update the animation system so it can compute the local transforms if this is needed.

The more involved case is when there are more bones than rigid bodies. In this case you need to detect internal and leaf bones which are not driven by a rigid bodies. You would reset the internal bones to the bind pose and let the physic system deal with the possible joint errors. For the leaf bones you can do whatever you like.

Hey, sorry for the late respons.
Dirk Gregorius: I am having issues with putting the PhysX actors in the right position. For some reasons the data I get does not match as a direct input for PhysX actors. For the step 1 I put the actors on the correct position at this moment. Doing it your way would make it more difficult at this stage, but your version would be the final version offcourse.

So, I know how a ragdoll system should work. But I have issues with writing one myself :). In particular the first step.


If I position my actors using this formula: TotalOffset * LocalTransformAnimation

I get these results:

http://img842.imageshack.us/img842/8779/ragdollissues01.jpg

http://img21.imageshack.us/img21/6029/ragdollissues02.jpg

My TotalOffset is something like this:

TotalOffset = parentOffset * parentOffset * ........... * ownOffset;

Also checked some of the raw data from the .x itself. And found some strange things.

1. The offset of the bone is the offset based from the parent BUT the transform already has transform of the parent. This is kinda weird, why not both the final transform and offset or it's own offset and it's own local transform?

2. When I double check the numbers of the TotalOffset not all of them are correct. Some numbers that need to be 32.901 for exmample are 35.487.

I've been looking into this issue for a while now and haven't come up with a solution. Could someone guide me in solving this issue?

Here you can find some code, in my opinion, related to this problem:

http://pastebin.com/QT8sxuUp

PS: Everything works fine for the model itself (raw transform are being passed to a shader that positions the vertices to the right position). It is being animated correctly so there is no issue with the raw data from the .X file I guess (also double checked it with the Assimp Viewer).

Sorry for bumping this thread but I am really desperate in finding my problems.
As said before I guess there is something wrong with my Offset and TransformMatrix calculations.

So here the snippet isolated: http://pastebin.com/gVTLCrbJ.

Anyone out here having experience with ragdolls or mapping actors to "bones" from an .x file?

Maybe one can point me in the right direction regarding formulas or pointing out an mistake in my
logic :)
Thx guys!

This topic is closed to new replies.

Advertisement