0

I'm trying to convert between two different skeletal formats. I have a hierarchical skeleton.

Now in one format, a given node's matrix is calculated by (DirectX) (recurively, from bottom node to top, where matScale/matRotate/matTranslationFromParent are that particular nodes SRT):

appliedMatrices = appliedMatrices * matScale * matRotate * matTranslationFromParent;

But I need to convert it to a format that uses (recurively, from bottom node to top, where the translationIn is vector subtraction of (ParentPos - EndPartPos) and translation out is (EndPartPos - ParentPos), andmatScale/matRotate/matTranslationFromParent are that particular nodes SRT):

appliedMatrices = appliedMatrices * matScale * matTranslationOut * matRotate * matTranslationIn * matTranslationFromParent;

How do I convert from the first format to the second skeletal format (and back)?

Mary Ellen Bench
  • 589
  • 1
  • 8
  • 28
  • Do you have control over the in- and out-translations? Are these inverse to each other (as the subtraction suggests)? Converting from format 1 to format 2 could be achieved by setting these translations to the identity, right? – Nico Schertler Jul 09 '17 at 07:44
  • They are inverses, but unfortunately, I don't have control over the skeleton. So I can't just get rid of them (it would move the skeletal nodes). – Mary Ellen Bench Jul 09 '17 at 11:03

1 Answers1

0

If we compare the two versions, we see that the following two parts need to match:

matRotate1 * matTranslationFromParent1 
            = matTranslationOut * matRotate2 * matTranslationIn * matTranslationFromParent2

Since matRotate1 and matRotate2 are the only rotations, those two have to be equal. So this is simple:

matRotate1 = matRotate2

Then, for the two conversions, only one unknown is left:

//conversion 1 -> 2
matTranslationFromParent2 = (matTranslationOut * matRotate2 * matTranslationIn)^-1 * matRotate1 * matTranslationFromParent1
//conversion 2 -> 1
matTranslationFromParent1 = matRotate1^-1 * matTranslationOut * matRotate2 * matTranslationIn * matTranslationFromParent2

If performance is critical, you can do these calculations only on the translation vectors and not the entire matrices.

Nico Schertler
  • 32,049
  • 4
  • 39
  • 70