C# 如何旋转模型而不旋转它';什么是局部轴?
我只需要在模型启动时将其旋转90度,而不编辑其局部轴。 我有一枚导弹在隧道中以90度的角度横向飞行,我需要它面对隧道,同时保持它的运动方向。我试过:C# 如何旋转模型而不旋转它';什么是局部轴?,c#,matrix,xna,rotation,C#,Matrix,Xna,Rotation,我只需要在模型启动时将其旋转90度,而不编辑其局部轴。 我有一枚导弹在隧道中以90度的角度横向飞行,我需要它面对隧道,同时保持它的运动方向。我试过: virtual public void setOrientationWorld(float x, float y, float z) { mOrientation *= Matrix.CreateRotationX(MathHelper.ToRadians(x)); mOrientation *= Matrix.CreateRota
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));
}
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));
}
SetOrientionWorld(0,-90,0)
我试过:
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));
}
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));
}
设置方向局部(0,-90,0)
但他们都毁了一切。当我这样做的时候,导弹会旋转,所有轴都会改变。即使只是移动设置位置(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;
}
及
我能想到的唯一其他相关的东西是draw函数,它可能与此有关:
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();
}
请停下来 应用平移和旋转的顺序很重要。如果要全局应用旋转,则在将对象从旋转中心移开时,首先平移会导致问题。在这种情况下,需要旋转然后平移
在导弹的局部空间应用旋转时,应用旋转的顺序也很重要。按“横摇”、“俯仰”、“偏航”的顺序应用它们将产生与按“俯仰”、“偏航”、“横摇”等顺序应用它们不同的结果。顺序取决于您试图实现的目标,因此您可能必须创建一个方法,该方法可以完成所有六项任务,并根据参数选择其中一项任务。您如何移动导弹?我的答案已在问题中更新:)您的
移动世界
方法应该按照您的意愿工作-只要将导弹移动到您想要的位置即可。但是我不完全理解你的setOrientation
方法。为什么只有一个方向值。4x4矩阵可以更清晰地描述位置和方向。mOrientation是4x4矩阵,不是吗?是吗?你没有展示它的声明,就是这样!第一部分!在我的绘图函数中,我交换了矩阵;到Morentation*矩阵。创建转换(合成);现在一切都好起来了!