2013-02-16 59 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 

我希望这有助于大家 谢谢