switch to stage tracking on client
This commit is contained in:
committed by
Patrick Nicolas
parent
5e55e714aa
commit
2141c66c6e
@@ -131,7 +131,6 @@ 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->command_buffer = std::move(self->device.allocateCommandBuffers({
|
||||
@@ -714,7 +713,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
XrCompositionLayerProjection layer{
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_PROJECTION,
|
||||
.layerFlags = 0,
|
||||
.space = local_floor,
|
||||
.space = world_space,
|
||||
.viewCount = (uint32_t)layer_view.size(),
|
||||
.views = layer_view.data(),
|
||||
};
|
||||
@@ -1006,22 +1005,10 @@ scene::meta & scenes::stream::get_meta_scene()
|
||||
return m;
|
||||
}
|
||||
|
||||
void scenes::stream::update_local_floor(XrTime when)
|
||||
{
|
||||
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}, {location.pose.position.x, 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);
|
||||
if (space == XrReferenceSpaceType::XR_REFERENCE_SPACE_TYPE_LOCAL)
|
||||
{
|
||||
local_dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,10 +78,9 @@ 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;
|
||||
std::mutex tracking_control_mutex;
|
||||
to_headset::tracking_control tracking_control;
|
||||
std::atomic<bool> local_dirty = false;
|
||||
std::atomic<XrDuration> display_time_phase = 0;
|
||||
std::atomic<XrDuration> display_time_period = 0;
|
||||
std::optional<std::thread> tracking_thread;
|
||||
@@ -230,7 +229,6 @@ 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
|
||||
|
||||
@@ -255,14 +255,17 @@ void scenes::stream::tracking()
|
||||
j.fov = i.fov;
|
||||
}
|
||||
|
||||
packet.flags = flags;
|
||||
packet.view_flags = flags;
|
||||
|
||||
packet.state_flags = 0;
|
||||
if (local_dirty.exchange(false))
|
||||
packet.state_flags = xrt::drivers::wivrn::from_headset::tracking::recentered;
|
||||
|
||||
packet.device_poses.clear();
|
||||
std::lock_guard lock(local_floor_mutex);
|
||||
for (auto [device, space]: spaces)
|
||||
{
|
||||
if (enabled(control, device))
|
||||
packet.device_poses.push_back(locate_space(device, space, local_floor, t0 + Δt));
|
||||
packet.device_poses.push_back(locate_space(device, space, world_space, t0 + Δt));
|
||||
}
|
||||
|
||||
send_stream(packet);
|
||||
@@ -272,14 +275,14 @@ void scenes::stream::tracking()
|
||||
if (control.enabled[size_t(tid::left_hand)])
|
||||
{
|
||||
hands.hand = xrt::drivers::wivrn::from_headset::hand_tracking::left;
|
||||
hands.joints = locate_hands(application::get_left_hand(), local_floor, hands.timestamp);
|
||||
hands.joints = locate_hands(application::get_left_hand(), world_space, hands.timestamp);
|
||||
send_stream(hands);
|
||||
}
|
||||
|
||||
if (control.enabled[size_t(tid::right_hand)])
|
||||
{
|
||||
hands.hand = xrt::drivers::wivrn::from_headset::hand_tracking::right;
|
||||
hands.joints = locate_hands(application::get_right_hand(), local_floor, hands.timestamp);
|
||||
hands.joints = locate_hands(application::get_right_hand(), world_space, hands.timestamp);
|
||||
send_stream(hands);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +131,11 @@ struct tracking
|
||||
position_tracked = 1 << 5
|
||||
};
|
||||
|
||||
enum state_flags : uint8_t
|
||||
{
|
||||
recentered = 1 << 0,
|
||||
};
|
||||
|
||||
struct pose
|
||||
{
|
||||
device_id device;
|
||||
@@ -149,7 +154,9 @@ struct tracking
|
||||
|
||||
XrTime production_timestamp;
|
||||
XrTime timestamp;
|
||||
XrViewStateFlags flags;
|
||||
XrViewStateFlags view_flags;
|
||||
|
||||
uint8_t state_flags;
|
||||
|
||||
std::array<view, 2> views;
|
||||
std::vector<pose> device_poses;
|
||||
|
||||
@@ -45,7 +45,7 @@ bool view_list::update_tracking(const from_headset::tracking & tracking, const c
|
||||
tracked_views view{};
|
||||
|
||||
view.relation = pose_list::convert_pose(pose);
|
||||
view.flags = tracking.flags;
|
||||
view.flags = tracking.view_flags;
|
||||
|
||||
for (size_t eye = 0; eye < 2; ++eye)
|
||||
{
|
||||
|
||||
@@ -20,9 +20,11 @@
|
||||
#include "wivrn_session.h"
|
||||
|
||||
#include "accept_connection.h"
|
||||
#include "driver/xrt_cast.h"
|
||||
#include "main/comp_compositor.h"
|
||||
#include "main/comp_main_interface.h"
|
||||
#include "main/comp_target.h"
|
||||
#include "math/m_api.h"
|
||||
#include "util/u_builders.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "util/u_system.h"
|
||||
@@ -236,37 +238,38 @@ void wivrn_session::operator()(from_headset::headset_info_packet &&)
|
||||
}
|
||||
void wivrn_session::operator()(from_headset::tracking && tracking)
|
||||
{
|
||||
// Reset the tracking origin on reconnect
|
||||
if (tracking.timestamp == tracking.production_timestamp)
|
||||
if (tracking.state_flags & from_headset::tracking::state_flags::recentered)
|
||||
{
|
||||
for (const auto & p: tracking.device_poses)
|
||||
for (const auto & pose: tracking.device_poses)
|
||||
{
|
||||
if (p.device == device_id::HEAD)
|
||||
{
|
||||
if (p.flags & from_headset::tracking::flags::position_valid)
|
||||
{
|
||||
const auto & pos = p.pose.position;
|
||||
if (reconnect_offset.z != 0)
|
||||
{
|
||||
// Apply offset
|
||||
xrt_pose offset;
|
||||
auto tracking_origin = ((xrt_device *)hmd.get())->tracking_origin;
|
||||
space_overseer->get_tracking_origin_offset(space_overseer, tracking_origin, &offset);
|
||||
offset.position.x = reconnect_offset.x - pos.x;
|
||||
offset.position.y = reconnect_offset.y - pos.y;
|
||||
auto res = space_overseer->set_tracking_origin_offset(space_overseer, tracking_origin, &offset);
|
||||
U_LOG_I("Updated tracking origin, offset %f,%f",
|
||||
reconnect_offset.x - pos.x,
|
||||
reconnect_offset.y - pos.y);
|
||||
}
|
||||
// Store latest position
|
||||
reconnect_offset = {
|
||||
.x = pos.x,
|
||||
.y = pos.y,
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (pose.device != device_id::HEAD)
|
||||
continue;
|
||||
|
||||
xrt_pose offset;
|
||||
auto tracking_origin = ((xrt_device *)hmd.get())->tracking_origin;
|
||||
space_overseer->get_reference_space_offset(space_overseer, xrt_reference_space_type::XRT_SPACE_REFERENCE_TYPE_STAGE, &offset);
|
||||
|
||||
xrt_vec3 hmd_pos = xrt_cast(pose.pose.position);
|
||||
xrt_quat hmd_quat = xrt_cast(pose.pose.orientation);
|
||||
xrt_vec3 unit_z = XRT_VEC3_UNIT_Z;
|
||||
xrt_vec3 unit_y = XRT_VEC3_UNIT_Y;
|
||||
|
||||
xrt_vec3 hmd_z;
|
||||
math_quat_rotate_vec3(&hmd_quat, &unit_z, &hmd_z);
|
||||
|
||||
float angle_y = atan2(unit_z.x, unit_z.z) - atan2(hmd_z.x, hmd_z.z);
|
||||
|
||||
xrt_quat new_orientation;
|
||||
math_quat_from_angle_vector(-angle_y, &unit_y, &new_orientation);
|
||||
offset.orientation = new_orientation;
|
||||
offset.position.x = hmd_pos.x;
|
||||
offset.position.z = hmd_pos.z;
|
||||
|
||||
auto res = space_overseer->set_reference_space_offset(space_overseer, xrt_reference_space_type::XRT_SPACE_REFERENCE_TYPE_STAGE, &offset);
|
||||
if (res != XRT_SUCCESS)
|
||||
U_LOG_W("could not recenter: offset failed to apply!");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,9 +457,6 @@ void wivrn_session::reconnect()
|
||||
U_LOG_W("Failed to notify session state change");
|
||||
}
|
||||
|
||||
// Flag offset to be applied
|
||||
reconnect_offset.z = 1;
|
||||
|
||||
U_LOG_I("Waiting for new connection");
|
||||
auto tcp = accept_connection(0 /*stdin*/, [this]() { return quit_if_no_client(xrt_system); });
|
||||
if (not tcp)
|
||||
|
||||
@@ -83,7 +83,6 @@ class wivrn_session : public std::enable_shared_from_this<wivrn_session>
|
||||
|
||||
u_system & xrt_system;
|
||||
xrt_space_overseer * space_overseer;
|
||||
xrt_vec3 reconnect_offset{}; // z is used to store reconnect flag: 0 is none, non 0 means offset needs to be applied
|
||||
|
||||
std::atomic<bool> quit = false;
|
||||
std::thread thread;
|
||||
|
||||
Reference in New Issue
Block a user