2013-02-16 63 views
0

我正在開發一個解決xna框架c#中魔方的遊戲。我想知道如何在旋轉它們後保存骨骼位置。我調用這個方法來繪製構建立方體正面的骨骼。在xna中旋轉後保存骨骼位置

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

    } 




} 

後,我運行遊戲,旋轉運行良好,但一旦它的完成,在遊戲中他們看着開始重新加載的骨頭。

大家

回答

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 

我希望這有助於大家 謝謝