diff --git a/client/application.cpp b/client/application.cpp index 4c46e207..23455612 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -1267,7 +1267,7 @@ void application::reference_space_changed(XrReferenceSpaceType referenceSpaceTyp { if (std::shared_ptr s = current_scene()) { - s->on_reference_space_changed(referenceSpaceType); + s->on_reference_space_changed(referenceSpaceType, timestamp); } } diff --git a/client/scene.cpp b/client/scene.cpp index 89207274..30a8c028 100644 --- a/client/scene.cpp +++ b/client/scene.cpp @@ -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) {} diff --git a/client/scene.h b/client/scene.h index 7935a3e4..bcc19f5b 100644 --- a/client/scene.h +++ b/client/scene.h @@ -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); }; diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 4564cd57..5de97638 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -123,6 +123,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptrnetwork_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); +} diff --git a/client/scenes/stream.h b/client/scenes/stream.h index b9d48cc7..04308402 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -75,6 +75,8 @@ private: std::unique_ptr network_session; std::atomic exiting = false; std::thread network_thread; + std::mutex local_floor_mutex; + xr::space local_floor = nullptr; std::atomic tracking_prediction_offset; std::optional tracking_thread; std::thread video_thread; @@ -220,5 +222,7 @@ private: void accumulate_metrics(XrTime predicted_display_time, const std::vector> & 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 diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index 95b1026c..488f367c 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -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();