父子矩阵链接/顺序层次结构

发布于 2025-01-03 14:40:29 字数 753 浏览 2 评论 0原文

我正在尝试在 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;

谢谢您的帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山色无中 2025-01-10 14:40:29

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

这是我在 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( );
        }
    }

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( );
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文