You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
Keep mouse inside 3D viewport rotation widget
Hide and keep the mouse in place when the user oribts the scene via the 3D
rotation widget.
(cherry picked from commit 051f02a3a0)
This commit is contained in:
@@ -195,12 +195,20 @@ void ViewportRotationControl::_gui_input(Ref<InputEvent> p_event) {
|
||||
_update_focus();
|
||||
}
|
||||
orbiting = false;
|
||||
if (Input::get_singleton()->get_mouse_mode() == Input::MOUSE_MODE_CAPTURED) {
|
||||
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
|
||||
Input::get_singleton()->warp_mouse_position(orbiting_mouse_start);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const Ref<InputEventMouseMotion> mm = p_event;
|
||||
if (mm.is_valid()) {
|
||||
if (orbiting) {
|
||||
if (Input::get_singleton()->get_mouse_mode() == Input::MOUSE_MODE_VISIBLE) {
|
||||
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
|
||||
orbiting_mouse_start = mm->get_global_position();
|
||||
}
|
||||
viewport->_nav_orbit(mm, viewport->_get_warped_mouse_motion(mm));
|
||||
focused_axis = -1;
|
||||
} else {
|
||||
@@ -2182,14 +2190,14 @@ void SpatialEditorViewport::set_freelook_active(bool active_now) {
|
||||
}
|
||||
|
||||
// Hide mouse like in an FPS (warping doesn't work)
|
||||
OS::get_singleton()->set_mouse_mode(OS::MOUSE_MODE_CAPTURED);
|
||||
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
|
||||
|
||||
} else if (freelook_active && !active_now) {
|
||||
// Sync camera cursor to cursor to "cut" interpolation jumps due to changing referential
|
||||
cursor = camera_cursor;
|
||||
|
||||
// Restore mouse
|
||||
OS::get_singleton()->set_mouse_mode(OS::MOUSE_MODE_VISIBLE);
|
||||
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
|
||||
}
|
||||
|
||||
freelook_active = active_now;
|
||||
|
||||
Reference in New Issue
Block a user