我只需要在模型開始時旋轉90度,而不需要編輯它的局部座標軸。 我有一個導彈沿着隧道向側方飛行90度,我需要它在隧道中朝下,同時仍然保持其運動方向。我試過了:如何在不旋轉本地軸的情況下旋轉模型?
virtual public void setOrientationWorld(float x, float y, float z)
{
mOrientation *= Matrix.CreateRotationX(MathHelper.ToRadians(x));
mOrientation *= Matrix.CreateRotationY(MathHelper.ToRadians(y));
mOrientation *= Matrix.CreateRotationZ(MathHelper.ToRadians(z));
}
setOrientationWorld(0,-90,0);
我已經試過:
virtual public void setOrientationLocal(float x, float y, float z)
{
mOrientation *= Matrix.CreateFromAxisAngle(mOrientation.Right, MathHelper.ToRadians(x));
mOrientation *= Matrix.CreateFromAxisAngle(mOrientation.Up, MathHelper.ToRadians(y));
mOrientation *= Matrix.CreateFromAxisAngle(mOrientation.Forward, MathHelper.ToRadians(z));
}
setOrientationLocal(0,-90,0);
但他們都毀了一切。當我這樣做的時候,導彈就會旋轉,並且所有的軸都會改變。即使只是去setPosition兩種(0,0,-1)使它沿着世界X軸移動,而不是它的Z.
我試圖本地和全球移動導彈,但無濟於事,就像這樣:
virtual public void moveLocal(float x, float y, float z)
{
mPosition += mOrientation.Right * x;
mPosition += mOrientation.Up * y;
mPosition += mOrientation.Forward * z;
}
而且
virtual public void moveWorld(float x, float y, float z)
{
mPosition.X += x;
mPosition.Y += y;
mPosition.Z += z;
}
我能想到的唯一的其他實質性的事情就是繪製函數,它可能有一些用它做:
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.World = Matrix.Identity *
Matrix.CreateScale(mScale) *
transforms[mesh.ParentBone.Index] *
Matrix.CreateTranslation(mPosition) *
mOrientation;
effect.View = game1.getView();
effect.Projection = game1.getProjection();
}
請致電Halp!
你是如何移動導彈的? – ChrisF
我的回答已在問題中更新:) – Magicaxis
您的'moveWorld'方法*應該*按您的願望工作 - 只需將導彈移動到您想要的位置。雖然我不完全理解你的'setOrientation'方法。爲什麼你有一個單一的方向值。一個4×4的矩陣將更清楚地描述位置和方向。 – ChrisF