0

我花了 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);

    }

问题是什么?为什么要这样做?我希望船在一角钱上旋转,因为它是空间。

编辑:-模型不是问题。

编辑2:没关系,旋转实际上是在工作,是我的天空盒坏了!

4

1 回答 1

0

这段代码实际上是完美的,我的天空盒让它看起来像是坏了。

于 2012-07-13T19:39:02.033 回答