C# 为什么当鼠标移动到360C左右时,鼠标光标会在中间结巴? 鼠标不移动,鼠标指针/光标卡在中间,口吃/跳舞/摇动。< /P>

C# 为什么当鼠标移动到360C左右时,鼠标光标会在中间结巴? 鼠标不移动,鼠标指针/光标卡在中间,口吃/跳舞/摇动。< /P>,c#,xna,xna-4.0,C#,Xna,Xna 4.0,这是我用于鼠标输入的代码: private void ProcessInputCamera(float amount) { previousState = currentState; currentState = Mouse.GetState(); MouseState currentMouseState = Mouse.GetState(); if (currentMouseState != originalMou

这是我用于鼠标输入的代码:

    private void ProcessInputCamera(float amount)
    {
        previousState = currentState;
        currentState = Mouse.GetState();
        MouseState currentMouseState = Mouse.GetState();
        if (currentMouseState != originalMouseState)
        {
            float xDifference = currentMouseState.X - originalMouseState.X;
            float yDifference = currentMouseState.Y - originalMouseState.Y;
            leftrightRot -= rotationSpeed * xDifference * amount;
            updownRot -= rotationSpeed * yDifference * amount;
            Mouse.SetPosition(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);
        }

        Vector3 moveVector = new Vector3(0, 0, 0);
        KeyboardState keyState = Keyboard.GetState();
        if (keyState.IsKeyDown(Keys.Up) || keyState.IsKeyDown(Keys.Up))
            moveVector += new Vector3(0, 0, -1);
        if (keyState.IsKeyDown(Keys.Down) || keyState.IsKeyDown(Keys.Down))
            moveVector += new Vector3(0, 0, 1);
        if (keyState.IsKeyDown(Keys.Right) || keyState.IsKeyDown(Keys.Right))
            moveVector += new Vector3(1, 0, 0);
        if (keyState.IsKeyDown(Keys.Left) || keyState.IsKeyDown(Keys.Left))
            moveVector += new Vector3(-1, 0, 0);
        if (keyState.IsKeyDown(Keys.Q))
            moveVector += new Vector3(0, 100, 0);
        if (keyState.IsKeyDown(Keys.Z))
            moveVector += new Vector3(0, -100, 0);
        AddToCameraPosition(moveVector * amount);
    }

    private void AddToCameraPosition(Vector3 vectorToAdd)
    {
        Matrix cameraRotation = Matrix.CreateRotationX(updownRot) * Matrix.CreateRotationY(leftrightRot);
        Vector3 rotatedVector = Vector3.Transform(vectorToAdd, cameraRotation);
        cameraPosition += moveSpeed * rotatedVector;
        UpdateViewMatrix(viewMatrix);
    }

    private void UpdateViewMatrix(Matrix viewMatrix)
    {
        Matrix cameraRotation = Matrix.CreateRotationX(updownRot) * Matrix.CreateRotationY(leftrightRot);

        Vector3 cameraOriginalTarget = new Vector3(0, 0, -1);
        Vector3 cameraRotatedTarget = Vector3.Transform(cameraOriginalTarget, cameraRotation);
        Vector3 cameraFinalTarget = cameraPosition + cameraRotatedTarget;

        Vector3 cameraOriginalUpVector = new Vector3(0, 1, 0);
        Vector3 cameraRotatedUpVector = Vector3.Transform(cameraOriginalUpVector, cameraRotation);

        viewMatrix = Matrix.CreateLookAt(cameraPosition, cameraFinalTarget, cameraRotatedUpVector);
    }
钥匙正在工作,它们正在旋转地形。 但我想用鼠标改变我的视角360度,就像第一人称视角一样环顾四周,不要旋转地形,也不要旋转物体,而是让我环顾360度

问题是这一行:

Mouse.SetPosition(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);
出于某种原因,使老鼠蜷缩在中间,跳舞/抖动/口吃。 如果我不使用它取消注释这一行,那么鼠标移动平稳,但它不移动任何360度的东西,我只需要定期移动鼠标光标

问题是为什么我不能像第一人称射击游戏那样移动360c鼠标

这是mt Game1.cs代码,包括我标记的相机代码。


该行将鼠标光标位置设置为屏幕中心。宽度/2和高度/2是屏幕中心的坐标。这条线在每个游戏循环中执行一次,因此它会将光标位置设置回中心。这就是为什么当你试图移动鼠标时,鼠标会卡在中间并抖动。

好的,所以我删除了这一行,并且在LoadContent方法中仅用这一行更新它一次。现在为什么当我把鼠标左右上下移动时,它根本不移动360度?我看到鼠标光标有规律地移动?它完成了所有的部分处理输入相机的方法,但鼠标不是电影我的观点360c像第一人称射击。就像在这个演示中一样:在查看代码的作用之后,这一行应该在那里。鼠标应该复位到屏幕中央。我帮不了你更多。
Mouse.SetPosition(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);