Add hand tracking
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#include <vulkan/vulkan_core.h>
|
||||
#include "audio/audio.h"
|
||||
#include "hardware.h"
|
||||
#include "utils/contains.h"
|
||||
|
||||
using namespace xrt::drivers::wivrn;
|
||||
|
||||
@@ -108,6 +109,8 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
if (info.available_refresh_rates.empty())
|
||||
spdlog::warn("Unable to detect refresh rates");
|
||||
|
||||
info.hand_tracking = application::get_hand_tracking_supported();
|
||||
|
||||
audio::get_audio_description(info);
|
||||
|
||||
self->network_session->send_control(info);
|
||||
|
||||
@@ -63,6 +63,42 @@ static from_headset::tracking::pose locate_space(device_id device, XrSpace space
|
||||
return res;
|
||||
}
|
||||
|
||||
static std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT_COUNT_EXT> locate_hands(xr::hand_tracker& hand, XrSpace space, XrTime time)
|
||||
{
|
||||
std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> joints = hand.locate(space, time);
|
||||
|
||||
std::array<from_headset::hand_tracking::pose, XR_HAND_JOINT_COUNT_EXT> poses;
|
||||
for(int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++)
|
||||
{
|
||||
poses[i] = {
|
||||
.pose = joints[i].first.pose,
|
||||
.linear_velocity = joints[i].second.linearVelocity,
|
||||
.angular_velocity = joints[i].second.angularVelocity,
|
||||
.radius = joints[i].first.radius,
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void scenes::stream::tracking()
|
||||
{
|
||||
std::vector<std::pair<device_id, XrSpace>> spaces = {
|
||||
@@ -91,7 +127,10 @@ void scenes::stream::tracking()
|
||||
for (XrTime Δt = 0; Δt < extrapolation_horizon; Δt += tracking_period)
|
||||
{
|
||||
from_headset::tracking packet{};
|
||||
from_headset::hand_tracking hands{};
|
||||
|
||||
packet.timestamp = t0 + Δt;
|
||||
hands.timestamp = t0 + Δt;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -112,6 +151,14 @@ void scenes::stream::tracking()
|
||||
}
|
||||
|
||||
network_session->send_stream(packet);
|
||||
|
||||
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);
|
||||
|
||||
network_session->send_stream(hands);
|
||||
}
|
||||
}
|
||||
catch (const std::system_error & e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user