From 0fa694338da508e3b2a97fe2ccecc7893a0b689d Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 5 Sep 2024 12:50:55 +0200 Subject: [PATCH] Don't show hands if position is not tracked+valid --- client/scenes/hand_model.cpp | 2 +- client/scenes/lobby.cpp | 4 ++-- client/xr/hand_tracker.cpp | 7 +++++++ client/xr/hand_tracker.h | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/client/scenes/hand_model.cpp b/client/scenes/hand_model.cpp index 1438217a..6a3f0457 100644 --- a/client/scenes/hand_model.cpp +++ b/client/scenes/hand_model.cpp @@ -61,7 +61,7 @@ hand_model::hand_model(const std::filesystem::path & gltf_path, scene_loader & l void hand_model::apply(const std::optional> & joints_location) { - if (joints_location) + if (joints_location and xr::hand_tracker::check_flags(*joints_location, XR_SPACE_LOCATION_POSITION_VALID_BIT | XR_SPACE_LOCATION_POSITION_TRACKED_BIT, 0)) { root_node->visible = true; diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 695640ab..33a22f2b 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -559,7 +559,7 @@ void scenes::lobby::render(const XrFrameState & frame_state) auto joints = hand.locate(world_space, frame_state.predictedDisplayTime); left_hand->apply(joints); - if (joints) + if (joints and xr::hand_tracker::check_flags(*joints, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0)) { hide_left_controller = true; if (!new_gui_position) @@ -573,7 +573,7 @@ void scenes::lobby::render(const XrFrameState & frame_state) auto joints = hand.locate(world_space, frame_state.predictedDisplayTime); right_hand->apply(joints); - if (joints) + if (joints and xr::hand_tracker::check_flags(*joints, XR_SPACE_LOCATION_POSITION_TRACKED_BIT | XR_SPACE_LOCATION_POSITION_VALID_BIT, 0)) { hide_right_controller = true; if (!new_gui_position) diff --git a/client/xr/hand_tracker.cpp b/client/xr/hand_tracker.cpp index 01077aba..2e273c92 100644 --- a/client/xr/hand_tracker.cpp +++ b/client/xr/hand_tracker.cpp @@ -79,3 +79,10 @@ std::optional> xr:: return joints; } + +bool xr::hand_tracker::check_flags(const std::array & joints, XrSpaceLocationFlags position, XrSpaceVelocityFlags velocity) +{ + return std::ranges::all_of(joints, [position, velocity](const auto & joint) { + return (joint.first.locationFlags & position) == position and (joint.second.velocityFlags & velocity) == velocity; + }); +} diff --git a/client/xr/hand_tracker.h b/client/xr/hand_tracker.h index 69439d4d..95cc19f1 100644 --- a/client/xr/hand_tracker.h +++ b/client/xr/hand_tracker.h @@ -44,5 +44,7 @@ public: using joint = std::pair; std::optional> locate(XrSpace space, XrTime time); + + static bool check_flags(const std::array & joints, XrSpaceLocationFlags position, XrSpaceVelocityFlags velocity); }; } // namespace xr