diff --git a/client/configuration.cpp b/client/configuration.cpp index 79cb2728..92ca4414 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -348,6 +348,9 @@ const std::vector & configuration::config_fields() scalar("codec", &configuration::codec), scalar("bit_depth", &configuration::bit_depth), scalar("usb_network", &configuration::usb_network), + scalar("height_offset_standing", &configuration::height_offset_standing), + scalar("height_offset_seated", &configuration::height_offset_seated), + scalar("default_posture", &configuration::default_posture), }; return fields; } @@ -414,3 +417,27 @@ float configuration::get_default_stream_scale() const return 0.3; return 0.5; } + +float configuration::get_height_offset() const +{ + std::lock_guard lock(mutex); + return default_posture == posture::seated ? height_offset_seated : height_offset_standing; +} + +void configuration::set_height_offset(float value) +{ + std::lock_guard lock(mutex); + (default_posture == posture::seated ? height_offset_seated : height_offset_standing) = value; +} + +posture configuration::get_posture() const +{ + std::lock_guard lock(mutex); + return default_posture; +} + +void configuration::set_posture(posture p) +{ + std::lock_guard lock(mutex); + default_posture = p; +} diff --git a/client/configuration.h b/client/configuration.h index b4134fa2..f5b51c83 100644 --- a/client/configuration.h +++ b/client/configuration.h @@ -50,6 +50,12 @@ enum class feature body_tracking, }; +enum class posture +{ + standing, + seated, +}; + class configuration { public: @@ -128,10 +134,16 @@ public: bool check_feature(feature f) const; void set_feature(feature f, bool state); + static constexpr float default_height_offset_standing = 0; + static constexpr float default_height_offset_seated = 0.45; + private: mutable std::mutex mutex; std::map features; std::optional stream_scale; + float height_offset_standing = default_height_offset_standing; + float height_offset_seated = default_height_offset_seated; + posture default_posture = posture::standing; // table of scalar settings shared by save()/load(); non-scalar settings are explicit static const std::vector & config_fields(); @@ -146,6 +158,12 @@ public: float get_stream_scale() const; float get_default_stream_scale() const; + float get_height_offset() const; + void set_height_offset(float); + + posture get_posture() const; + void set_posture(posture); + uint32_t max_bitrate(bool extended) const { return extended ? 800'000'000u : 200'000'000u; diff --git a/client/scenes/gui_settings.cpp b/client/scenes/gui_settings.cpp index ff27dc71..d9607f9a 100644 --- a/client/scenes/gui_settings.cpp +++ b/client/scenes/gui_settings.cpp @@ -31,6 +31,7 @@ #include "render/imgui_impl.h" #include "render/ui_theme.h" #include "render/ui_widgets.h" +#include "stream.h" #include "utils/i18n.h" #include "xr/instance.h" #include "xr/session.h" @@ -586,7 +587,37 @@ bool settings_tracking(const settings_context & ctx) auto & config = ctx.config; auto & default_config = ctx.default_config; const std::string disconnect_tip = ctx.in_game ? _C("tooltip for disabled settings", "Disconnect to change this setting.") : std::string{}; - std::vector list; + std::vector list, posture_items; + + const posture current_posture = config.get_posture(); + const bool seated = current_posture == posture::seated; + const float default_height_offset = seated ? configuration::default_height_offset_seated : configuration::default_height_offset_standing; + + posture_items.push_back({ + .id = "##posture", + .label = _C("setting name", "Posture"), + .description = _("Posture assumed when a stream connects."), + .ui = ui_kind::segmented, + .get_int = [seated] { return seated ? 1 : 0; }, + .set_int = [&config](int v) { config.set_posture(v ? posture::seated : posture::standing); config.save(); }, + .options = [] { return std::vector{_C("posture", "Standing"), _C("posture", "Seated")}; }, + .default_int = default_config.get_posture() == posture::seated ? 1 : 0, + }); + + posture_items.push_back({ + .id = "##height_offset", + .label = _C("setting name", "Height adjustment"), + .description = seated + ? _("Corrects the height reported to the PC when seated, useful for games without native seated support.") + : _("Corrects the height reported to the PC when standing, useful for a miscalibrated floor."), + .ui = ui_kind::slider, + .get_int = [&config] { return int(std::lround(config.get_height_offset() * 100)); }, + .set_int = [&config](int v) { config.set_height_offset(v / 100.f); config.save(); }, + .v_min = -30, + .v_max = 70, + .fmt = "%d cm", + .default_int = int(std::lround(default_height_offset * 100)), + }); auto feature_toggle = [&](const char * id, std::string label, std::string desc, feature f) { list.push_back({ @@ -676,6 +707,7 @@ bool settings_tracking(const settings_context & ctx) ui::page_header(_cS("page header title", "Tracking"), _cS("page header subtitle", "Body and input tracking sent to the PC.")); render_settings(ctx, "##tracking", list); + render_settings(ctx, "##posture", posture_items); return changed; } diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 931ad157..158fa79b 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -946,7 +946,14 @@ void scenes::lobby::render(const XrFrameState & frame_state) renderdoc_begin(*vk_instance); #endif - XrSpace world_space = application::space(xr::spaces::world); + // Locating everything against this instead of the raw world space lets the configured + // player height offset be previewed here, the same shift a stream would apply. + if (float offset = application::get_config().get_height_offset(); not height_offset_space or offset != applied_height_offset) + { + applied_height_offset = offset; + height_offset_space = session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE, {{0, 0, 0, 1}, {0, -offset, 0}}); + } + XrSpace world_space = height_offset_space; auto [flags, views] = session.locate_views(viewconfig, frame_state.predictedDisplayTime, world_space); // assert(views.size() == swapchains_lobby.size()); assert(views.size() == 2); // FIXME diff --git a/client/scenes/lobby.h b/client/scenes/lobby.h index 31e900d8..a14d645e 100644 --- a/client/scenes/lobby.h +++ b/client/scenes/lobby.h @@ -81,6 +81,11 @@ class lobby : public scene_impl xr::face_tracker face_tracker; + // STAGE space translated by the configured player height offset, so it previews here the + // same shift a stream would apply; recreated only when the offset actually changes. + xr::space height_offset_space; + float applied_height_offset = 0; + std::string selected_item; std::unique_ptr license; diff --git a/client/scenes/stream.h b/client/scenes/stream.h index 0829716b..4fa5d494 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -20,7 +20,9 @@ #pragma once #include "app_launcher.h" +#include "application.h" #include "audio/audio.h" +#include "configuration.h" #include "decoder/shard_accumulator.h" #include "render/imgui_impl.h" #include "scene.h" diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index b74516b4..15f07984 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -271,7 +271,17 @@ void scenes::stream::tracking() } XrSpace view_space = application::space(xr::spaces::view); - XrSpace world_space = application::space(xr::spaces::world); + + // poses sent to the PC are located against this space instead of xr::spaces::world + // directly, so the configured player height offset applies uniformly to the head, hands + // and body. It shares xr::spaces::world's STAGE origin, translated by -offset: locating a + // pose in it therefore reports that pose offset up by +offset, i.e. increases perceived + // height. + auto make_height_offset_space = [&](float offset) { + return session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE, {{0, 0, 0, 1}, {0, -offset, 0}}); + }; + float applied_height_offset = config.get_height_offset(); + xr::space height_offset_space = make_height_offset_space(applied_height_offset); XrTime t0 = instance.now(); from_headset::tracking tracking; @@ -291,7 +301,7 @@ void scenes::stream::tracking() const bool body_tracking = config.check_feature(feature::body_tracking); xr::body_tracker body_tracker; - locate_spaces_functor locate_spaces{instance, world_space}; + locate_spaces_functor locate_spaces{instance, height_offset_space}; on_interaction_profile_changed({}); @@ -305,6 +315,13 @@ void scenes::stream::tracking() { try { + if (float offset = config.get_height_offset(); offset != applied_height_offset) + { + applied_height_offset = offset; + height_offset_space = make_height_offset_space(applied_height_offset); + locate_spaces = locate_spaces_functor{instance, height_offset_space}; + } + if (pattern_position == pattern.size()) { // Upper limit to 200FPS @@ -457,8 +474,8 @@ void scenes::stream::tracking() else { // Pico headsets fail to locate gaze relative to view - auto gaze = locate_space(item.device, spaces[item.device], world_space, tracking.timestamp); - auto view_pose = locate_space(item.device, view_space, world_space, tracking.timestamp); + auto gaze = locate_space(item.device, spaces[item.device], height_offset_space, tracking.timestamp); + auto view_pose = locate_space(item.device, view_space, height_offset_space, tracking.timestamp); glm::quat gaze_quat(gaze.pose.orientation.w, gaze.pose.orientation.x, gaze.pose.orientation.y, gaze.pose.orientation.z); glm::quat view_quat(view_pose.pose.orientation.w, view_pose.pose.orientation.x, view_pose.pose.orientation.y, view_pose.pose.orientation.z); gaze_quat = glm::conjugate(view_quat) * gaze_quat; @@ -495,7 +512,7 @@ void scenes::stream::tracking() t0, at_time, from_headset::hand_tracking::left, - locate_hands(*left_hand, world_space, tracking.timestamp)); + locate_hands(*left_hand, height_offset_space, tracking.timestamp)); } break; case wivrn::device_id::RIGHT_HAND: @@ -505,14 +522,14 @@ void scenes::stream::tracking() t0, at_time, from_headset::hand_tracking::right, - locate_hands(*right_hand, world_space, tracking.timestamp)); + locate_hands(*right_hand, height_offset_space, tracking.timestamp)); } break; case wivrn::device_id::BODY: std::visit(utils::overloaded{ [](std::monostate &) {}, [&](auto & b) { - auto packet = b.locate_spaces(at_time, world_space); + auto packet = b.locate_spaces(at_time, height_offset_space); packet.timestamp = at_time; packet.production_timestamp = tracking.production_timestamp; body.push_back(packet); diff --git a/locale/fr/wivrn.po b/locale/fr/wivrn.po index 6d2cdd18..8e7c83ec 100644 --- a/locale/fr/wivrn.po +++ b/locale/fr/wivrn.po @@ -395,6 +395,38 @@ msgstr "Envoie les périphériques d'entrée du casque au PC." msgid "The server does not allow forwarded input devices" msgstr "Le serveur n'autorise pas les périphériques virtuels" +#: client/scenes/gui_settings.cpp:592 +msgctxt "setting name" +msgid "Posture" +msgstr "Posture" + +#: client/scenes/gui_settings.cpp:594 +msgid "Posture assumed when a stream connects." +msgstr "Posture appliquée à la connexion." + +#: client/scenes/gui_settings.cpp:605 +msgctxt "posture" +msgid "Standing" +msgstr "Debout" + +#: client/scenes/gui_settings.cpp:605 +msgctxt "posture" +msgid "Seated" +msgstr "Assis" + +#: client/scenes/gui_settings.cpp:611 +msgctxt "setting name" +msgid "Height adjustment" +msgstr "Ajustement de la hauteur" + +#: client/scenes/gui_settings.cpp:604 +msgid "Corrects the height reported to the PC when seated, useful for games without native seated support." +msgstr "Corrige la hauteur transmise au PC en position assise, utile pour les jeux sans mode assis natif." + +#: client/scenes/gui_settings.cpp:605 +msgid "Corrects the height reported to the PC when standing, useful for a miscalibrated floor." +msgstr "Corrige la hauteur transmise au PC en position debout, utile si le sol est mal calibré." + #: client/scenes/gui_settings.cpp:597 msgctxt "setting name" msgid "Hand tracking"