Use separate packet to send generic tracker poses

This commit is contained in:
Sapphire
2025-06-08 18:07:23 +02:00
committed by xytovl
parent 460fbec06d
commit 1d6b444ec6
13 changed files with 145 additions and 130 deletions
+17 -28
View File
@@ -21,6 +21,8 @@
#include "xr/xr.h"
#include <openxr/openxr.h>
static_assert(xr::pico_body_tracker::joint_whitelist.size() <= wivrn::from_headset::body_tracking::max_tracked_poses);
static PFN_xrDestroyBodyTrackerBD xrDestroyBodyTrackerBD{};
XrResult xr::destroy_pico_body_tracker(XrBodyTrackerBD id)
@@ -34,24 +36,11 @@ xr::pico_body_tracker::pico_body_tracker(instance & inst, XrBodyTrackerBD h)
xrLocateBodyJointsBD = inst.get_proc<PFN_xrLocateBodyJointsBD>("xrLocateBodyJointsBD");
}
void xr::pico_body_tracker::locate_spaces(XrTime time, std::vector<wivrn::from_headset::tracking::pose> & out_poses, XrSpace reference)
std::optional<std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses>> xr::pico_body_tracker::locate_spaces(XrTime time, XrSpace reference)
{
auto fill_poses = [&]() {
for (auto _: joint_whitelist)
{
wivrn::from_headset::tracking::pose pose{
.pose = {},
.device = wivrn::device_id::GENERIC_TRACKER,
.flags = 0,
};
out_poses.push_back(std::move(pose));
}
};
if (!xrLocateBodyJointsBD)
{
fill_poses();
return;
return std::nullopt;
}
XrBodyJointsLocateInfoBD locate_info{
@@ -72,28 +61,28 @@ void xr::pico_body_tracker::locate_spaces(XrTime time, std::vector<wivrn::from_h
if (auto res = xrLocateBodyJointsBD(id, &locate_info, &joint_locations); !XR_SUCCEEDED(res))
{
spdlog::warn("Unable to get body joints: xrLocateBodyJointsBD returned {}", xr::to_string(res));
fill_poses();
return;
return std::nullopt;
}
for (auto & joint: joint_whitelist)
std::array<wivrn::from_headset::body_tracking::pose, wivrn::from_headset::body_tracking::max_tracked_poses> poses{};
for (int i = 0; i < joint_whitelist.size(); i++)
{
auto & joint_location = joints[joint];
wivrn::from_headset::tracking::pose pose{
auto & joint_location = joints[joint_whitelist[i]];
wivrn::from_headset::body_tracking::pose pose{
.pose = joint_location.pose,
.device = wivrn::device_id::GENERIC_TRACKER,
.flags = 0,
};
if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
pose.flags |= wivrn::from_headset::tracking::position_valid;
if (joint_location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
pose.flags |= wivrn::from_headset::tracking::orientation_valid;
if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
pose.flags |= wivrn::from_headset::tracking::position_tracked;
pose.flags |= wivrn::from_headset::body_tracking::orientation_valid;
if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT)
pose.flags |= wivrn::from_headset::body_tracking::position_valid;
if (joint_location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT)
pose.flags |= wivrn::from_headset::tracking::orientation_tracked;
pose.flags |= wivrn::from_headset::body_tracking::orientation_tracked;
if (joint_location.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
pose.flags |= wivrn::from_headset::body_tracking::position_tracked;
out_poses.push_back(std::move(pose));
poses[i] = std::move(pose);
}
return poses;
}