简体   繁体   中英

Parent-Child Matrix Chaining/Order Hierarchy

I'm trying to create a Bone structure in XNA C#.

I am trying to achieve this by a parent-child relationship with matrices. When I rotate the parent, the child should rotate in the same manner...

At the moment this works fine, but when performing an IK routine upon the bones, everything goes wild.

Can someone check my code? ID 0 in the vector is the parent, and 1 being the child offset 52 units from the parent...

        _boneList[0]._position = new Vector3(0, 0, 0);
        _boneList[0]._localTransform = _boneList[0]._rotationTransform * Matrix.CreateTranslation(_boneList[0]._position);
        _boneList[0]._globalTransform = _boneList[0]._localTransform;


        _boneList[1]._position = new Vector3(0, 52, 0);
        _boneList[1]._localTransform =  _boneList[1]._rotationTransform * Matrix.CreateTranslation(_boneList[1]._position);
        _boneList[1]._globalTransform = _boneList[1]._localTransform * _boneList[0]._globalTransform;

Thank you for the help.

It looks fine to me, you should have other problem, maybe with angles?

This is my code to reach it in 2D, you can watch it in action here

    //------------------------------------------------------------------------------------
    public void UpdateLocal( )
    {  
        Vector2 traslation = Translator.GetValue();
        float rotation = Rotator.GetValue();
        Vector2 scale = Scalator.GetValue();

        Matrix mTraslation, mRotation, mScale;
        Matrix.CreateTranslation( traslation.X, traslation.Y, 0, out mTraslation );
        Matrix.CreateRotationZ( rotation, out mRotation );
        Matrix.CreateScale(scale.X, scale.Y, 1 , out mScale );
        Matrix.Multiply( ref mScale, ref mRotation, out Local );
        Matrix.Multiply( ref Local, ref mTraslation, out Local );  
    }


    //---------------------------------------------------------------------------------
    protected virtual void SpecialUpdateTransformTopToDown( )
    {            
        UpdateLocal( );

        if ( Parent != null )
        {
             Matrix.Multiply( ref Local, ref (Parent as BoneData).Absolute, out Absolute );
        }
        else
        {
            Absolute = Local;
        }

        foreach ( BoneData child in _children.OfType<BoneData>() )
        {
            child.SpecialUpdateTransformTopToDown( );
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM