简体   繁体   English

父子矩阵链接/订单层次结构

[英]Parent-Child Matrix Chaining/Order Hierarchy

I'm trying to create a Bone structure in XNA C#. 我正在尝试在XNA C#中创建Bone结构。

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. 目前,它可以正常工作,但是在骨骼上执行IK例程时,一切都会变得疯狂。

Can someone check my code? 有人可以检查我的代码吗? ID 0 in the vector is the parent, and 1 being the child offset 52 units from the parent... 向量中的ID 0是父代,而1是子代,相对于父代偏移52个单位...

        _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 这是我在2D模式下达到的代码,您可以在此处观看实际操作

    //------------------------------------------------------------------------------------
    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( );
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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