在xna中保存旋转后的骨骼位置

本文关键字:位置 旋转 xna 保存 | 更新日期: 2023-09-27 17:59:31

我正在开发一个在xna框架c#中求解rubik立方体的游戏。我想知道如何在旋转骨骼后保存它们的位置。我调用这个方法来绘制一个骨骼,该骨骼构造立方体的面侧。

protected void DrawModel()
{
    cube.CopyAbsoluteBoneTransformsTo(modelTransforms);
    ModelMeshCollection cubes = cube.Meshes;
    List<string> yellowFace = new List<string>();
    for (int i = 0; i < cubes.Count; i++)
    {
        if (cubes.ElementAt(i).Name.ToString().Contains("F"))
        {
            yellowFace.Add(cubes.ElementAt(i).Name.ToString());
        }
    }
    for (int j = 0; j < yellowFace.Count; j++)
    {
        foreach (BasicEffect eff in cubes[yellowFace.ElementAt(j)].Effects)
        {
            eff.View = View;
            eff.Projection = Projection;
            eff.EnableDefaultLighting();
            degree = (float)degree;
            if (xtan <= degree)
            {
                eff.World = Matrix.CreateFromAxisAngle(new Vector3(0, 0, 1), -xtan);

            }


        }

        cubes[yellowFace.ElementAt(j)].Draw();
    }
    for (int i = 0; i < cubes.Count; i++)
    {
        if (cubes.ElementAt(i).Name.ToString().Contains("F"))
        {
            continue;
        }
        else
        {
            foreach (BasicEffect eff in cubes.ElementAt(i).Effects)
            {
                eff.View = View;

                eff.World = Matrix.Identity;

                eff.Projection = Projection;
                eff.EnableDefaultLighting();
            }
            cubes.ElementAt(i).Draw();
        }
    }


}

在我运行游戏后,旋转运行良好,但一旦完成,游戏就会重新加载骨骼,就像它们在开始时一样。

在xna中保存旋转后的骨骼位置

大家好,要在旋转后保存骨骼位置,必须在矩阵变换中对其进行变换

//this before the drawing loop
model.CopyAbsoluteBoneTransformsTo(modelTransforms);
//drawing loop .... 
//basiceffect loop
......
//after basiceffect loop
Matrix rotationmatrix = Matrix.CreateRotationX(angle);
// X,Y Z are the axis , angle is the rotaion value
mesh.parentbone.Transform = rotationmatrix * mesh.parentbone.transform;
//end drawing loop

我希望这能帮助到每个人感谢