Use a fixed GUI position in the stream scene when the GUI is interactable

This commit is contained in:
Guillaume Meunier
2026-06-05 20:43:35 +02:00
parent 95a5283b51
commit f01ffd9182
3 changed files with 43 additions and 39 deletions
+13 -36
View File
@@ -681,50 +681,27 @@ std::shared_ptr<shard_accumulator::blit_handle> scenes::stream::accumulator_imag
void scenes::stream::update_gui_position(xr::spaces controller)
{
std::optional<std::pair<glm::vec3, glm::quat>> 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<std::pair<glm::vec3, glm::quat>> 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;
}
}
+5 -1
View File
@@ -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;
+25 -2
View File
@@ -17,6 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <glm/ext/quaternion_common.hpp>
#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;
}
}