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;
}