From 534b4c23e33e8ce398b8c3e177c62996003fbb23 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Wed, 18 Mar 2026 18:25:11 -0500 Subject: [PATCH] Use shared pose_flags enum in packets --- client/scenes/stream_tracking.cpp | 62 ++++------------------ client/xr/fb_body_tracker.cpp | 20 ++----- client/xr/htc_body_tracker.cpp | 15 +----- client/xr/pico_body_tracker.cpp | 10 +--- common/wivrn_packets.h | 69 +++++++++++-------------- server/compositor/foveation.cpp | 2 +- server/driver/hand_joints_list.cpp | 26 +--------- server/driver/pose_list.cpp | 8 +-- server/driver/wivrn_body_tracker.cpp | 40 ++------------ server/driver/wivrn_generic_tracker.cpp | 19 +------ server/driver/xrt_cast.cpp | 20 +++++++ server/driver/xrt_cast.h | 2 + 12 files changed, 80 insertions(+), 213 deletions(-) diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index 206f3602..cfddf7a0 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -35,30 +35,6 @@ #include "android/battery.h" #endif -static uint8_t cast_flags(XrSpaceLocationFlags location, XrSpaceVelocityFlags velocity) -{ - uint8_t flags = 0; - if (location & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) - flags |= from_headset::tracking::orientation_valid; - - if (location & XR_SPACE_LOCATION_POSITION_VALID_BIT) - flags |= from_headset::tracking::position_valid; - - if (velocity & XR_SPACE_VELOCITY_LINEAR_VALID_BIT) - flags |= from_headset::tracking::linear_velocity_valid; - - if (velocity & XR_SPACE_VELOCITY_ANGULAR_VALID_BIT) - flags |= from_headset::tracking::angular_velocity_valid; - - if (location & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) - flags |= from_headset::tracking::orientation_tracked; - - if (location & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) - flags |= from_headset::tracking::position_tracked; - - return flags; -} - namespace { @@ -81,7 +57,7 @@ from_headset::tracking::pose locate_space(device_id device, XrSpace space, XrSpa .linear_velocity = velocity.linearVelocity, .angular_velocity = velocity.angularVelocity, .device = device, - .flags = cast_flags(location.locationFlags, velocity.velocityFlags), + .flags = from_headset::to_pose_flags(location.locationFlags, velocity.velocityFlags), }; spdlog::warn("xrLocateSpace failed for {}: {}", magic_enum::enum_name(device), xr::to_string(res)); return {.device = device}; @@ -168,7 +144,7 @@ public: .linear_velocity = velocity.linearVelocity, .angular_velocity = velocity.angularVelocity, .device = devices[i], - .flags = cast_flags(location.locationFlags, velocity.velocityFlags), + .flags = from_headset::to_pose_flags(location.locationFlags, velocity.velocityFlags), }); } } @@ -191,31 +167,15 @@ static std::optional poses; for (int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++) { + const auto & joint = (*joints)[i]; poses[i] = { - .position = (*joints)[i].first.pose.position, - .orientation = pack((*joints)[i].first.pose.orientation), - .linear_velocity = (*joints)[i].second.linearVelocity, - .angular_velocity = (*joints)[i].second.angularVelocity, - .radius = uint16_t((*joints)[i].first.radius * 10'000), + .position = joint.first.pose.position, + .orientation = pack(joint.first.pose.orientation), + .linear_velocity = joint.second.linearVelocity, + .angular_velocity = joint.second.angularVelocity, + .radius = uint16_t(joint.first.radius * 10'000), + .flags = from_headset::to_pose_flags(joint.first.locationFlags, joint.second.velocityFlags), }; - - if ((*joints)[i].first.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) - poses[i].flags |= from_headset::hand_tracking::orientation_valid; - - if ((*joints)[i].first.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) - poses[i].flags |= from_headset::hand_tracking::position_valid; - - if ((*joints)[i].second.velocityFlags & XR_SPACE_VELOCITY_LINEAR_VALID_BIT) - poses[i].flags |= from_headset::hand_tracking::linear_velocity_valid; - - if ((*joints)[i].second.velocityFlags & XR_SPACE_VELOCITY_ANGULAR_VALID_BIT) - poses[i].flags |= from_headset::hand_tracking::angular_velocity_valid; - - if ((*joints)[i].first.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) - poses[i].flags |= from_headset::hand_tracking::orientation_tracked; - - if ((*joints)[i].first.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) - poses[i].flags |= from_headset::hand_tracking::position_tracked; } return poses; @@ -503,7 +463,7 @@ void scenes::stream::tracking() 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; - using flags = from_headset::tracking::flags; + using flags = from_headset::pose_flags; tracking.device_poses.push_back( from_headset::tracking::pose{ // Zero position and velocities @@ -798,7 +758,7 @@ void scenes::stream::send_derived_pose() else { if (auto pose = locate_space(target, target_space, source_space, now); - pose.flags & from_headset::tracking::position_valid and pose.flags & from_headset::tracking::orientation_valid) + pose.flags & from_headset::pose_flags::position_valid and pose.flags & from_headset::pose_flags::orientation_valid) { network_session->send_control(from_headset::derived_pose{ .source = source, diff --git a/client/xr/fb_body_tracker.cpp b/client/xr/fb_body_tracker.cpp index 11856ef3..f8b6f8b1 100644 --- a/client/xr/fb_body_tracker.cpp +++ b/client/xr/fb_body_tracker.cpp @@ -19,6 +19,7 @@ #include "fb_body_tracker.h" #include "spdlog/spdlog.h" #include "utils/overloaded.h" +#include "wivrn_packets.h" #include "xr/instance.h" #include "xr/session.h" #include "xr/to_string.h" @@ -26,21 +27,6 @@ #include #include -static uint8_t convert_flags(XrSpaceLocationFlags in_flags) -{ - uint8_t flags{}; - if (in_flags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) - flags |= wivrn::from_headset::meta_body::orientation_valid; - if (in_flags & XR_SPACE_LOCATION_POSITION_VALID_BIT) - flags |= wivrn::from_headset::meta_body::position_valid; - if (in_flags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) - flags |= wivrn::from_headset::meta_body::orientation_tracked; - if (in_flags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) - flags |= wivrn::from_headset::meta_body::position_tracked; - - return flags; -} - xr::fb_body_tracker::fb_body_tracker(instance & inst, session & s, bool lower_body) : handle(inst.get_proc("xrDestroyBodyTrackerFB")), xrRequestBodyTrackingFidelityMETA(inst.get_proc("xrRequestBodyTrackingFidelityMETA")), @@ -110,7 +96,7 @@ xr::fb_body_tracker::packet_type xr::fb_body_tracker::locate_spaces(XrTime time, o.root = { .position = root.pose.position, .orientation = pack(root.pose.orientation), - .flags = convert_flags(root.locationFlags), + .flags = wivrn::from_headset::to_pose_flags(root.locationFlags), }; for (size_t joint = XR_BODY_JOINT_HIPS_FB; joint < std::size(o.joints) + 1; joint++) { @@ -121,7 +107,7 @@ xr::fb_body_tracker::packet_type xr::fb_body_tracker::locate_spaces(XrTime time, .y = int16_t((loc.pose.position.y - root.pose.position.y) * 10'000.f), .z = int16_t((loc.pose.position.z - root.pose.position.z) * 10'000.f)}, .orientation = pack(loc.pose.orientation), - .flags = convert_flags(loc.locationFlags), + .flags = wivrn::from_headset::to_pose_flags(loc.locationFlags), }; } }, diff --git a/client/xr/htc_body_tracker.cpp b/client/xr/htc_body_tracker.cpp index dcddb2d1..e4c467f6 100644 --- a/client/xr/htc_body_tracker.cpp +++ b/client/xr/htc_body_tracker.cpp @@ -19,6 +19,7 @@ */ #include "htc_body_tracker.h" +#include "wivrn_packets.h" #include "xr/details/enumerate.h" #include "xr/session.h" #include @@ -72,21 +73,9 @@ static wivrn::from_headset::htc_body::pose locate_space(XrSpace space, XrSpace r wivrn::from_headset::htc_body::pose res{ .pose = location.pose, - .flags = 0, + .flags = wivrn::from_headset::to_pose_flags(location.locationFlags), }; - if (location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) - res.flags |= wivrn::from_headset::htc_body::orientation_valid; - - if (location.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) - res.flags |= wivrn::from_headset::htc_body::position_valid; - - if (location.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) - res.flags |= wivrn::from_headset::htc_body::orientation_tracked; - - if (location.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) - res.flags |= wivrn::from_headset::htc_body::position_tracked; - return res; } diff --git a/client/xr/pico_body_tracker.cpp b/client/xr/pico_body_tracker.cpp index 9f133fa3..fafde5bc 100644 --- a/client/xr/pico_body_tracker.cpp +++ b/client/xr/pico_body_tracker.cpp @@ -18,6 +18,7 @@ #include "pico_body_tracker.h" #include "spdlog/spdlog.h" +#include "wivrn_packets.h" #include "xr/instance.h" #include "xr/session.h" #include "xr/to_string.h" @@ -73,15 +74,8 @@ xr::pico_body_tracker::packet_type xr::pico_body_tracker::locate_spaces(XrTime t ret.joints[joint] = { .position = joint_loc.pose.position, .orientation = pack(joint_loc.pose.orientation), + .flags = wivrn::from_headset::to_pose_flags(joint_loc.locationFlags), }; - if (joint_loc.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) - ret.joints[joint].flags |= wivrn::from_headset::bd_body::orientation_valid; - if (joint_loc.locationFlags & XR_SPACE_LOCATION_POSITION_VALID_BIT) - ret.joints[joint].flags |= wivrn::from_headset::bd_body::position_valid; - if (joint_loc.locationFlags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) - ret.joints[joint].flags |= wivrn::from_headset::bd_body::orientation_tracked; - if (joint_loc.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) - ret.joints[joint].flags |= wivrn::from_headset::bd_body::position_tracked; } return ret; diff --git a/common/wivrn_packets.h b/common/wivrn_packets.h index f36f8599..d4d7f319 100644 --- a/common/wivrn_packets.h +++ b/common/wivrn_packets.h @@ -327,18 +327,37 @@ struct handshake // Sending this on TCP means connection will be TCP only }; +enum pose_flags : uint8_t +{ + orientation_valid = 1 << 0, + position_valid = 1 << 1, + linear_velocity_valid = 1 << 2, + angular_velocity_valid = 1 << 3, + orientation_tracked = 1 << 4, + position_tracked = 1 << 5 +}; + +inline uint8_t to_pose_flags(XrSpaceLocationFlags location_flags, XrSpaceVelocityFlags velocity_flags = 0) +{ + uint8_t flags{}; + if (location_flags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT) + flags |= pose_flags::orientation_valid; + if (location_flags & XR_SPACE_LOCATION_POSITION_VALID_BIT) + flags |= pose_flags::position_valid; + if (location_flags & XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT) + flags |= pose_flags::orientation_tracked; + if (location_flags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT) + flags |= pose_flags::position_tracked; + + if (velocity_flags & XR_SPACE_VELOCITY_LINEAR_VALID_BIT) + flags |= pose_flags::linear_velocity_valid; + if (velocity_flags & XR_SPACE_VELOCITY_ANGULAR_VALID_BIT) + flags |= pose_flags::angular_velocity_valid; + return flags; +} + struct tracking { - enum flags : uint8_t - { - orientation_valid = 1 << 0, - position_valid = 1 << 1, - linear_velocity_valid = 1 << 2, - angular_velocity_valid = 1 << 3, - orientation_tracked = 1 << 4, - position_tracked = 1 << 5 - }; - enum state_flags : uint8_t { recentered = 1 << 0, @@ -413,15 +432,6 @@ struct derived_pose struct hand_tracking { - enum flags : uint8_t - { - orientation_valid = 1 << 0, - position_valid = 1 << 1, - linear_velocity_valid = 1 << 2, - angular_velocity_valid = 1 << 3, - orientation_tracked = 1 << 4, - position_tracked = 1 << 5 - }; enum hand_id : uint8_t { left, @@ -447,13 +457,6 @@ struct hand_tracking struct meta_body { - enum flags : uint8_t - { - orientation_valid = 1 << 0, - position_valid = 1 << 1, - orientation_tracked = 1 << 2, - position_tracked = 1 << 3, - }; struct pose { XrVector3f position; @@ -504,13 +507,6 @@ struct meta_body_skeleton struct bd_body { - enum flags : uint8_t - { - orientation_valid = 1 << 0, - position_valid = 1 << 1, - orientation_tracked = 1 << 2, - position_tracked = 1 << 3, - }; struct pose { XrVector3f position; @@ -527,13 +523,6 @@ struct bd_body struct htc_body { inline static const size_t max_tracked_poses = 16; - enum flags : uint8_t - { - orientation_valid = 1 << 0, - position_valid = 1 << 1, - orientation_tracked = 1 << 2, - position_tracked = 1 << 3, - }; struct pose { XrPosef pose{}; diff --git a/server/compositor/foveation.cpp b/server/compositor/foveation.cpp index 7e255e2a..b973da65 100644 --- a/server/compositor/foveation.cpp +++ b/server/compositor/foveation.cpp @@ -431,7 +431,7 @@ void foveation::update_tracking(const from_headset::tracking & tracking) { std::lock_guard lock(mutex); - const uint8_t orientation_ok = from_headset::tracking::orientation_valid | from_headset::tracking::orientation_tracked; + const uint8_t orientation_ok = from_headset::pose_flags::orientation_valid | from_headset::pose_flags::orientation_tracked; if (tracking.view_flags & XR_VIEW_STATE_POSITION_VALID_BIT) { diff --git a/server/driver/hand_joints_list.cpp b/server/driver/hand_joints_list.cpp index ae2dbfae..02bc8384 100644 --- a/server/driver/hand_joints_list.cpp +++ b/server/driver/hand_joints_list.cpp @@ -20,6 +20,7 @@ #include "hand_joints_list.h" #include "math/m_space.h" #include "pose_list.h" +#include "wivrn_packets.h" #include "xrt_cast.h" static_assert(XRT_HAND_JOINT_COUNT == XR_HAND_JOINT_COUNT_EXT); @@ -53,33 +54,10 @@ xrt_hand_joint_set hand_joints_list::extrapolate(const xrt_hand_joint_set & a, c return t <= ta ? a : b; } -static xrt_space_relation_flags cast_flags(uint8_t in_flags) -{ - std::underlying_type_t flags = 0; - if (in_flags & from_headset::hand_tracking::position_valid) - flags |= XRT_SPACE_RELATION_POSITION_VALID_BIT; - - if (in_flags & from_headset::hand_tracking::orientation_valid) - flags |= XRT_SPACE_RELATION_ORIENTATION_VALID_BIT; - - if (in_flags & from_headset::hand_tracking::linear_velocity_valid) - flags |= XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT; - - if (in_flags & from_headset::hand_tracking::angular_velocity_valid) - flags |= XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT; - - if (in_flags & from_headset::hand_tracking::position_tracked) - flags |= XRT_SPACE_RELATION_POSITION_TRACKED_BIT; - - if (in_flags & from_headset::hand_tracking::orientation_tracked) - flags |= XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT; - return xrt_space_relation_flags(flags); -} - static xrt_space_relation to_relation(const from_headset::hand_tracking::pose & pose) { return { - .relation_flags = cast_flags(pose.flags), + .relation_flags = from_pose_flags(pose.flags), .pose = xrt_cast(XrPosef{ .orientation = pose.orientation, .position = pose.position, diff --git a/server/driver/pose_list.cpp b/server/driver/pose_list.cpp index 1b0c6868..a19291ca 100644 --- a/server/driver/pose_list.cpp +++ b/server/driver/pose_list.cpp @@ -166,19 +166,19 @@ void pose_list::add_sample(XrTime production_timestamp, XrTime timestamp, const // TODO keep the tracked flag polynomial_interpolator<3>::sample position{production_timestamp, timestamp}; - if (pose.flags & from_headset::tracking::position_valid) + if (pose.flags & from_headset::pose_flags::position_valid) position.y.emplace( pose.pose.position.x, pose.pose.position.y, pose.pose.position.z); - if (pose.flags & from_headset::tracking::linear_velocity_valid) + if (pose.flags & from_headset::pose_flags::linear_velocity_valid) position.dy.emplace( pose.linear_velocity.x, pose.linear_velocity.y, pose.linear_velocity.z); polynomial_interpolator<4, true>::sample orientation{production_timestamp, timestamp}; - if (pose.flags & from_headset::tracking::orientation_valid) + if (pose.flags & from_headset::pose_flags::orientation_valid) { orientation.y.emplace( pose.pose.orientation.w, @@ -186,7 +186,7 @@ void pose_list::add_sample(XrTime production_timestamp, XrTime timestamp, const pose.pose.orientation.y, pose.pose.orientation.z); - if (pose.flags & from_headset::tracking::angular_velocity_valid) + if (pose.flags & from_headset::pose_flags::angular_velocity_valid) { Eigen::Quaternionf q{ pose.pose.orientation.w, diff --git a/server/driver/wivrn_body_tracker.cpp b/server/driver/wivrn_body_tracker.cpp index a358df0f..7308af5a 100644 --- a/server/driver/wivrn_body_tracker.cpp +++ b/server/driver/wivrn_body_tracker.cpp @@ -34,44 +34,10 @@ static_assert(std::to_underlying(XR_BODY_JOINT_COUNT_FB) == std::to_underlying(X static_assert(std::to_underlying(XR_FULL_BODY_JOINT_COUNT_META) == std::to_underlying(XRT_FULL_BODY_JOINT_COUNT_META)); static_assert(XR_BODY_JOINT_COUNT_BD == XRT_BODY_JOINT_COUNT_BD); -static xrt_space_relation_flags cast_meta_flags(uint8_t in_flags) -{ - std::underlying_type_t flags = 0; - if (in_flags & wivrn::from_headset::meta_body::position_valid) - flags |= XRT_SPACE_RELATION_POSITION_VALID_BIT; - - if (in_flags & wivrn::from_headset::meta_body::orientation_valid) - flags |= XRT_SPACE_RELATION_ORIENTATION_VALID_BIT; - - if (in_flags & wivrn::from_headset::meta_body::position_tracked) - flags |= XRT_SPACE_RELATION_POSITION_TRACKED_BIT; - - if (in_flags & wivrn::from_headset::meta_body::orientation_tracked) - flags |= XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT; - return xrt_space_relation_flags(flags); -} - -static xrt_space_relation_flags cast_bd_flags(uint8_t in_flags) -{ - std::underlying_type_t flags = 0; - if (in_flags & wivrn::from_headset::bd_body::position_valid) - flags |= XRT_SPACE_RELATION_POSITION_VALID_BIT; - - if (in_flags & wivrn::from_headset::bd_body::orientation_valid) - flags |= XRT_SPACE_RELATION_ORIENTATION_VALID_BIT; - - if (in_flags & wivrn::from_headset::bd_body::position_tracked) - flags |= XRT_SPACE_RELATION_POSITION_TRACKED_BIT; - - if (in_flags & wivrn::from_headset::bd_body::orientation_tracked) - flags |= XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT; - return xrt_space_relation_flags(flags); -} - static xrt_space_relation to_relation(const wivrn::from_headset::meta_body::pose & pose) { return { - .relation_flags = cast_meta_flags(pose.flags), + .relation_flags = from_pose_flags(pose.flags), .pose = xrt_cast(XrPosef{ .orientation = pose.orientation, .position = pose.position, @@ -81,7 +47,7 @@ static xrt_space_relation to_relation(const wivrn::from_headset::meta_body::pose static xrt_space_relation to_relation(const wivrn::from_headset::bd_body::pose & pose) { return { - .relation_flags = cast_bd_flags(pose.flags), + .relation_flags = from_pose_flags(pose.flags), .pose = xrt_cast(XrPosef{ .orientation = pose.orientation, .position = pose.position, @@ -91,7 +57,7 @@ static xrt_space_relation to_relation(const wivrn::from_headset::bd_body::pose & static xrt_space_relation to_relation(const wivrn::from_headset::meta_body::pose & base, const wivrn::from_headset::meta_body::packed_pose & pose) { return { - .relation_flags = cast_meta_flags(pose.flags), + .relation_flags = from_pose_flags(pose.flags), .pose = xrt_cast(XrPosef{ .orientation = pose.orientation, .position = { diff --git a/server/driver/wivrn_generic_tracker.cpp b/server/driver/wivrn_generic_tracker.cpp index 40055755..5e7137d7 100644 --- a/server/driver/wivrn_generic_tracker.cpp +++ b/server/driver/wivrn_generic_tracker.cpp @@ -34,23 +34,6 @@ using namespace xrt::auxiliary::math; -static xrt_space_relation_flags cast_flags(uint8_t in_flags) -{ - std::underlying_type_t flags{}; - if (in_flags & wivrn::from_headset::htc_body::orientation_valid) - flags |= XRT_SPACE_RELATION_ORIENTATION_VALID_BIT; - - if (in_flags & wivrn::from_headset::htc_body::position_valid) - flags |= XRT_SPACE_RELATION_POSITION_VALID_BIT; - - if (in_flags & wivrn::from_headset::htc_body::orientation_tracked) - flags |= XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT; - - if (in_flags & wivrn::from_headset::htc_body::position_tracked) - flags |= XRT_SPACE_RELATION_POSITION_TRACKED_BIT; - return xrt_space_relation_flags(flags); -} - namespace wivrn { @@ -90,7 +73,7 @@ xrt_space_relation tracker_pose_list::extrapolate(const xrt_space_relation & a, void tracker_pose_list::update_tracking(XrTime produced_timestamp, XrTime timestamp, const from_headset::htc_body::pose & pose, const clock_offset & offset) { xrt_space_relation rel{ - .relation_flags = cast_flags(pose.flags), + .relation_flags = from_pose_flags(pose.flags), .pose = xrt_cast(pose.pose), }; add_sample(produced_timestamp, timestamp, rel, offset); diff --git a/server/driver/xrt_cast.cpp b/server/driver/xrt_cast.cpp index 5de05dbd..947ef922 100644 --- a/server/driver/xrt_cast.cpp +++ b/server/driver/xrt_cast.cpp @@ -18,7 +18,9 @@ */ #include "xrt_cast.h" +#include "wivrn_packets.h" #include +#include namespace { @@ -45,3 +47,21 @@ XRT_CAST(XrFovf, xrt_fov) XRT_CAST(xrt_pose, XrPosef) XRT_CAST(xrt_fov, XrFovf) + +xrt_space_relation_flags from_pose_flags(uint8_t in_flags) +{ + std::underlying_type_t flags{}; + if (in_flags & wivrn::from_headset::pose_flags::orientation_valid) + flags |= XRT_SPACE_RELATION_ORIENTATION_VALID_BIT; + if (in_flags & wivrn::from_headset::pose_flags::position_valid) + flags |= XRT_SPACE_RELATION_POSITION_VALID_BIT; + if (in_flags & wivrn::from_headset::pose_flags::linear_velocity_valid) + flags |= XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT; + if (in_flags & wivrn::from_headset::pose_flags::angular_velocity_valid) + flags |= XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT; + if (in_flags & wivrn::from_headset::pose_flags::orientation_tracked) + flags |= XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT; + if (in_flags & wivrn::from_headset::pose_flags::position_tracked) + flags |= XRT_SPACE_RELATION_POSITION_TRACKED_BIT; + return xrt_space_relation_flags(flags); +} diff --git a/server/driver/xrt_cast.h b/server/driver/xrt_cast.h index 0f417ba5..1ef6d00c 100644 --- a/server/driver/xrt_cast.h +++ b/server/driver/xrt_cast.h @@ -29,3 +29,5 @@ xrt_fov xrt_cast(const XrFovf &); XrPosef xrt_cast(const xrt_pose &); XrFovf xrt_cast(const xrt_fov &); + +xrt_space_relation_flags from_pose_flags(uint8_t in_flags);