c# - SFML 3D 鼠标外观

标签 c# opengl mouse sfml

编辑2: 我解决了大部分问题,但我有一个烦恼。当光标到达屏幕边缘并被拉到另一边时,相机会抖动,这将无法正常工作。有人可以看到如何停止吗?

    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;

    }

最佳答案

通常,您将鼠标位置设置为每帧窗口的中心。之前您读取鼠标位置并减去窗口的中心。通过这种方式,您可以轻松地在每一帧中移动鼠标,而不必担心窗口边界。

Vector2i center(window->getSize().x / 2, window->getSize().y / 2);
Vector2i delta = Mouse::getPosition(*window) - center;
Mouse::setPosition(center, *window);

关于c# - SFML 3D 鼠标外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6799078/

相关文章:

c# - 如何选择父级和筛选的子级列表(如果存在)(外连接)

c# - OpenTK 中的立方体贴图

c++ - Qt debian/ubuntu : Can't compile, 错误:找不到-lGL

python - 用于 Python 的 OpenGL 矩阵数学实用程序?

java - 使用鼠标拖动绘制三角形(如何使用鼠标拖动移动先前绘制的三角形)

C++ 简单 if 语句不检查?

c# - 覆盖 Form 的 OnFormClosing 以进行验证

c# - 错误 : 22001: value too long for type character varying(255)

c++ - Win32 中缺少鼠标移动消息

c# - 使用并行写入 MongoDB 时出错