我有一个关于XNA模型旋转的问题。现在的问题是 - 我该怎么办(其值应更改以及如何)那样的旋转绿化模范(红色箭头):XNA中的旋转
http://img843.imageshack.us/i/question1.jpg/
代码用于绘制:
DrawModel(elementD, new Vector3(-1, 0.5f, 0.55f), 0,-90,0);
private void DrawModel(Model model, Vector3 position, float rotXInDeg, float rotYInDeg, float rotZInDeg)
{
float rotX = (float)(rotXInDeg * Math.PI/180);
float rotY = (float)(rotYInDeg * Math.PI/180);
float rotZ = (float)(rotZInDeg * Math.PI/180);
Matrix worldMatrix = Matrix.CreateScale(0.5f, 0.5f, 0.5f) * Matrix.CreateRotationY(rotY) *Matrix.CreateRotationX(rotX)*Matrix.CreateRotationZ(rotZ)* Matrix.CreateTranslation(position);
Matrix[] xwingTransforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(xwingTransforms);
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.View = cam.viewMatrix;
effect.Projection = cam.projectionMatrix;
effect.World = (xwingTransforms[mesh.ParentBone.Index] * worldMatrix);
}
mesh.Draw();
}
}
所以,我想通过稍微改变我的代码以应用解决方案:
Matrix worldMatrix = Matrix.CreateScale(0.5f, 0.5f, 0.5f) * Matrix.CreateRotationY(rotY) * Matrix.CreateRotationX(rotX) * Matrix.CreateTranslation(position)
* Matrix.CreateRotationX((float)(45 * Math.PI/180)) * Matrix.CreateRotationZ(rotZ) * Matrix.CreateRotationX((float)(-45 * Math.PI/180));
通过改变rotZ参数,我确实能够旋转模型。不过效果不是我想要达到的http://img225.imageshack.us/i/questionau.jpg/,它改变了立场。是因为模型有缺陷还是其他一些错误?我希望“圆柱体”能够保持其位置。你知道我该怎么做?
您是否考虑过注册您的答案或将其标记为已接受?我看到你在这里是新的,所以记得upvotes是什么驱动这个网站... – Pedery 2011-03-24 23:13:07