Don't send haptics when focusing with hand

This commit is contained in:
Patrick Nicolas
2024-04-12 16:13:31 +02:00
parent 9722ce9831
commit e1a6d4c40a
3 changed files with 43 additions and 29 deletions
+27 -25
View File
@@ -314,38 +314,40 @@ void imgui_context::new_frame(XrTime display_time)
controller_state & new_state = new_states.emplace_back(); controller_state & new_state = new_states.emplace_back();
if (auto joints = ctrl.hand.locate(world, display_time)) if (ctrl.hand)
{ {
XrHandJointLocationEXT & index_tip = (*joints)[XR_HAND_JOINT_INDEX_TIP_EXT].first; if (auto joints = ctrl.hand->locate(world, display_time))
if (index_tip.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
{ {
new_state.aim_position = { XrHandJointLocationEXT & index_tip = (*joints)[XR_HAND_JOINT_INDEX_TIP_EXT].first;
index_tip.pose.position.x, if (index_tip.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
index_tip.pose.position.y,
index_tip.pose.position.z};
new_state.aim_orientation = orientation_;
new_state.active = true;
auto position_distance = ray_plane_intersection(new_state);
if (position_distance)
{ {
new_state.hover_distance = std::abs(position_distance->second); new_state.aim_position = {
index_tip.pose.position.x,
index_tip.pose.position.y,
index_tip.pose.position.z};
if (std::abs(position_distance->second) < 0.1f) new_state.aim_orientation = orientation_;
new_state.fingertip_hovered = true;
new_state.active = true;
auto position_distance = ray_plane_intersection(new_state);
if (position_distance)
{
new_state.hover_distance = std::abs(position_distance->second);
if (std::abs(position_distance->second) < 0.1f)
new_state.fingertip_hovered = true;
else
new_state.active = false;
if (new_state.hover_distance < 0.02)
new_state.fingertip_touched = true;
}
else else
new_state.active = false; new_state.hover_distance = 1e10;
if (new_state.hover_distance < 0.02)
new_state.fingertip_touched = true;
} }
else
new_state.hover_distance = 1e10;
continue;
} }
continue;
} }
if (auto location = application::locate_controller(ctrl.aim, world, display_time)) if (auto location = application::locate_controller(ctrl.aim, world, display_time))
+1 -1
View File
@@ -63,7 +63,7 @@ public:
XrAction scroll; // XR_ACTION_TYPE_VECTOR2F_INPUT XrAction scroll; // XR_ACTION_TYPE_VECTOR2F_INPUT
// TODO: thresholds? // TODO: thresholds?
xr::hand_tracker & hand; xr::hand_tracker * hand = nullptr;
}; };
struct controller_state struct controller_state
+15 -3
View File
@@ -735,22 +735,34 @@ void scenes::lobby::on_focused()
} }
recenter_action = get_action("recenter").first; recenter_action = get_action("recenter").first;
std::array imgui_inputs{ std::vector imgui_inputs{
imgui_context::controller{ imgui_context::controller{
.aim = get_action_space("left_aim"), .aim = get_action_space("left_aim"),
.trigger = get_action("left_trigger").first, .trigger = get_action("left_trigger").first,
.squeeze = get_action("left_squeeze").first, .squeeze = get_action("left_squeeze").first,
.scroll = get_action("left_scroll").first, .scroll = get_action("left_scroll").first,
.hand = application::get_left_hand(),
}, },
imgui_context::controller{ imgui_context::controller{
.aim = get_action_space("right_aim"), .aim = get_action_space("right_aim"),
.trigger = get_action("right_trigger").first, .trigger = get_action("right_trigger").first,
.squeeze = get_action("right_squeeze").first, .squeeze = get_action("right_squeeze").first,
.scroll = get_action("right_scroll").first, .scroll = get_action("right_scroll").first,
.hand = application::get_right_hand(),
}, },
}; };
if (auto & hand = application::get_left_hand())
{
imgui_inputs.push_back(
{
.hand = &hand,
});
}
if (auto & hand = application::get_right_hand())
{
imgui_inputs.push_back(
{
.hand = &hand,
});
}
swapchain_imgui = xr::swapchain(session, device, swapchain_format, 1500, 1000); swapchain_imgui = xr::swapchain(session, device, swapchain_format, 1500, 1000);
imgui_ctx.emplace(physical_device, device, queue_family_index, queue, world_space, imgui_inputs, swapchain_imgui, glm::vec2{1.0, 0.6666}); imgui_ctx.emplace(physical_device, device, queue_family_index, queue, world_space, imgui_inputs, swapchain_imgui, glm::vec2{1.0, 0.6666});