Sign in to follow this  

Re-orientate the pivot of a biped?

Recommended Posts

I want to re-orientate the pivot of a biped.
This is what I am trying to do...
1) Calculate the difference in position between old and new pivot
   1a) apply an inverse to the result
2) Calculate the difference in orientation between old and new pivot
   2a) apply an inverse to the result
3) add on to each bone's offset matrix for position
4) add on to each bone's transformation matrix for rotation

What I am getting out of this is not correct

 

Could anyone give it a fix?

 

void Skeleton::MovePivot(const D3DXVECTOR3& newPivot)
    {
        // basically, when the pivot is translated down 0.5m
        // all offset matrices translated up 0.5m
        // if the pivot rotates left 30 degrees
        // all transformation matrix rotates right 30 degrees

        LPD3DXFRAME oldFrame = D3DXFrameFind(mDXSkeleton, "Bip001");

        D3DXVECTOR3 oldPivot(oldFrame->TransformationMatrix._41, oldFrame->TransformationMatrix._42, oldFrame->TransformationMatrix._43);

        // (0,0,0) - (0,1,0) = (0,-1,0)
        D3DXVECTOR3 offsetDiff = newPivot - oldPivot;

        D3DXMATRIX matOffsetDiff;
        D3DXMatrixTranslation(&matOffsetDiff, offsetDiff.x, offsetDiff.y, offsetDiff.z);

        D3DXMatrixInverse(&matOffsetDiff, NULL, &matOffsetDiff);

        D3DXVECTOR3 tempPos, tempSca;
        D3DXQUATERNION tempQuat;

        D3DXMatrixDecompose(&tempSca, &tempQuat, &tempPos, &oldFrame->TransformationMatrix);

        D3DXMATRIX matOffsetDiff2;
        // rotation

        D3DXQUATERNION newQuat(0,0,0,1);

        // delta_q = conjugate(q1) * q2;
        D3DXQuaternionConjugate(&newQuat, &newQuat);

        D3DXQUATERNION qOffset = newQuat * tempQuat;

        D3DXMatrixRotationQuaternion(&matOffsetDiff2, &qOffset);

        //D3DXMatrixInverse(&matOffsetDiff2, NULL, &matOffsetDiff2);        
            
          
        TransformBones(mDXSkeleton, matOffsetDiff, matOffsetDiff2);

        D3DXMATRIX iden;
        D3DXMatrixIdentity(&iden);

        oldFrame->TransformationMatrix = iden;

        // pivot is now at ground (0,0,0)

        
    }

    void Skeleton::TransformBones(LPD3DXFRAME frame, const D3DXMATRIX& matDiffTrans, const D3DXMATRIX& matDiffRot)
    {
        if (!frame)
            return;

        // offset all transformation matrix for rotations
        // offset all offset matrix for translations

        if (frame->pMeshContainer)
        {
            MESHCONTAINER* pMeshContainer = (MESHCONTAINER*)frame->pMeshContainer;
            D3DXMATRIX* pOffsetMatrix = pMeshContainer->pBoneOffsetMatrices;
            *pOffsetMatrix *= matDiffTrans;
        }

        D3DXMATRIX& localMat = frame->TransformationMatrix;
        localMat *= matDiffRot;             

        if (frame->pFrameFirstChild)
        {
            TransformBones(frame->pFrameFirstChild, matDiffTrans, matDiffRot);
        }

        if (frame->pFrameSibling)
        {
            TransformBones(frame->pFrameSibling, matDiffTrans, matDiffRot);
        }

    }

Share this post


Link to post
Share on other sites

Could you give a little more details on the effect you are trying to achieve?

By biped, do you mean the biped of a rifle? Or a bipedal creature?

If it's a bipedal creature, do you mean to tilt the creature? Or repivot it's foot in mid stride?

Share this post


Link to post
Share on other sites

Hello,
I want to animate a character object with crounching....
Actually, I have turned to other solutions right now.
What I did was bend the thighs and calf, then lower the object as a whole.
Then I achieve the effect.

 

BTW, you do have to translate the pivot of the biped (3ds max),

What you can do is just find the difference between old and new (rotation)

then just transform the scene root with the difference... it works!

Thanks
Jack

Edited by lucky6969b

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this