2

Edit2:我解决了大部分问题,但我有一个烦恼。当光标到达屏幕边缘并被拉到另一侧时,相机会抖动,这将不起作用。有人能看到如何阻止吗?

    bool attention = true;
    Vector2 p, mousePos;
    private float MOUSE_SENSITIVITY = 4.0f;

    private void OnMouseMove(object sender, MouseMoveEventArgs e)
    {
        float DeltX = 0, DeltY = 0;
        int border = 2;
        Console.WriteLine(attention + "");

        if (attention == true)
        {
            p.X = e.X;
            p.Y = e.Y;

            DeltX = (float)(mousePos.X - e.X) / MOUSE_SENSITIVITY;
            DeltY = (float)(mousePos.Y - e.Y) / MOUSE_SENSITIVITY;
        }
        else
        {
            mousePos = p;
        }

        attention = true;

        if (e.X > App.Width - border)
        {
            attention = false;
            App.SetCursorPosition((uint)border, (uint)e.Y);
            DeltX = 0;
            DeltY = 0;

        }
        else if (e.X < border)
        {
            attention = false;
            App.SetCursorPosition((uint)(App.Width - border), (uint)e.Y);
            DeltX = 0;
            DeltY = 0;

        }

        if (e.Y > App.Height - border)
        {
            attention = false;
            App.SetCursorPosition((uint)e.X, (uint)border);
            DeltX = 0;
            DeltY = 0;

        }
        else if (e.Y < border)
        {
            attention = false;
            App.SetCursorPosition((uint)e.X, (uint)(App.Height - border));
            DeltX = 0;
            DeltY = 0;

        }



        Cam.RotateY(DeltX);
        Cam.RotateX(DeltY);


        mousePos = p;

    }
4

2 回答 2

1

Typically you set the mouse position to the center of the window each frame. Previously you read to mouse position and subtract the center of the window. This way you can easily get the mouse movement each frame without having to worry about window borders.

Vector2i center(window->getSize().x / 2, window->getSize().y / 2);
Vector2i delta = Mouse::getPosition(*window) - center;
Mouse::setPosition(center, *window);
于 2012-12-25T13:27:04.930 回答
0

我还在加快速度,所以请谨慎对待。(我正在努力!)

我认为您的鼠标移动以像素为单位,这意味着相机的完整旋转。通过除以 0.4,(MOUSE_MOVEMENT,),您将影响“0.4 完整转”的一些倍数,(例如 152 像素 / .04 = 380 转,让您面向与开始时相同的方向。)

尝试除以 256 而不是 0.4,看看效果是否更好。

于 2011-07-23T23:33:49.413 回答