【问题标题】:Ease into model rotation轻松进入模型旋转
【发布时间】:2012-03-11 12:36:56
【问题描述】:

我正在 XNA 中制作一个简单的游戏(对于 Windows,如果这会有所不同),当玩家向右移动时,我正在使用以下代码旋转船模型,使其看起来像船俯身扫射:

RotationMatrix = Matrix.CreateRotationX(MathHelper.PiOver2) *
                 Matrix.CreateRotationY(0.4f);

这行得通,但它会立即将船弹到所需的旋转位置。我宁愿它缓解几帧。作为参考,旋转矩阵声明如下:

public Matrix RotationMatrix = Matrix.CreateRotationX(MathHelper.PiOver2);

我可以做些什么来平滑精益?

【问题讨论】:

    标签: c# 3d matrix xna


    【解决方案1】:

    我认为您只需要在代码中包含时间。在 Xna 中,您可以访问 GameTime 对象(例如在 Game.Draw 方法中),因此,您可以尝试这样的操作:

    private float _seconds = 0;
    protected override void Draw(GameTime gameTime)
    {
        if (_seconds < 1)
        {
            _seconds += gameTime.ElapsedGameTime.TotalSeconds;
        }
        RotationMatrix = Matrix.CreateRotationX(MathHelper.PiOver2) *
             Matrix.CreateRotationY(0.4f * _seconds);
        base.Draw(gameTime);
    }
    

    从我现在所在的地方,我无法检查此代码是否有效,所以这只是想法;)。

    【讨论】:

    • 是的,这行得通。我最终将变量设置为船舶类中的公共浮点数,以便我可以更轻松地跟踪它。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-31
    • 1970-01-01
    • 1970-01-01
    • 2020-06-22
    • 2021-01-27
    相关资源
    最近更新 更多