gpt4 book ai didi

c++ - OpenGL 相机 - 在使用 SetCursorPos(x,y) 时移动相机而不使其快速返回;?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:04:43 25 4
gpt4 key购买 nike

我在尝试更新相机时遇到问题。

我想通过鼠标改变相机的俯仰和偏航(它看起来的地方)但我希望鼠标保持在窗口的中心。

//where MouseP.x .y is the mouse position 
//(which is centered to the current window)

//get old position of the mouse
OldP.x = MouseP.x;
OldP.y = MouseP.y;

//work out the distance traveled
Delta.x = MouseP.x - OldP.x;
Delta.y = MouseP.y - OldP.y;

//update the camera(using distance traveled)
Rot.Yaw -=Delta.x/5;
Rot.Pitch -= Delta.y/5;

//move mouse to the center of the screen
SetCursorPos(CENTER_SCREEN_X,CENTER_SCREEN_Y);

问题是当鼠标设置为返回原点时,相机会快速返回到某个点。

我想根据从原点移动的距离而不是返回原点的距离来更新相机。

如果我把它拿出来,它会很好用,但是鼠标会飞出窗外。

最佳答案

必须小心光标和 3D 鼠标的移动。人们倾向于认为它是相关的,但实际上并非如此。从msdn阅读文章: http://msdn.microsoft.com/en-us/library/windows/desktop/ee418864%28v=vs.85%29.aspx“利用高清鼠标移动”这就是在 3D 应用程序中必须获得鼠标输入的方式。光标应该被隐藏。

如果您尝试将其重新居中,则会产生一种可怕的锯齿状感觉,即用户移动鼠标时光标试图脱离中心,但被一个看不见的 Spring 固定在原位。这看起来不是很专业。您无法解决这个问题,因为您的应用程序未安排在鼠标光标显示之前。

关于c++ - OpenGL 相机 - 在使用 SetCursorPos(x,y) 时移动相机而不使其快速返回;?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10488688/

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