Move tracking origin to prevent warp on reconnect
This commit is contained in:
@@ -173,6 +173,7 @@ xrt_result_t xrt::drivers::wivrn::wivrn_session::create_session(xrt::drivers::wi
|
|||||||
devices->xdev_count,
|
devices->xdev_count,
|
||||||
false,
|
false,
|
||||||
out_xspovrs);
|
out_xspovrs);
|
||||||
|
self->space_overseer = *out_xspovrs;
|
||||||
|
|
||||||
devices->destroy = [](xrt_system_devices * xsd) {
|
devices->destroy = [](xrt_system_devices * xsd) {
|
||||||
// TODO
|
// TODO
|
||||||
@@ -204,6 +205,40 @@ void wivrn_session::operator()(from_headset::headset_info_packet &&)
|
|||||||
}
|
}
|
||||||
void wivrn_session::operator()(from_headset::tracking && tracking)
|
void wivrn_session::operator()(from_headset::tracking && tracking)
|
||||||
{
|
{
|
||||||
|
// Reset the tracking origin on reconnect
|
||||||
|
if (tracking.timestamp == tracking.production_timestamp)
|
||||||
|
{
|
||||||
|
for (const auto & p: 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto offset = offset_est.get_offset();
|
auto offset = offset_est.get_offset();
|
||||||
if (not offset)
|
if (not offset)
|
||||||
return;
|
return;
|
||||||
@@ -332,6 +367,9 @@ void wivrn_session::reconnect()
|
|||||||
U_LOG_W("Failed to notify session state change");
|
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");
|
U_LOG_I("Waiting for new connection");
|
||||||
auto tcp = accept_connection(0 /*stdin*/, [this]() { return quit_if_no_client(xrt_system); });
|
auto tcp = accept_connection(0 /*stdin*/, [this]() { return quit_if_no_client(xrt_system); });
|
||||||
if (not tcp)
|
if (not tcp)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "clock_offset.h"
|
#include "clock_offset.h"
|
||||||
#include "wivrn_connection.h"
|
#include "wivrn_connection.h"
|
||||||
#include "wivrn_packets.h"
|
#include "wivrn_packets.h"
|
||||||
|
#include "xrt/xrt_defines.h"
|
||||||
#include "xrt/xrt_results.h"
|
#include "xrt/xrt_results.h"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@@ -69,6 +70,8 @@ class wivrn_session : public std::enable_shared_from_this<wivrn_session>
|
|||||||
wivrn_connection connection;
|
wivrn_connection connection;
|
||||||
|
|
||||||
u_system & xrt_system;
|
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::atomic<bool> quit = false;
|
||||||
std::thread thread;
|
std::thread thread;
|
||||||
|
|||||||
Reference in New Issue
Block a user