Add hand tracking
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2024 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "hand_tracker.h"
|
||||
|
||||
|
||||
std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> xr::hand_tracker::locate(XrSpace space, XrTime time)
|
||||
{
|
||||
if (!xrLocateHandJointsEXT)
|
||||
xrLocateHandJointsEXT = inst->get_proc<PFN_xrLocateHandJointsEXT>("xrLocateHandJointsEXT");
|
||||
|
||||
XrHandJointsLocateInfoEXT info{
|
||||
.type = XR_TYPE_HAND_JOINTS_LOCATE_INFO_EXT,
|
||||
.next = nullptr,
|
||||
.baseSpace = space,
|
||||
.time = time,
|
||||
};
|
||||
|
||||
std::array<XrHandJointLocationEXT, XR_HAND_JOINT_COUNT_EXT> joints_pos;
|
||||
std::array<XrHandJointVelocityEXT, XR_HAND_JOINT_COUNT_EXT> joints_vel;
|
||||
|
||||
XrHandJointVelocitiesEXT velocities{
|
||||
.type = XR_TYPE_HAND_JOINT_VELOCITIES_EXT,
|
||||
.next = nullptr,
|
||||
.jointCount = joints_vel.size(),
|
||||
.jointVelocities = joints_vel.data(),
|
||||
};
|
||||
|
||||
XrHandJointLocationsEXT locations{
|
||||
.type = XR_TYPE_HAND_JOINT_LOCATIONS_EXT,
|
||||
.next = &velocities,
|
||||
.jointCount = joints_pos.size(),
|
||||
.jointLocations = joints_pos.data(),
|
||||
};
|
||||
|
||||
CHECK_XR(xrLocateHandJointsEXT(id, &info, &locations));
|
||||
|
||||
std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> joints;
|
||||
for(int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++)
|
||||
{
|
||||
joints[i] = { joints_pos[i], joints_vel[i] };
|
||||
}
|
||||
|
||||
return joints;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2024 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils/handle.h"
|
||||
#include <openxr/openxr.h>
|
||||
#include <array>
|
||||
#include <utility>
|
||||
|
||||
#include "instance.h"
|
||||
|
||||
namespace xr
|
||||
{
|
||||
class hand_tracker : public utils::handle<XrHandTrackerEXT>
|
||||
{
|
||||
instance * inst;
|
||||
PFN_xrLocateHandJointsEXT xrLocateHandJointsEXT{};
|
||||
|
||||
public:
|
||||
hand_tracker() = default;
|
||||
hand_tracker(instance * i, XrHandTrackerEXT h)
|
||||
{
|
||||
inst = i;
|
||||
id = h;
|
||||
}
|
||||
hand_tracker(hand_tracker &&) = default;
|
||||
hand_tracker & operator=(hand_tracker &&) = default;
|
||||
|
||||
~hand_tracker()
|
||||
{
|
||||
auto xrDestroyHandTrackerEXT = inst->get_proc<PFN_xrDestroyHandTrackerEXT>("xrDestroyHandTrackerEXT");
|
||||
|
||||
if (id != XR_NULL_HANDLE && xrDestroyHandTrackerEXT)
|
||||
xrDestroyHandTrackerEXT(id);
|
||||
}
|
||||
|
||||
using joint = std::pair<XrHandJointLocationEXT, XrHandJointVelocityEXT>;
|
||||
|
||||
std::array<joint, XR_HAND_JOINT_COUNT_EXT> locate(XrSpace space, XrTime time);
|
||||
};
|
||||
} // namespace xr
|
||||
@@ -76,6 +76,26 @@ xr::space xr::session::create_action_space(XrAction action, const XrPosef & pose
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
xr::hand_tracker xr::session::create_hand_tracker(XrHandEXT hand, XrHandJointSetEXT hand_joint_set)
|
||||
{
|
||||
XrHandTrackerCreateInfoEXT create_info
|
||||
{
|
||||
.type = XR_TYPE_HAND_TRACKER_CREATE_INFO_EXT,
|
||||
.next = nullptr,
|
||||
.hand = hand,
|
||||
.handJointSet = hand_joint_set,
|
||||
};
|
||||
|
||||
XrHandTrackerEXT ht;
|
||||
|
||||
auto xrCreateHandTrackerEXT = inst->get_proc<PFN_xrCreateHandTrackerEXT>("xrCreateHandTrackerEXT");
|
||||
assert(xrCreateHandTrackerEXT);
|
||||
|
||||
CHECK_XR(xrCreateHandTrackerEXT(id, &create_info, &ht));
|
||||
return {inst, ht};
|
||||
}
|
||||
|
||||
std::vector<vk::Format> xr::session::get_swapchain_formats() const
|
||||
{
|
||||
std::vector<vk::Format> formats;
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
#include "space.h"
|
||||
#include "hand_tracker.h"
|
||||
|
||||
namespace xr
|
||||
{
|
||||
@@ -48,6 +49,7 @@ public:
|
||||
std::vector<XrReferenceSpaceType> get_reference_spaces() const;
|
||||
space create_reference_space(XrReferenceSpaceType ref, const XrPosef & pose = {{0, 0, 0, 1}, {0, 0, 0}});
|
||||
space create_action_space(XrAction action, const XrPosef & pose = {{0, 0, 0, 1}, {0, 0, 0}});
|
||||
hand_tracker create_hand_tracker(XrHandEXT hand, XrHandJointSetEXT hand_joint_set = XR_HAND_JOINT_SET_DEFAULT_EXT);
|
||||
|
||||
std::vector<vk::Format> get_swapchain_formats() const;
|
||||
|
||||
|
||||
@@ -63,6 +63,25 @@ XrSystemProperties xr::system::properties() const
|
||||
return prop;
|
||||
}
|
||||
|
||||
XrSystemHandTrackingPropertiesEXT xr::system::hand_tracking_properties() const
|
||||
{
|
||||
if (!id)
|
||||
throw std::invalid_argument("this");
|
||||
|
||||
XrSystemHandTrackingPropertiesEXT hand_tracking_prop
|
||||
{
|
||||
.type = XR_TYPE_SYSTEM_HAND_TRACKING_PROPERTIES_EXT,
|
||||
};
|
||||
|
||||
XrSystemProperties prop{
|
||||
.type = XR_TYPE_SYSTEM_PROPERTIES,
|
||||
.next = &hand_tracking_prop,
|
||||
};
|
||||
CHECK_XR(xrGetSystemProperties(*inst, id, &prop));
|
||||
|
||||
return hand_tracking_prop;
|
||||
}
|
||||
|
||||
vk::raii::PhysicalDevice xr::system::physical_device(vk::raii::Instance& vulkan) const
|
||||
{
|
||||
auto xrGetVulkanGraphicsDevice2KHR =
|
||||
|
||||
@@ -54,6 +54,8 @@ public:
|
||||
}
|
||||
|
||||
XrSystemProperties properties() const;
|
||||
XrSystemHandTrackingPropertiesEXT hand_tracking_properties() const;
|
||||
|
||||
XrGraphicsRequirementsVulkan2KHR graphics_requirements() const;
|
||||
vk::raii::PhysicalDevice physical_device(vk::raii::Instance& vulkan) const;
|
||||
vk::raii::Device create_device(vk::raii::PhysicalDevice& pdev, vk::DeviceCreateInfo & create_info) const;
|
||||
|
||||
Reference in New Issue
Block a user