XNA 3D相机滚动

时间:2013-02-19 18:28:32

标签: c# xna

我正在使用Seabase Alpha的XNA相机类,它运行得很好,我根本不需要修改它。但是,如果我同时横向水平和偏航,它会改变我的滚动,我无法弄清楚它是如何“锁定”的,以至于它永远不会滚动。 (类似于第一人称射击游戏,它只能扫射,推力,并调整它的俯仰和偏航。)

我调用该类的代码如下:

        if (gamepadState.ThumbSticks.Right.X != 0)
        {
            // Look Around
            camera.Yaw(-gamepadState.ThumbSticks.Right.X);
        }
        if (gamepadState.ThumbSticks.Right.Y != 0)
        {
            // Look Around
            camera.Pitch(-gamepadState.ThumbSticks.Right.Y);
        }
        if (gamepadState.ThumbSticks.Left.X != 0)
        {
            // Move Around
            camera.StrafeHorz(-gamepadState.ThumbSticks.Left.X);
        }
        if (gamepadState.ThumbSticks.Left.Y != 0)
        {
            // Move Around
            camera.Thrust(gamepadState.ThumbSticks.Left.Y);
        }
        if (gamepadState.Buttons.LeftShoulder == ButtonState.Pressed)
        {
            camera.StrafeVert(0.2f);
        }
        if (gamepadState.Buttons.RightShoulder == ButtonState.Pressed)
        {
            camera.StrafeVert(-0.2f);
        }

我尝试将相机类中的向上矢量强制为Vector(0, 0, 1)Vector(0, 1, 0)。设置Z为1有点帮助,但它仍然可以滚动。

1 个答案:

答案 0 :(得分:0)

如果您无意在相机中实现滚动,最好像这样修改海基会代码:

public Matrix ViewMatrix
{
    get
    {
        return Matrix.CreateLookAt(Position, Forward+Position, Vector3.Up);//changed the 3rd param from Up toVector3.Up
    }
}

这将禁止您遇到的任意滚动。但也会妨碍你实施roll。