Don't show hands if position is not tracked+valid

This commit is contained in:
Patrick Nicolas
2024-09-05 12:50:55 +02:00
parent a70acbe6d2
commit 0fa694338d
4 changed files with 12 additions and 3 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ hand_model::hand_model(const std::filesystem::path & gltf_path, scene_loader & l
void hand_model::apply(const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & 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;
+2 -2
View File
@@ -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)
+7
View File
@@ -79,3 +79,10 @@ std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> xr::
return joints;
}
bool xr::hand_tracker::check_flags(const std::array<joint, XR_HAND_JOINT_COUNT_EXT> & 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;
});
}
+2
View File
@@ -44,5 +44,7 @@ public:
using joint = std::pair<XrHandJointLocationEXT, XrHandJointVelocityEXT>;
std::optional<std::array<joint, XR_HAND_JOINT_COUNT_EXT>> locate(XrSpace space, XrTime time);
static bool check_flags(const std::array<joint, XR_HAND_JOINT_COUNT_EXT> & joints, XrSpaceLocationFlags position, XrSpaceVelocityFlags velocity);
};
} // namespace xr