2013-02-16 1 views
0

Je suis en train de développer un jeu pour résoudre un cube de rubik dans xna framework C#. Je veux savoir comment sauvegarder les positions des os après les avoir tournées. J'appelle cette méthode pour dessiner un os qui construit le côté face du cube.Sauvegarder la position des os après rotation dans 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(); 
     } 

    } 




} 

Après je lance le jeu, la rotation est en cours d'exécution bonne, mais une fois qu'il est fait, le jeu relise les os comme ils avaient l'air au début.

Répondre

0

Salut tout le monde pour sauver la position des os après la rotation que vous avez à les transformer dans la matrice transformerai

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

J'espère que cette aide tout le monde merci

Questions connexes