Поворот 3D-модели в XNA

Я новичок в XNA, и я создаю простую игру. Извините, что это, вероятно, очень просто, но я не могу найти никакой помощи.В игре есть корабль, который я сделал с помощью Blender, и я хочу иметь возможность управлять кораблем, вращая его оси X, Y и Z. Вот код, который у меня есть:

protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);
  RotationMatrix = Matrix.CreateRotationY(MathHelper.PiOver2) * Matrix.CreateRotationY    (rotationY) * Matrix.CreateRotationX(rotationX) * Matrix.CreateRotationZ(rotationZ);

        Matrix shipTransformMatrix = RotationMatrix * Matrix.CreateTranslation(ship.Position);

                        DrawModel(ship.Model, shipTransformMatrix, ship.Transforms);
        // TODO: Add your drawing code here


        base.Draw(gameTime);
    }

    public  void DrawModel(Model model, Matrix modelTransform, Matrix[] absoluteBoneTransforms)
    {
        //Draw the model, a model can have multiple meshes, so loop
        foreach (ModelMesh mesh in model.Meshes)
        {
            //This is where the mesh orientation is set
            foreach (BasicEffect effect in mesh.Effects)
            {

                effect.World = absoluteBoneTransforms[mesh.ParentBone.Index] * modelTransform;
                effect.Projection = projectionMatrix;
                effect.View = viewMatrix;

            }

            //Draw the mesh, will use the effects set above.
            mesh.Draw();
        }
    }

Это будет вращать корабль, но не вдоль оси корабля. Если я поверну ось Y (изменив значение rotateY), корабль будет вращаться вдоль своей оси Y. Но если я поверну ось X или Z, корабль будет вращаться в соответствии с мировыми осями X и Z, а не своей собственной. Как сделать так, чтобы корабль вращался вокруг своей оси? Нужно ли делать что-то другое с матрицами? Спасибо

9
задан davidsbro 11 September 2013 в 14:03
поделиться