我只需要在模型启动时将其旋转 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();
}
请哈普!