首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >正确旋转一个皮肤模型的骨头?XNA

正确旋转一个皮肤模型的骨头?XNA
EN

Stack Overflow用户
提问于 2012-01-16 05:48:18
回答 1查看 1.2K关注 0票数 0

我如何旋转皮肤模型的骨头围绕自己,而不是模型的起源?

SkinningSample中,当我旋转花花公子的前臂时,它会围绕模型的起源旋转。如果可能的话,我想让骨头围绕自己的起源旋转。

GetSkinTransforms()的描述是:

“获取当前的骨转换矩阵,相对于剥皮绑定姿势。

所以我怀疑这可能是问题所在。有没有人知道如何将这些转换转换成需要的样子?

这里是SkinningSample的一部分。

代码语言:javascript
复制
  float rotation = 0;
    protected override void Update(GameTime gameTime)
    {
        HandleInput();

        UpdateCamera(gameTime);

        animationPlayer.UpdateWorldTransforms(Matrix.Identity);
        animationPlayer.UpdateSkinTransforms();

        Matrix RotationTransform = Matrix.CreateFromYawPitchRoll(rotation, 0, 0) ;
        animationPlayer.GetSkinTransforms().SetValue(RotationTransform, 34); 

        rotation = rotation + .1f;
        base.Update(gameTime);
    }


    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice device = graphics.GraphicsDevice;

        device.Clear(Color.CornflowerBlue);

        Matrix[] bones = animationPlayer.GetSkinTransforms();

        // Compute camera matrices.
        Matrix view = Matrix.CreateTranslation(0, -40, 0) * 
                      Matrix.CreateRotationY(MathHelper.ToRadians(cameraRotation)) *
                      Matrix.CreateRotationX(MathHelper.ToRadians(cameraArc)) *
                      Matrix.CreateLookAt(new Vector3(0, 0, -cameraDistance), 
                                          new Vector3(0, 0, 0), Vector3.Up);

        Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                                device.Viewport.AspectRatio,
                                                                1,
                                                                10000);

        // Render the skinned mesh.
        foreach (ModelMesh mesh in currentModel.Meshes)
        {
            foreach (SkinnedEffect effect in mesh.Effects)
            {
                effect.SetBoneTransforms(bones);

                effect.View = view;
                effect.Projection = projection;

                effect.EnableDefaultLighting();

                effect.SpecularColor = new Vector3(0.25f);
                effect.SpecularPower = 16;
            }

            mesh.Draw();
        }

        base.Draw(gameTime);
    }
EN

回答 1

Stack Overflow用户

发布于 2012-02-09 14:19:06

您必须转换boneTransform,而不是skinTransform。我刚刚在AnimationPlayer类中创建了另一个方法来允许这种操作:

代码语言:javascript
复制
public void TransformBone(Matrix BoneAlteration, int BoneID)
{
    boneTransform[BoneID] = BoneAlteration * bindPose[BoneID];
    UpdateWorldTransforms(Matrix.Identity);
    UpdateSkinTransforms();
}

因此,如果我想旋转一个骨头,我会调用这个方法来创建正确的skinTransformation矩阵。这假设其他boneTransforms设置在正确的位置。我还认为,如果你想围绕已经旋转的骨头旋转,你可以用bindPose代替boneTransform。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8876211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档