diff --git a/client/constants.h b/client/constants.h index caddd7f1..f35738e0 100644 --- a/client/constants.h +++ b/client/constants.h @@ -123,6 +123,18 @@ constexpr ImVec4 urgent_border_color = {8.f, .6f, 0.f, .8f}; // Dimming for the streamed video when the GUI is interactable constexpr float dimming_scale = 0.4; constexpr float dimming_bias = 0.01; + +constexpr float gui_max_foveation_speed = 2; // Maximum speed (@ 1m) when changing the foveation distance with the thumbstick +constexpr float gui_min_foveation_distance = 0.5; +constexpr float gui_max_foveation_distance = 100; + +constexpr float gui_min_foveation_pitch = -M_PI / 3; +constexpr float gui_max_foveation_pitch = M_PI / 3; + +constexpr float gui_max_layer_speed = 10; // Maximum speed (@ 1m) when changing the GUI distance with the thumbstick +constexpr float gui_min_layer_distance = 0.5; +constexpr float gui_max_layer_distance = 3; + } // namespace constants::stream namespace constants::style diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index b78b50f0..f01036ab 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -506,6 +506,8 @@ void scenes::stream::on_focused() } recenter_left = get_action("recenter_left").first; recenter_right = get_action("recenter_right").first; + gui_distance_left = get_action("gui_distance_left").first; + gui_distance_right = get_action("gui_distance_right").first; settings_adjust = get_action("settings_adjust").first; foveation_distance = get_action("foveation_distance").first; foveation_ok = get_action("foveation_ok").first; @@ -679,7 +681,7 @@ std::shared_ptr scenes::stream::accumulator_imag return frame; } -void scenes::stream::update_gui_position(xr::spaces controller) +void scenes::stream::update_gui_position(xr::spaces controller, float predicted_display_period) { std::optional> aim = application::locate_controller( application::space(controller), @@ -725,7 +727,13 @@ void scenes::stream::update_gui_position(xr::spaces controller) else { // Subsequent frames of recentering: keep the GUI locked to the controller - auto [_, controller_gui_position, controller_gui_orientation] = *recentering_context; + auto & [_, controller_gui_position, controller_gui_orientation] = *recentering_context; + + if (auto gui_distance = application::read_action_float(controller == xr::spaces::aim_left ? gui_distance_left : gui_distance_right)) + { + controller_gui_position.z *= std::pow(constants::stream::gui_max_layer_speed, gui_distance->second * predicted_display_period); + controller_gui_position.z = -std::clamp(-controller_gui_position.z, constants::stream::gui_min_layer_distance, constants::stream::gui_max_layer_distance); + } world_gui_position = world_controller_position + world_controller_orientation * controller_gui_position; world_gui_orientation = world_controller_orientation * controller_gui_orientation; @@ -1207,6 +1215,8 @@ scene::meta & scenes::stream::get_meta_scene() {"recenter_left", XR_ACTION_TYPE_BOOLEAN_INPUT}, {"recenter_right", XR_ACTION_TYPE_BOOLEAN_INPUT}, + {"gui_distance_left", XR_ACTION_TYPE_FLOAT_INPUT}, + {"gui_distance_right", XR_ACTION_TYPE_FLOAT_INPUT}, {"settings_adjust", XR_ACTION_TYPE_FLOAT_INPUT}, {"foveation_distance", XR_ACTION_TYPE_FLOAT_INPUT}, @@ -1241,6 +1251,8 @@ scene::meta & scenes::stream::get_meta_scene() {"recenter_left", "/user/hand/left/input/squeeze/value"}, {"recenter_right", "/user/hand/right/input/squeeze/value"}, + {"gui_distance_left", "/user/hand/left/input/thumbstick/y"}, + {"gui_distance_right", "/user/hand/right/input/thumbstick/y"}, {"settings_adjust", "/user/hand/right/input/thumbstick/y"}, {"foveation_distance", "/user/hand/left/input/thumbstick/y"}, {"foveation_ok", "/user/hand/right/input/a/click"}, diff --git a/client/scenes/stream.h b/client/scenes/stream.h index e506a2b7..e705b75e 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -157,6 +157,8 @@ private: XrAction plots_toggle_2 = XR_NULL_HANDLE; XrAction recenter_left = XR_NULL_HANDLE; XrAction recenter_right = XR_NULL_HANDLE; + XrAction gui_distance_left = XR_NULL_HANDLE; + XrAction gui_distance_right = XR_NULL_HANDLE; XrAction settings_adjust = XR_NULL_HANDLE; XrAction foveation_distance = XR_NULL_HANDLE; XrAction foveation_ok = XR_NULL_HANDLE; @@ -176,7 +178,7 @@ private: // Which controller is used for recentering and position of the GUI relative to the controller, in controller axes, during recentering std::optional> recentering_context; - void update_gui_position(xr::spaces controller); + void update_gui_position(xr::spaces controller, float predicted_display_period); // Keep a reference to the resources needed to blit the images until vkWaitForFences std::array, decoder_count> current_blit_handles; diff --git a/client/scenes/stream_gui.cpp b/client/scenes/stream_gui.cpp index 5ccf0013..6a2af4ed 100644 --- a/client/scenes/stream_gui.cpp +++ b/client/scenes/stream_gui.cpp @@ -508,10 +508,10 @@ void scenes::stream::gui_foveation_settings(float predicted_display_period) float delta_pitch = application::read_action_float(settings_adjust).value_or(std::pair{0, 0}).second * predicted_display_period; // Maximum speed 2m/s @ 1m - float delta_distance = std::exp(std::log(2) * application::read_action_float(foveation_distance).value_or(std::pair{0, 0}).second * predicted_display_period); + float delta_distance = std::pow(constants::stream::gui_max_foveation_speed, application::read_action_float(foveation_distance).value_or(std::pair{0, 0}).second * predicted_display_period); - override_foveation_pitch = std::clamp(override_foveation_pitch + delta_pitch, -M_PI / 3, M_PI / 3); - override_foveation_distance = std::clamp(override_foveation_distance * delta_distance, 0.5, 100); + override_foveation_pitch = std::clamp(override_foveation_pitch + delta_pitch, constants::stream::gui_min_foveation_pitch, constants::stream::gui_max_foveation_pitch); + override_foveation_distance = std::clamp(override_foveation_distance * delta_distance, constants::stream::gui_min_foveation_distance, constants::stream::gui_max_foveation_distance); bool ok = application::read_action_bool(foveation_ok).value_or(std::pair{0, false}).second; bool cancel = application::read_action_bool(foveation_cancel).value_or(std::pair{0, false}).second; @@ -690,7 +690,7 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte case stream_tab::application_launcher: break; } - imgui_ctx->set_controllers_enabled(interactable); + imgui_ctx->set_controllers_enabled(interactable and not recentering_context); if (interactable) { if (system.hand_tracking_supported()) @@ -965,14 +965,14 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte } if (state) - update_gui_position(controller); + update_gui_position(controller, predicted_display_period * 1e-9f); else recentering_context.reset(); } else if (auto state = application::read_action_bool(recenter_left); state and state->second) - update_gui_position(xr::spaces::aim_left); + update_gui_position(xr::spaces::aim_left, predicted_display_period * 1e-9f); else if (auto state = application::read_action_bool(recenter_right); state and state->second) - update_gui_position(xr::spaces::aim_right); + update_gui_position(xr::spaces::aim_right, predicted_display_period * 1e-9f); else recentering_context.reset();