feat(client): add per-posture player height offset setting (#1121)

This commit is contained in:
moi952
2026-09-29 23:21:55 +02:00
committed by GitHub
parent a083901bdc
commit 85f6cb0bd9
8 changed files with 149 additions and 9 deletions
+33 -1
View File
@@ -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<setting> list;
std::vector<setting> 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<std::string>{_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;
}
+8 -1
View File
@@ -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
+5
View File
@@ -81,6 +81,11 @@ class lobby : public scene_impl<lobby>
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<utils::mapped_file> license;
+2
View File
@@ -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"
+24 -7
View File
@@ -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);