From f01ffd91821295c2288b41d20b5af66a484f90e4 Mon Sep 17 00:00:00 2001 From: Guillaume Meunier Date: Sat, 16 May 2026 17:29:46 +0200 Subject: [PATCH] Use a fixed GUI position in the stream scene when the GUI is interactable --- client/scenes/stream.cpp | 49 ++++++++++-------------------------- client/scenes/stream.h | 6 ++++- client/scenes/stream_gui.cpp | 27 ++++++++++++++++++-- 3 files changed, 43 insertions(+), 39 deletions(-) diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index d8e04dd1..b78b50f0 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -681,50 +681,27 @@ std::shared_ptr scenes::stream::accumulator_imag void scenes::stream::update_gui_position(xr::spaces controller) { - std::optional> aim; - - if (application::get_hmd_traits().view_locate) - { - aim = application::locate_controller( - application::space(controller), - application::space(xr::spaces::view), - predicted_display_time); - } - else - { - // Pico fails to find its controllers within view space, so use the head position in - // world space as a reference - aim = application::locate_controller( - application::space(controller), - application::space(xr::spaces::world), - predicted_display_time); - - auto head_position = application::locate_controller(application::space(xr::spaces::view), - application::space(xr::spaces::world), - predicted_display_time); - if (not(aim and head_position)) - return; - - aim->first = glm::conjugate(head_position->second) * (aim->first - head_position->first); - aim->second = glm::conjugate(head_position->second) * aim->second; - } + std::optional> aim = application::locate_controller( + application::space(controller), + application::space(xr::spaces::world), + predicted_display_time); if (not aim) return; auto [offset_position, offset_orientation] = input->offset[controller]; - auto head_controller_position = aim->first + glm::mat3_cast(aim->second * offset_orientation) * offset_position; - auto head_controller_orientation = aim->second * offset_orientation; - auto head_controller_direction = -glm::column(glm::mat3_cast(head_controller_orientation), 2); + auto world_controller_position = aim->first + glm::mat3_cast(aim->second * offset_orientation) * offset_position; + auto world_controller_orientation = aim->second * offset_orientation; + auto world_controller_direction = -glm::column(glm::mat3_cast(world_controller_orientation), 2); if (not recentering_context) { // First frame of recentering: get the GUI position relative to the controller // Compute the intersection of the ray with the GUI - auto gui_controller_direction = glm::conjugate(head_gui_orientation) * head_controller_direction; - auto gui_controller_position = glm::conjugate(head_gui_orientation) * (head_controller_position - head_gui_position); + auto gui_controller_direction = glm::conjugate(world_gui_orientation) * world_controller_direction; + auto gui_controller_position = glm::conjugate(world_gui_orientation) * (world_controller_position - world_gui_position); float lambda = -gui_controller_position.z / gui_controller_direction.z; auto gui_intersection = gui_controller_position + lambda * gui_controller_direction; @@ -739,8 +716,8 @@ void scenes::stream::update_gui_position(xr::spaces controller) } else { - glm::vec3 controller_gui_position = glm::conjugate(head_controller_orientation) * (head_gui_position - head_controller_position); - glm::quat controller_gui_orientation = glm::conjugate(head_controller_orientation) * head_gui_orientation; + glm::vec3 controller_gui_position = glm::conjugate(world_controller_orientation) * (world_gui_position - world_controller_position); + glm::quat controller_gui_orientation = glm::conjugate(world_controller_orientation) * world_gui_orientation; recentering_context.emplace(controller, controller_gui_position, controller_gui_orientation); } @@ -750,8 +727,8 @@ void scenes::stream::update_gui_position(xr::spaces controller) // Subsequent frames of recentering: keep the GUI locked to the controller auto [_, controller_gui_position, controller_gui_orientation] = *recentering_context; - head_gui_position = head_controller_position + head_controller_orientation * controller_gui_position; - head_gui_orientation = head_controller_orientation * controller_gui_orientation; + world_gui_position = world_controller_position + world_controller_orientation * controller_gui_position; + world_gui_orientation = world_controller_orientation * controller_gui_orientation; } } diff --git a/client/scenes/stream.h b/client/scenes/stream.h index 601427fb..e506a2b7 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -162,10 +162,14 @@ private: XrAction foveation_ok = XR_NULL_HANDLE; XrAction foveation_cancel = XR_NULL_HANDLE; - // Position of the GUI relative to the view space, in view space axes + // Position of the GUI relative to the view space, in view space axes, used when the GUI is not interactable glm::vec3 head_gui_position{-0.1, -0.3, -1.2}; // Shift 10cm left by default so that the stats are centered accounting for the tab list glm::quat head_gui_orientation{1, 0, 0, 0}; + // Position of the GUI relative to the world space, in world space axes, used when the GUI is interactable + glm::vec3 world_gui_position; + glm::quat world_gui_orientation; + bool override_foveation_enable; float override_foveation_pitch; // The pitch is the opposite as the height displayed in the GUI float override_foveation_distance; diff --git a/client/scenes/stream_gui.cpp b/client/scenes/stream_gui.cpp index 2b3ba544..5ccf0013 100644 --- a/client/scenes/stream_gui.cpp +++ b/client/scenes/stream_gui.cpp @@ -17,6 +17,7 @@ * along with this program. If not, see . */ +#include #define IMGUI_DEFINE_MATH_OPERATORS #include "stream.h" @@ -635,6 +636,24 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte if (auto new_status = next_gui_status.load(); new_status != gui_status) { spdlog::info("Switch tab from {} to {}", magic_enum::enum_name(gui_status), magic_enum::enum_name(new_status)); + + if (not is_gui_interactable() and is_interactable(new_status)) + { + if (auto head_position = application::locate_controller(application::space(xr::spaces::view), application::space(xr::spaces::world), predicted_display_time)) + { + world_gui_orientation = head_position->second * head_gui_orientation; + world_gui_position = head_position->first + glm::mat3_cast(head_position->second) * head_gui_position; + } + } + else if (is_gui_interactable() and not is_interactable(new_status)) + { + if (auto head_position = application::locate_controller(application::space(xr::spaces::view), application::space(xr::spaces::world), predicted_display_time)) + { + head_gui_orientation = glm::conjugate(head_position->second) * world_gui_orientation; + head_gui_position = glm::mat3_cast(glm::conjugate(head_position->second)) * (world_gui_position - head_position->first); + } + } + stored_gui_status = gui_status; gui_status = new_status; gui_status_last_change = predicted_display_time; @@ -729,12 +748,16 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte case stream_tab::overlay_only: case stream_tab::compact: + imgui_ctx->layers()[0].orientation = head_position->second * head_gui_orientation; + imgui_ctx->layers()[0].position = head_position->first + M * head_gui_position; + break; + case stream_tab::stats: case stream_tab::settings: case stream_tab::applications: case stream_tab::application_launcher: - imgui_ctx->layers()[0].orientation = head_position->second * head_gui_orientation; - imgui_ctx->layers()[0].position = head_position->first + M * head_gui_position; + imgui_ctx->layers()[0].orientation = world_gui_orientation; + imgui_ctx->layers()[0].position = world_gui_position; break; } }