Allow recentering

This commit is contained in:
Patrick Nicolas
2024-05-09 16:17:46 +02:00
parent f7c6b6c99e
commit 4f3a1d0b7f
6 changed files with 37 additions and 7 deletions
+1 -1
View File
@@ -1267,7 +1267,7 @@ void application::reference_space_changed(XrReferenceSpaceType referenceSpaceTyp
{
if (std::shared_ptr<scene> s = current_scene())
{
s->on_reference_space_changed(referenceSpaceType);
s->on_reference_space_changed(referenceSpaceType, timestamp);
}
}
+1 -1
View File
@@ -47,5 +47,5 @@ scene::scene(key, const meta & current_meta) :
void scene::on_unfocused() {}
void scene::on_focused() {}
void scene::on_interaction_profile_changed() {}
void scene::on_reference_space_changed(XrReferenceSpaceType) {}
void scene::on_reference_space_changed(XrReferenceSpaceType, XrTime) {}
void scene::on_session_state_changed(XrSessionState) {}
+1 -1
View File
@@ -105,7 +105,7 @@ public:
virtual void on_unfocused();
virtual void on_focused();
virtual void on_interaction_profile_changed();
virtual void on_reference_space_changed(XrReferenceSpaceType space);
virtual void on_reference_space_changed(XrReferenceSpaceType space, XrTime);
virtual void on_session_state_changed(XrSessionState state);
};
+26 -1
View File
@@ -123,6 +123,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
self->network_session->send_control(info);
self->update_local_floor(self->instance.now());
self->network_thread = utils::named_thread("network_thread", &stream::process_packets, self.get());
self->video_thread = utils::named_thread("video_thread", &stream::video, self.get());
@@ -696,7 +697,7 @@ void scenes::stream::render(XrTime predicted_display_time, bool should_render)
XrCompositionLayerProjection layer{
.type = XR_TYPE_COMPOSITION_LAYER_PROJECTION,
.layerFlags = 0,
.space = world_space,
.space = local_floor,
.viewCount = (uint32_t)layer_view.size(),
.views = layer_view.data(),
};
@@ -949,3 +950,27 @@ scene::meta & scenes::stream::get_meta_scene()
return m;
}
void scenes::stream::update_local_floor(XrTime when)
{
XrReferenceSpaceCreateInfo createInfo{XR_TYPE_REFERENCE_SPACE_CREATE_INFO};
createInfo.poseInReferenceSpace.orientation.w = 1.f;
createInfo.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_LOCAL;
xr::space local = session.create_reference_space(XR_REFERENCE_SPACE_TYPE_LOCAL);
xr::space stage = session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE);
XrSpaceLocation location{
.type = XR_TYPE_SPACE_LOCATION,
};
xrLocateSpace(stage, local, when, &location);
XrPosef offset{{0, 0, 0, 1}, {0, location.pose.position.y, 0}};
std::lock_guard lock(local_floor_mutex);
local_floor = session.create_reference_space(XR_REFERENCE_SPACE_TYPE_LOCAL, offset);
}
void scenes::stream::on_reference_space_changed(XrReferenceSpaceType space, XrTime when)
{
update_local_floor(when);
}
+4
View File
@@ -75,6 +75,8 @@ private:
std::unique_ptr<wivrn_session> network_session;
std::atomic<bool> exiting = false;
std::thread network_thread;
std::mutex local_floor_mutex;
xr::space local_floor = nullptr;
std::atomic<std::chrono::nanoseconds::rep> tracking_prediction_offset;
std::optional<std::thread> tracking_thread;
std::thread video_thread;
@@ -220,5 +222,7 @@ private:
void accumulate_metrics(XrTime predicted_display_time, const std::vector<std::shared_ptr<shard_accumulator::blit_handle>> & blit_handles, const gpu_timestamps & timestamps);
XrCompositionLayerQuad plot_performance_metrics(XrTime predicted_display_time);
void update_local_floor(XrTime when);
void on_reference_space_changed(XrReferenceSpaceType space, XrTime) override;
};
} // namespace scenes
+4 -3
View File
@@ -192,9 +192,10 @@ void scenes::stream::tracking()
packet.flags = flags;
packet.device_poses.clear();
std::lock_guard lock(local_floor_mutex);
for (auto [device, space]: spaces)
{
packet.device_poses.push_back(locate_space(device, space, world_space, t0 + Δt));
packet.device_poses.push_back(locate_space(device, space, local_floor, t0 + Δt));
}
t.pause();
@@ -204,13 +205,13 @@ void scenes::stream::tracking()
if (application::get_hand_tracking_supported())
{
hands.hand = xrt::drivers::wivrn::from_headset::hand_tracking::left;
hands.joints = locate_hands(application::get_left_hand(), world_space, hands.timestamp);
hands.joints = locate_hands(application::get_left_hand(), local_floor, hands.timestamp);
t.pause();
network_session->send_stream(hands);
t.resume();
hands.hand = xrt::drivers::wivrn::from_headset::hand_tracking::right;
hands.joints = locate_hands(application::get_right_hand(), world_space, hands.timestamp);
hands.joints = locate_hands(application::get_right_hand(), local_floor, hands.timestamp);
t.pause();
network_session->send_stream(hands);
t.resume();