我有一個關於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