【问题标题】:Parent-Child Matrix Chaining/Order Hierarchy父子矩阵链接/顺序层次结构
【发布时间】:2012-02-08 12:36:58
【问题描述】:

我正在尝试在 XNA C# 中创建骨骼结构。

我试图通过与矩阵的父子关系来实现这一点。当我旋转父母时,孩子应该以同样的方式旋转......

目前这工作正常,但在骨骼上执行 IK 例程时,一切都变得疯狂。

有人可以检查我的代码吗?向量中的 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;

感谢您的帮助。

【问题讨论】:

    标签: c# matrix xna


    【解决方案1】:

    对我来说看起来不错,你应该有其他问题,也许是角度?

    这是我的二维码,您可以观看它的实际操作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( );
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-23
      • 1970-01-01
      • 1970-01-01
      • 2020-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多