Maintain distance to controller when recentering
This commit is contained in:
@@ -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)
|
if (!in.active)
|
||||||
return {};
|
return {};
|
||||||
|
|||||||
@@ -131,8 +131,6 @@ private:
|
|||||||
|
|
||||||
bool button_pressed = false;
|
bool button_pressed = false;
|
||||||
|
|
||||||
std::optional<std::pair<ImVec2, float>> ray_plane_intersection(const imgui_context::controller_state & in);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
imgui_context(
|
imgui_context(
|
||||||
vk::raii::PhysicalDevice physical_device,
|
vk::raii::PhysicalDevice physical_device,
|
||||||
@@ -206,6 +204,8 @@ public:
|
|||||||
return focused_controller;
|
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, vk::raii::Sampler && sampler);
|
||||||
ImTextureID load_texture(const std::string & filename);
|
ImTextureID load_texture(const std::string & filename);
|
||||||
void free_texture(ImTextureID);
|
void free_texture(ImTextureID);
|
||||||
|
|||||||
+26
-5
@@ -142,10 +142,10 @@ static std::string json_string(const std::string & in)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const std::array supported_formats =
|
static const std::array supported_formats = {
|
||||||
{
|
vk::Format::eR8G8B8A8Srgb,
|
||||||
vk::Format::eR8G8B8A8Srgb,
|
vk::Format::eB8G8R8A8Srgb,
|
||||||
vk::Format::eB8G8R8A8Srgb};
|
};
|
||||||
|
|
||||||
void scenes::lobby::move_gui(glm::vec3 head_position, glm::vec3 new_gui_position)
|
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 (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 & v = aim->first;
|
||||||
const auto & q = aim->second;
|
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;
|
return std::nullopt;
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ class lobby : public scene_impl<lobby>
|
|||||||
|
|
||||||
XrAction recenter_left_action = XR_NULL_HANDLE;
|
XrAction recenter_left_action = XR_NULL_HANDLE;
|
||||||
XrAction recenter_right_action = XR_NULL_HANDLE;
|
XrAction recenter_right_action = XR_NULL_HANDLE;
|
||||||
|
std::optional<float> gui_recenter_distance;
|
||||||
bool recenter_gui = true;
|
bool recenter_gui = true;
|
||||||
void move_gui(glm::vec3 head_position, glm::vec3 new_gui_position);
|
void move_gui(glm::vec3 head_position, glm::vec3 new_gui_position);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user