c++matrix3ddirectxskeletal-animation

Convert Between 3D Skeletal Systems DirectX


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)?


Solution

  • 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.