我正在开发一款用于在xna framework c#中解决rubik立方体的游戏。我想知道旋转后如何保存骨骼位置。我正在调用这种方法来绘制构造立方体正面的骨骼。
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 :(得分: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
我希望这对大家有所帮助 谢谢