gpt4 book ai didi

c# - SFML 3D 鼠标外观

转载 作者:太空宇宙 更新时间:2023-11-03 14:14:56 25 4
gpt4 key购买 nike

编辑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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com