Fix meta handtracking thumb rotation offset

This commit is contained in:
Stellanora
2025-03-25 10:52:20 +01:00
committed by GitHub
parent 6a26f395f5
commit e0a1598ac5
2 changed files with 48 additions and 1 deletions
+45 -1
View File
@@ -18,10 +18,13 @@
*/
#include "hand_tracker.h"
#include "hardware.h"
#include "xr/check.h"
#include "xr/instance.h"
#include "xr/session.h"
#include <cassert>
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
static PFN_xrDestroyHandTrackerEXT xrDestroyHandTrackerEXT{};
@@ -30,7 +33,8 @@ XrResult xr::destroy_hand_tracker(XrHandTrackerEXT id)
return xrDestroyHandTrackerEXT(id);
}
xr::hand_tracker::hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info)
xr::hand_tracker::hand_tracker(instance & inst, session & session, const XrHandTrackerCreateInfoEXT & info) :
hand_id(info.hand)
{
static auto xrCreateHandTrackerEXT = inst.get_proc<PFN_xrCreateHandTrackerEXT>("xrCreateHandTrackerEXT");
assert(xrCreateHandTrackerEXT);
@@ -73,9 +77,49 @@ std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> xr::
if (!locations.isActive)
return std::nullopt;
float offset_angle;
// check if we have a device that needs a thumb offset
switch (guess_model())
{
case model::meta_quest_3:
case model::meta_quest_pro:
case model::meta_quest_3s:
case model::oculus_quest:
case model::oculus_quest_2:
if (hand_id == XR_HAND_LEFT_EXT)
offset_angle = glm::radians(-90.0f);
else if (hand_id == XR_HAND_RIGHT_EXT)
offset_angle = glm::radians(90.0f);
break;
default:
offset_angle = 0.0f;
break;
}
std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT> joints;
for (int i = 0; i < XR_HAND_JOINT_COUNT_EXT; i++)
{
if (i >= XR_HAND_JOINT_THUMB_METACARPAL_EXT && i <= XR_HAND_JOINT_THUMB_TIP_EXT)
{
// Need to convert the XrQuaternionf to a glm::quat to use glm::rotate
glm::quat q(
joints_pos[i].pose.orientation.w,
joints_pos[i].pose.orientation.x,
joints_pos[i].pose.orientation.y,
joints_pos[i].pose.orientation.z);
glm::quat offset_rotation = glm::rotate(q, offset_angle, glm::vec3(0, 0, 1));
joints_pos[i].pose.orientation = {
.x = offset_rotation.x,
.y = offset_rotation.y,
.z = offset_rotation.z,
.w = offset_rotation.w,
};
}
joints[i] = {joints_pos[i], joints_vel[i]};
}
+3
View File
@@ -43,5 +43,8 @@ public:
std::optional<std::array<joint, XR_HAND_JOINT_COUNT_EXT>> locate(XrSpace space, XrTime time);
static bool check_flags(const std::array<joint, XR_HAND_JOINT_COUNT_EXT> & joints, XrSpaceLocationFlags position, XrSpaceVelocityFlags velocity);
private:
XrHandEXT hand_id;
};
} // namespace xr