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 に答える