Parent/Child Transform problems

Started by
3 comments, last by lipsryme 11 years, 1 month ago

I'm trying to achieve a parent-child transform hierarchy but there's always something wrong about it:

I define a parent transform:


// Create parent transform
XMMATRIX parentTrans = XMMatrixTranslation(this->position.x, this->position.y, this->position.z);
XMStoreFloat4x4(&this->parentTransform, parentTrans);

then I define the transform of my child like this:


modelTrans = XMLoadFloat4x4(&left_arm->GetTransform());
localTrans = XMMatrixScaling(0.075f, 0.075f, 0.075f) * XMMatrixRotationZ(DegToRad(-20)) * XMMatrixTranslation(-0.27f, 0.025f, 0.0f);
transform = modelTrans * localTrans * parentTrans;
XMStoreFloat4x4(&newTransform, transform);
left_arm->SetTransform(newTransform);
this->left_armSocketTransform = left_arm->GetTransform();
  

This is where it gets odd since I thought the transform hierarchy would be (parent * child) but it turns out that the other way around is the only thing that is correct for me.

But now when I try to parent another child onto the transform of my child...


modelTrans = XMLoadFloat4x4(&this->projectile->GetTransform());
localTrans = XMMatrixIdentity(); //XMMatrixRotationX(DegToRad(-90));
transform = modelTrans * localTrans;
XMStoreFloat4x4(&this->local, transform);
XMMATRIX transform = XMLoadFloat4x4(&this->local) * XMLoadFloat4x4(&newOwner->GetLeftArmSocketTransform());

The normals of this child (actually just the Z-axis is inverted). I've already tried using the WorldInverseTranspose but since this is not a scaling issue it doesn't fix it.

This problem only occurs when I combine some local transform with the "LeftArmSocketTransform" (the transform of the first child)

Any ideas what I'm doing wrong ?

Advertisement

Why is the first one transform = modelTrans * localTrans * parentTrans; and the second one is only transform = modelTrans * localTrans?

Check out Frank Luna's description of the problem here: http://mathinfo.univ-reims.fr/image/dxMesh/extra/d3dx_skinnedmesh.pdf

Hi, the parent of the second one is in the last line "newOwner->GetLeftArmSocketTransform()"

And btw I know it's called torso, arm and stuff but it's actually not a skinned mesh. Just some meshes stuck together.

Hi, the parent of the second one is in the last line "newOwner->GetLeftArmSocketTransform()"

And btw I know it's called torso, arm and stuff but it's actually not a skinned mesh. Just some meshes stuck together.

The link I sent you is still valid, just read section 1 and stop there. The skinning part is just aesthetic anyway.

Ok so I now understand why I have to multiply it in the order of local * parent but this only means that everything I did was correct.
I still don't understand why the normals get screwed up after the last multiply.

LeftArmSocketTransform is the combined transform of the arm's local transform multiplied by it's parent's transform.
So then I'd multiply the local transform of e.g. the hand with this combined transform, right ? Well that's what I do.

This topic is closed to new replies.

Advertisement