Avoid hand tracking packet fragmentation

This commit is contained in:
Patrick Nicolas
2024-04-07 10:25:30 +02:00
parent 7768527fad
commit c9301332dd
3 changed files with 23 additions and 13 deletions
+6 -3
View File
@@ -78,7 +78,7 @@ static std::optional<std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT
.pose = (*joints)[i].first.pose,
.linear_velocity = (*joints)[i].second.linearVelocity,
.angular_velocity = (*joints)[i].second.angularVelocity,
.radius = (*joints)[i].first.radius,
.radius = uint16_t((*joints)[i].first.radius * 10'000),
};
if ((*joints)[i].first.locationFlags & XR_SPACE_LOCATION_ORIENTATION_VALID_BIT)
@@ -173,9 +173,12 @@ void scenes::stream::tracking()
if (application::get_hand_tracking_supported())
{
hands.left = locate_hands(application::get_left_hand(), world_space, hands.timestamp);
hands.right = locate_hands(application::get_right_hand(), world_space, hands.timestamp);
hands.hand = xrt::drivers::wivrn::from_headset::hand_tracking::left;
hands.joints = locate_hands(application::get_left_hand(), world_space, hands.timestamp);
network_session->send_stream(hands);
hands.hand = xrt::drivers::wivrn::from_headset::hand_tracking::right;
hands.joints = locate_hands(application::get_right_hand(), world_space, hands.timestamp);
network_session->send_stream(hands);
}
}
+10 -4
View File
@@ -160,20 +160,26 @@ struct hand_tracking
orientation_tracked = 1 << 4,
position_tracked = 1 << 5
};
enum hand_id : uint8_t
{
left,
right,
};
struct pose
{
XrPosef pose;
XrVector3f linear_velocity;
XrVector3f angular_velocity;
float radius;
// In order to avoid packet fragmentation
// use 2 less bytes for radius
uint16_t radius; // 10th of mm
uint8_t flags;
};
XrTime production_timestamp;
XrTime timestamp;
std::optional<std::array<pose, XR_HAND_JOINT_COUNT_EXT>> left;
std::optional<std::array<pose, XR_HAND_JOINT_COUNT_EXT>> right;
hand_id hand;
std::optional<std::array<pose, XR_HAND_JOINT_COUNT_EXT>> joints;
};
struct inputs
+7 -6
View File
@@ -104,7 +104,7 @@ static xrt_hand_joint_set convert_joints(const std::optional<std::array<from_hea
{
xrt_hand_joint_value & res = output_joints.values.hand_joint_set_default[i];
res.radius = (*input_joints)[i].radius;
res.radius = (*input_joints)[i].radius / 10'000.;
*joint_rel = to_relation((*input_joints)[i]);
m_relation_chain_resolve(&rel_chain, &res.relation);
@@ -120,9 +120,10 @@ static xrt_hand_joint_set convert_joints(const std::optional<std::array<from_hea
void hand_joints_list::update_tracking(const from_headset::hand_tracking & tracking, const clock_offset & offset)
{
add_sample(
tracking.production_timestamp,
tracking.timestamp,
convert_joints(hand_id == 0 ? tracking.left : tracking.right),
offset);
if (tracking.hand == hand_id)
add_sample(
tracking.production_timestamp,
tracking.timestamp,
convert_joints(tracking.joints),
offset);
}