Store all spaces in an array

This commit is contained in:
Patrick Nicolas
2024-10-05 13:55:20 +02:00
parent 3c09db939f
commit 974c90a36c
9 changed files with 49 additions and 64 deletions
+11 -12
View File
@@ -650,15 +650,15 @@ void application::initialize_actions()
actions_by_name.emplace(name, a);
if (name == "/user/hand/left/input/grip/pose")
left_grip_space = xr_session.create_action_space(a);
spaces[size_t(xr::spaces::grip_left)] = xr_session.create_action_space(a);
else if (name == "/user/hand/left/input/aim/pose")
left_aim_space = xr_session.create_action_space(a);
spaces[size_t(xr::spaces::aim_left)] = xr_session.create_action_space(a);
else if (name == "/user/hand/right/input/grip/pose")
right_grip_space = xr_session.create_action_space(a);
spaces[size_t(xr::spaces::grip_right)] = xr_session.create_action_space(a);
else if (name == "/user/hand/right/input/aim/pose")
right_aim_space = xr_session.create_action_space(a);
spaces[size_t(xr::spaces::aim_right)] = xr_session.create_action_space(a);
else if (name == "/user/eyes_ext/input/gaze_ext/pose")
eye_gaze_space = xr_session.create_action_space(a);
spaces[size_t(xr::spaces::eye_gaze)] = xr_session.create_action_space(a);
}
// Build an action set for each scene
@@ -828,16 +828,15 @@ void application::initialize()
xr_session = xr::session(xr_instance, xr_system_id, vk_instance, vk_physical_device, vk_device, vk_queue_family_index);
auto spaces = xr_session.get_reference_spaces();
spdlog::info("{} reference spaces", spaces.size());
for (XrReferenceSpaceType i: spaces)
{
spdlog::info(" {}", xr::to_string(i));
auto spaces = xr_session.get_reference_spaces();
spdlog::info("{} reference spaces", spaces.size());
for (XrReferenceSpaceType i: spaces)
spdlog::info(" {}", xr::to_string(i));
}
view_space = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_VIEW);
world_space = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE);
// world_space = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_LOCAL);
spaces[size_t(xr::spaces::view)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_VIEW);
spaces[size_t(xr::spaces::world)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE);
config.emplace(xr_system_id);
if (xr_instance.has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME))
+5 -30
View File
@@ -115,15 +115,9 @@ class application : public singleton<application>
xr::session xr_session;
XrSessionState session_state = XR_SESSION_STATE_UNKNOWN;
xr::space world_space;
xr::space view_space;
std::array<xr::space, size_t(xr::spaces::count)> spaces;
xr::actionset xr_actionset;
std::vector<std::tuple<XrAction, XrActionType, std::string>> actions;
xr::space left_grip_space;
xr::space left_aim_space;
xr::space right_grip_space;
xr::space right_aim_space;
xr::space eye_gaze_space;
bool hand_tracking_supported = false;
xr::hand_tracker left_hand;
@@ -294,30 +288,11 @@ public:
return (T)proc;
}
static XrSpace view()
static XrSpace space(xr::spaces s)
{
return instance().view_space;
};
static XrSpace left_grip()
{
return instance().left_grip_space;
};
static XrSpace left_aim()
{
return instance().left_aim_space;
};
static XrSpace right_grip()
{
return instance().right_grip_space;
};
static XrSpace right_aim()
{
return instance().right_aim_space;
};
static XrSpace eye_gaze()
{
return instance().eye_gaze_space;
};
assert(size_t(s) >= 0 and s < xr::spaces::count);
return instance().spaces[size_t(s)];
}
static wifi_lock & get_wifi_lock()
{
-2
View File
@@ -30,8 +30,6 @@ scene::scene(key, const meta & current_meta) :
instance(application::instance().xr_instance),
system(application::instance().xr_system_id),
session(application::instance().xr_session),
world_space(application::instance().world_space),
view_space(application::instance().view_space),
viewconfig(application::instance().app_info.viewconfig),
vk_instance(application::instance().vk_instance),
-2
View File
@@ -73,8 +73,6 @@ protected:
xr::instance & instance;
xr::system & system;
xr::session & session;
xr::space & world_space;
xr::space & view_space;
XrViewConfigurationType viewconfig;
bool focused = false;
+4 -4
View File
@@ -211,9 +211,9 @@ input_profile::input_profile(const std::filesystem::path & json_profile, scene_l
XrSpace space;
if (layout == "left")
space = application::left_grip();
space = application::space(xr::spaces::grip_left);
else if (layout == "right")
space = application::right_grip();
space = application::space(xr::spaces::grip_right);
else
continue;
@@ -292,13 +292,13 @@ void input_profile::apply(XrSpace world_space, XrTime predicted_display_time, bo
{
for (auto && [space, node]: model_handles)
{
if (space == application::left_grip() && hide_left)
if (space == application::space(xr::spaces::grip_left) && hide_left)
{
node->visible = false;
continue;
}
if (space == application::right_grip() && hide_right)
if (space == application::space(xr::spaces::grip_right) && hide_right)
{
node->visible = false;
continue;
+5 -4
View File
@@ -372,12 +372,12 @@ std::optional<glm::vec3> scenes::lobby::check_recenter_action(XrTime predicted_d
if (application::read_action_bool(recenter_left_action).value_or(std::pair{0, false}).second)
{
aim = application::locate_controller(application::left_aim(), world_space, predicted_display_time);
aim = application::locate_controller(application::space(xr::spaces::aim_left), application::space(xr::spaces::world), predicted_display_time);
}
if (application::read_action_bool(recenter_right_action).value_or(std::pair{0, false}).second)
{
aim = application::locate_controller(application::right_aim(), world_space, predicted_display_time);
aim = application::locate_controller(application::space(xr::spaces::aim_right), application::space(xr::spaces::world), predicted_display_time);
}
if (aim)
@@ -534,13 +534,14 @@ void scenes::lobby::render(const XrFrameState & frame_state)
session.begin_frame();
XrSpace world_space = application::space(xr::spaces::world);
auto [flags, views] = session.locate_views(viewconfig, frame_state.predictedDisplayTime, world_space);
assert(views.size() == swapchains_lobby.size());
bool hide_left_controller = false;
bool hide_right_controller = false;
std::optional<std::pair<glm::vec3, glm::quat>> head_position = application::locate_controller(application::view(), world_space, frame_state.predictedDisplayTime);
std::optional<std::pair<glm::vec3, glm::quat>> head_position = application::locate_controller(application::space(xr::spaces::view), world_space, frame_state.predictedDisplayTime);
std::optional<glm::vec3> new_gui_position;
if (head_position)
@@ -731,7 +732,7 @@ void scenes::lobby::on_focused()
}
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{0.6, 0.4});
imgui_ctx.emplace(physical_device, device, queue_family_index, queue, application::space(xr::spaces::world), imgui_inputs, swapchain_imgui, glm::vec2{0.6, 0.4});
try
{
+3 -3
View File
@@ -94,7 +94,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
auto [flags, views] = self->session.locate_views(
XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO,
self->instance.now(),
application::view());
application::space(xr::spaces::view));
assert(views.size() == info.fov.size());
@@ -209,7 +209,7 @@ void scenes::stream::on_focused()
device,
queue_family_index,
queue,
view_space,
application::space(xr::spaces::world),
std::span<imgui_context::controller>{},
swapchain_imgui,
glm::vec2{1.0, 0.6666});
@@ -734,7 +734,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
XrCompositionLayerProjection layer{
.type = XR_TYPE_COMPOSITION_LAYER_PROJECTION,
.layerFlags = 0,
.space = world_space,
.space = application::space(xr::spaces::world),
.viewCount = (uint32_t)layer_view.size(),
.views = layer_view.data(),
};
+8 -7
View File
@@ -176,16 +176,17 @@ void scenes::stream::tracking()
const XrDuration battery_check_interval = 30'000'000'000; // 30s
#endif
std::vector<std::pair<device_id, XrSpace>> spaces = {
{device_id::HEAD, application::view()},
{device_id::LEFT_AIM, application::left_aim()},
{device_id::LEFT_GRIP, application::left_grip()},
{device_id::RIGHT_AIM, application::right_aim()},
{device_id::RIGHT_GRIP, application::right_grip()}};
{device_id::HEAD, application::space(xr::spaces::view)},
{device_id::LEFT_AIM, application::space(xr::spaces::aim_left)},
{device_id::LEFT_GRIP, application::space(xr::spaces::grip_left)},
{device_id::RIGHT_AIM, application::space(xr::spaces::aim_right)},
{device_id::RIGHT_GRIP, application::space(xr::spaces::grip_right)}};
if (application::get_eye_gaze_supported())
spaces.push_back({device_id::EYE_GAZE, application::eye_gaze()});
spaces.push_back({device_id::EYE_GAZE, application::space(xr::spaces::eye_gaze)});
XrSpace view_space = application::view();
XrSpace view_space = application::space(xr::spaces::view);
XrSpace world_space = application::space(xr::spaces::world);
XrDuration tracking_period = 1'000'000; // Send tracking data every 1ms
const XrDuration dt = 100'000; // Wake up 0.1ms before measuring the position
+13
View File
@@ -25,4 +25,17 @@
namespace xr
{
using space = utils::handle<XrSpace, xrDestroySpace>;
enum class spaces
{
world,
view,
eye_gaze,
grip_left,
grip_right,
aim_left,
aim_right,
count
};
} // namespace xr