fix: capture cursor during viewport camera drags (#8)#236
Conversation
Pin the cursor to the press position via io.WantSetMousePos while a camera drag is active, and source motion from SDL_GetRelativeMouseState so deltas keep growing past screen edges. Hide the cursor for all three modes (previously only RMB hid it).
|
This change introduce a lot of stuttering when holding right to move the camera. |
So, I thought I was going crazy because I thought it was stuttering or slower FPS in my changes, but when I really tried to compare, I couldn't actually tell if it was or not. It's like my eyes would sometimes unconsciously notice it. But, I'm not really finding anything that I change makes a difference. I'll still work some more on this to see if I can't make it better, but I'll have to do it later because I've got a lot of other responsibilities to take care of. Maybe I'll submit some changes sometime later this week. |
Summary
Fixes #8.
The three viewport camera-drag controls (right-click free look, middle-click pan, and alt + left-click orbit)
all drove the camera by raw cursor motion.
There were at least two consequences:
This PR captures the cursor for the duration of any of the three camera drags, so motion is unbounded and the release always lands inside the editor.
How it works
The new
cameraDragActiveflagviewport3D.h:33, plus the press positioncursorLockPosviewport3D.h:37, drives a small set of changes inviewport3D.cpp:On press (Alt+LMB / MMB / RMB while in editor viewport)
viewport3D.cpp:650-657:cursorLockPosset toImGui::GetMousePos()SDL_GetRelativeMouseState(nullptr, nullptr)cameraDragActive = trueEach frame while captured
viewport3D.cpp:475-488:SDL_GetRelativeMouseState, which reports raw user motion since the last call. This delta is added tomousePos, so the existingdragDelta = mousePos - mousePosStartis unchanged.io.WantSetMousePos = true; io.MousePos = cursorLockPos. ImGui's handles warping the OS cursor back each frame, so other widgets never see the cursor move and don't register false hover.viewport3D.cpp:568.On release
viewport3D.cpp:733:cameraDragActive. Cursor is at the press point because we kept warping it there.