Maintain distance to controller when recentering

This commit is contained in:
Patrick Nicolas
2024-04-13 11:24:50 +02:00
parent 191b3ef477
commit 09c2bf19e5
4 changed files with 30 additions and 8 deletions
+1 -1
View File
@@ -104,7 +104,7 @@ static void check_vk_result(VkResult result)
}
}
std::optional<std::pair<ImVec2, float>> imgui_context::ray_plane_intersection(const imgui_context::controller_state & in)
std::optional<std::pair<ImVec2, float>> imgui_context::ray_plane_intersection(const imgui_context::controller_state & in) const
{
if (!in.active)
return {};
+2 -2
View File
@@ -131,8 +131,6 @@ private:
bool button_pressed = false;
std::optional<std::pair<ImVec2, float>> ray_plane_intersection(const imgui_context::controller_state & in);
public:
imgui_context(
vk::raii::PhysicalDevice physical_device,
@@ -206,6 +204,8 @@ public:
return focused_controller;
}
std::optional<std::pair<ImVec2, float>> ray_plane_intersection(const imgui_context::controller_state & in) const;
ImTextureID load_texture(const std::string & filename, vk::raii::Sampler && sampler);
ImTextureID load_texture(const std::string & filename);
void free_texture(ImTextureID);
+26 -5
View File
@@ -142,10 +142,10 @@ static std::string json_string(const std::string & in)
return out;
}
static const std::array supported_formats =
{
vk::Format::eR8G8B8A8Srgb,
vk::Format::eB8G8R8A8Srgb};
static const std::array supported_formats = {
vk::Format::eR8G8B8A8Srgb,
vk::Format::eB8G8R8A8Srgb,
};
void scenes::lobby::move_gui(glm::vec3 head_position, glm::vec3 new_gui_position)
{
@@ -510,9 +510,30 @@ std::optional<glm::vec3> scenes::lobby::check_recenter_action(XrTime predicted_d
if (aim)
{
if (not gui_recenter_distance)
{
auto intersection = imgui_ctx->ray_plane_intersection({
.active = true,
.aim_position = aim->first,
.aim_orientation = aim->second,
});
if (intersection)
{
gui_recenter_distance = std::clamp(intersection->second, 0.05f, 1.f);
spdlog::info("recentering at {}m", intersection->second);
}
else
{
gui_recenter_distance = 0.3;
}
}
const auto & v = aim->first;
const auto & q = aim->second;
return v + q * glm::vec3(0, 0, -0.3);
return v + q * glm::vec3(0, 0, -*gui_recenter_distance);
}
else
{
gui_recenter_distance.reset();
}
return std::nullopt;
+1
View File
@@ -101,6 +101,7 @@ class lobby : public scene_impl<lobby>
XrAction recenter_left_action = XR_NULL_HANDLE;
XrAction recenter_right_action = XR_NULL_HANDLE;
std::optional<float> gui_recenter_distance;
bool recenter_gui = true;
void move_gui(glm::vec3 head_position, glm::vec3 new_gui_position);