C# XNA空间模拟器中的四元数旋转问题

C# XNA空间模拟器中的四元数旋转问题,c#,matrix,xna,quaternions,C#,Matrix,Xna,Quaternions,我花了8个小时试图找到一个解决方案 这就是我的问题。我的船在旋转,就像绕着什么东西旋转一样,就像一根绳子。当我离起始位置越来越远时,我开始越来越奇怪地旋转。就像我依附在一根绳子上 这是旋转和移动的代码 public void MoveShip(List<InputAction> InputActionList, GameTime gameTime) { float second = (float)gameTime.ElapsedGameTime.TotalSe

我花了8个小时试图找到一个解决方案

这就是我的问题。我的船在旋转,就像绕着什么东西旋转一样,就像一根绳子。当我离起始位置越来越远时,我开始越来越奇怪地旋转。就像我依附在一根绳子上

这是旋转和移动的代码

public void MoveShip(List<InputAction> InputActionList, GameTime gameTime)
    {
        float second = (float)gameTime.ElapsedGameTime.TotalSeconds;
        float currentTurningSpeed = second * TurningSpeed;
        float leftRightRotation = 0; 
        float upDownRotation = 0;
        float linearLeftRightRotation = 0;
        foreach(InputAction action in InputActionList)
        {
            switch(action)
            {
                case InputAction.Left:
                    leftRightRotation -= currentTurningSpeed;
                    break;
                case InputAction.Right:
                    leftRightRotation += currentTurningSpeed;
                    break;
                case InputAction.Up:
                    upDownRotation += currentTurningSpeed;
                    break;
                case InputAction.Down:
                    upDownRotation -= currentTurningSpeed;
                    break;
                case InputAction.IncreaseSpeed:
                    if (ShipSpeed < MaxShipSpeed)
                        ShipSpeed += Acceleration;
                    break;
                case InputAction.DecreaseSpeed:
                    if (ShipSpeed > MinShipSpeed)
                        ShipSpeed -= Acceleration;
                    break;
                case InputAction.LinearLeft:
                    linearLeftRightRotation += currentTurningSpeed;
                    break;
                case InputAction.LinearRight:
                    linearLeftRightRotation -= currentTurningSpeed;
                    break;
                case InputAction.Fire1:
                    WeaponSystem2D.RequestFire(ShipPosition, ShipRotation);
                    break;
            }

        }


        Quaternion currentRotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), leftRightRotation) * 
            Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), upDownRotation) *
            Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), linearLeftRightRotation);


        currentRotation.Normalize();
        ShipRotation *= currentRotation;

        ShipPosition *= Vector3.Transform(new Vector3(0, 0, 1), ShipRotation) * (ShipSpeed * second);

        ShipWorld = Matrix.CreateFromQuaternion(ShipRotation) * Matrix.CreateTranslation(ShipPosition);

    }
public void MoveShip(列表输入操作列表,游戏时间游戏时间)
{
浮点秒=(浮点)gameTime.ElapsedGameTime.TotalSeconds;
浮动电流转速=秒*转速;
浮动左向右旋转=0;
浮动上下旋转=0;
浮点数linearLeftRightRotation=0;
foreach(InputActionList中的InputAction操作)
{
开关(动作)
{
案例输入。左:
左右旋转-=当前旋转速度;
打破
案例输入。右:
左右旋转+=当前旋转速度;
打破
案例输入。向上:
上下旋转+=当前旋转速度;
打破
案例输入。向下:
上下旋转-=当前旋转速度;
打破
案例输入。增加速度:
if(船速<最大船速)
船速+=加速度;
打破
案例输入。降低速度:
如果(船速>分钟船速)
船速-=加速度;
打破
案例输入.LinearLeft:
linearLeftRightRotation+=当前旋转速度;
打破
案例输入.LinearRight:
linearLeftRightRotation-=当前旋转速度;
打破
案例InputAction.Fire1:
武器系统2D.请求火力(船位、船位旋转);
打破
}
}
四元数currentRotation=四元数。CreateFromAxisAngle(新矢量3(0,0,1),leftRightRotation)*
四元数。CreateFromAxisAngle(新矢量3(1,0,0),上下旋转)*
四元数。CreateFromAxisAngle(新矢量3(0,1,0),linearLeftRightRotation);
currentRotation.Normalize();
船舶旋转*=当前旋转;
ShipPosition*=矢量3.变换(新矢量3(0,0,1),ShipRotation)*(ShipSpeed*秒);
ShipWorld=Matrix.CreateFromQuaternion(ShipRotation)*Matrix.CreateTranslation(ShipPosition);
}
有什么问题?为什么要这样做?我希望飞船在一角上旋转,因为它是空间

编辑: -模式不是问题


编辑2:没关系,旋转确实起作用了,是我的天空盒子坏了

这段代码实际上很完美,我的skybox让它看起来像坏了一样。

我知道你保证模型没有问题,但模型的枢轴/中心/中点设置正确吗?我以前也有过类似的问题,这是我的模型。