Update hand gesture for GUI repositioning to require that the hand is opened

This commit is contained in:
Guillaume Meunier
2025-11-02 17:51:59 +01:00
parent dd874eea4b
commit c4265d80a5
4 changed files with 97 additions and 21 deletions
+52 -19
View File
@@ -31,6 +31,7 @@
#include "render/scene_components.h"
#include "stream.h"
#include "utils/files.h"
#include "utils/glm_cast.h"
#include "utils/i18n.h"
#include "wivrn_client.h"
#include "wivrn_discover.h"
@@ -427,27 +428,59 @@ void scenes::lobby::connect(const configuration::server_data & data)
data.manual);
}
std::optional<glm::vec3> scenes::lobby::check_recenter_gesture(xr::spaces space, const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & joints)
std::optional<glm::vec3> scenes::lobby::check_recenter_gesture(
xr::spaces space,
const std::optional<std::array<xr::hand_tracker::joint, XR_HAND_JOINT_COUNT_EXT>> & joints,
const std::pair<glm::vec3, glm::quat> & head_pose)
{
if (recentering_context and std::get<0>(*recentering_context) != space)
return std::nullopt;
if (not joints)
if (joints)
{
recentering_context.reset();
return std::nullopt;
}
const auto & palm = (*joints)[XR_HAND_JOINT_PALM_EXT].first;
const auto palm_y = glm::rotate(glm_cast(palm.pose.orientation), glm::vec3(0, 1, 0));
const auto & palm = (*joints)[XR_HAND_JOINT_PALM_EXT].first;
const auto & o = palm.pose.orientation;
const auto & p = palm.pose.position;
glm::quat q{o.w, o.x, o.y, o.z};
glm::vec3 v{p.x, p.y, p.z};
for (XrHandJointEXT index: {
XR_HAND_JOINT_INDEX_PROXIMAL_EXT,
XR_HAND_JOINT_INDEX_INTERMEDIATE_EXT,
XR_HAND_JOINT_INDEX_DISTAL_EXT,
if (glm::dot(q * glm::vec3(0, 1, 0), glm::vec3(0, -1, 0)) > constants::lobby::recenter_cosangle_min)
{
recentering_context.emplace(space, glm::vec3{}, 0);
return v + glm::vec3(0, constants::lobby::recenter_distance_up, 0) + q * glm::vec3(0, 0, -constants::lobby::recenter_distance_front);
XR_HAND_JOINT_MIDDLE_PROXIMAL_EXT,
XR_HAND_JOINT_MIDDLE_INTERMEDIATE_EXT,
XR_HAND_JOINT_MIDDLE_DISTAL_EXT,
XR_HAND_JOINT_RING_PROXIMAL_EXT,
XR_HAND_JOINT_RING_INTERMEDIATE_EXT,
XR_HAND_JOINT_RING_DISTAL_EXT,
XR_HAND_JOINT_LITTLE_PROXIMAL_EXT,
XR_HAND_JOINT_LITTLE_INTERMEDIATE_EXT,
XR_HAND_JOINT_LITTLE_DISTAL_EXT,
})
{
const auto fingertip_y = glm::rotate(glm_cast((*joints)[index].first.pose.orientation), glm::vec3(0, 1, 0));
if (glm::dot(palm_y, fingertip_y) < constants::lobby::recenter_cos_fingertip_angle_max)
{
recentering_context.reset();
return std::nullopt;
}
}
const auto q = glm_cast(palm.pose.orientation);
const auto x = glm_cast(palm.pose.position);
// Make the up vector orthogonal to forward
const glm::vec3 forward = glm::rotate(head_pose.second, glm::vec3{0, 0, -1});
const glm::vec3 up = glm::normalize(glm::vec3{0, 1, 0} - forward * glm::dot(forward, {0, 1, 0}));
// Y is pointing to the back of the hand
if (glm::dot(q * glm::vec3(0, -1, 0), up) > constants::lobby::recenter_cos_palm_angle_min)
{
recentering_context.emplace(space, glm::vec3{}, 0);
return x + glm::rotate(q, glm::vec3{0, -constants::lobby::recenter_distance_up, -constants::lobby::recenter_distance_front});
}
}
recentering_context.reset();
@@ -959,14 +992,14 @@ void scenes::lobby::render(const XrFrameState & frame_state)
hand_model::apply(world, left, right);
if (not new_gui_position)
new_gui_position = check_recenter_gesture(xr::spaces::palm_left, left);
if (not new_gui_position and head_position)
new_gui_position = check_recenter_gesture(xr::spaces::palm_left, left, *head_position);
if (not new_gui_position)
new_gui_position = check_recenter_gesture(xr::spaces::palm_right, right);
if (not new_gui_position and head_position)
new_gui_position = check_recenter_gesture(xr::spaces::palm_right, right, *head_position);
}
if (head_position && new_gui_position)
if (head_position and new_gui_position)
{
move_gui(head_position->first, *new_gui_position);
}