0

我正在开发一个游戏来解决 xna 框架 c# 中的魔方。我想知道如何在旋转骨骼后保存骨骼位置。我正在调用此方法来绘制构成立方体正面的骨骼。

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

    }




}

在我运行游戏后,旋转运行良好,但一旦完成,游戏会重新加载骨骼,因为它们看着开始。

4

1 回答 1

0

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

//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

希望对大家有帮助 谢谢

于 2013-02-25T21:48:06.717 回答