Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -97,6 +97,7 @@ if (WIVRN_BUILD_SERVER)
|
||||
driver/wivrn_eye_tracker.cpp
|
||||
driver/wivrn_fb_face2_tracker.cpp
|
||||
driver/wivrn_htc_face_tracker.cpp
|
||||
driver/wivrn_generic_tracker.cpp
|
||||
driver/wivrn_foveation.cpp
|
||||
driver/pose_list.cpp
|
||||
driver/view_list.cpp
|
||||
|
||||
@@ -234,6 +234,7 @@ static input_data map_input(device_id id)
|
||||
return {WIVRN_CONTROLLER_THUMBREST_FORCE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
|
||||
case device_id::RIGHT_STYLUS_FORCE:
|
||||
return {WIVRN_CONTROLLER_STYLUS_FORCE, wivrn_input_type::FLOAT, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
|
||||
default:
|
||||
break;
|
||||
}
|
||||
throw std::range_error("bad input id " + std::to_string((int)id));
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "wivrn_generic_tracker.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/method.h"
|
||||
#include "wivrn_session.h"
|
||||
|
||||
#include "math/m_api.h"
|
||||
#include "math/m_eigen_interop.hpp"
|
||||
#include "math/m_space.h"
|
||||
#include "math/m_vec3.h"
|
||||
#include "xrt/xrt_defines.h"
|
||||
#include "xrt/xrt_results.h"
|
||||
#include "xrt_cast.h"
|
||||
#include <chrono>
|
||||
#include <format>
|
||||
|
||||
using namespace xrt::auxiliary::math;
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
xrt_space_relation tracker_pose_list::interpolate(const xrt_space_relation & a, const xrt_space_relation & b, float t)
|
||||
{
|
||||
xrt_space_relation result;
|
||||
xrt_space_relation_flags flags = xrt_space_relation_flags(a.relation_flags & b.relation_flags);
|
||||
m_space_relation_interpolate(const_cast<xrt_space_relation *>(&a), const_cast<xrt_space_relation *>(&b), t, flags, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
xrt_space_relation tracker_pose_list::extrapolate(const xrt_space_relation & a, const xrt_space_relation & b, int64_t ta, int64_t tb, int64_t t)
|
||||
{
|
||||
float h = (tb - ta) / 1.e9;
|
||||
|
||||
xrt_space_relation res = t < ta ? a : b;
|
||||
|
||||
xrt_vec3 lin_vel = res.relation_flags & XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT ? res.linear_velocity : (b.pose.position - a.pose.position) / h;
|
||||
|
||||
float dt = (t - tb) / 1.e9;
|
||||
|
||||
float dt2_over_2 = dt * dt / 2;
|
||||
res.pose.position = res.pose.position + lin_vel * dt;
|
||||
|
||||
if (res.relation_flags & XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT)
|
||||
{
|
||||
xrt_vec3 dtheta = res.angular_velocity * dt;
|
||||
xrt_quat dq;
|
||||
math_quat_exp(&dtheta, &dq);
|
||||
|
||||
map_quat(res.pose.orientation) = map_quat(res.pose.orientation) * map_quat(dq);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool tracker_pose_list::update_tracking(XrTime produced_timestamp, XrTime timestamp, const from_headset::body_tracking::pose & pose, const clock_offset & offset)
|
||||
{
|
||||
return add_sample(produced_timestamp, timestamp, convert_pose(pose), offset);
|
||||
}
|
||||
|
||||
std::pair<std::chrono::nanoseconds, xrt_space_relation> tracker_pose_list::get_pose_at(XrTime at_timestamp_ns)
|
||||
{
|
||||
return get_at(at_timestamp_ns);
|
||||
}
|
||||
|
||||
static xrt_space_relation_flags convert_flags(uint8_t flags)
|
||||
{
|
||||
std::underlying_type_t<xrt_space_relation_flags> out_flags = 0;
|
||||
if (flags & from_headset::body_tracking::orientation_valid)
|
||||
out_flags |= XRT_SPACE_RELATION_ORIENTATION_VALID_BIT;
|
||||
if (flags & from_headset::body_tracking::position_valid)
|
||||
out_flags |= XRT_SPACE_RELATION_POSITION_VALID_BIT;
|
||||
|
||||
if (flags & from_headset::body_tracking::orientation_tracked)
|
||||
out_flags |= XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT;
|
||||
if (flags & from_headset::body_tracking::position_tracked)
|
||||
out_flags |= XRT_SPACE_RELATION_POSITION_TRACKED_BIT;
|
||||
|
||||
return xrt_space_relation_flags(out_flags);
|
||||
}
|
||||
|
||||
xrt_space_relation tracker_pose_list::convert_pose(const from_headset::body_tracking::pose & pose)
|
||||
{
|
||||
return xrt_space_relation{
|
||||
.relation_flags = convert_flags(pose.flags),
|
||||
.pose = xrt_cast(pose.pose),
|
||||
.linear_velocity = {},
|
||||
.angular_velocity = {},
|
||||
};
|
||||
}
|
||||
|
||||
wivrn_generic_tracker::wivrn_generic_tracker(int index, xrt_device * hmd, wivrn_session & cnx) :
|
||||
xrt_device{
|
||||
.name = XRT_DEVICE_VIVE_TRACKER,
|
||||
.device_type = XRT_DEVICE_TYPE_GENERIC_TRACKER,
|
||||
.hmd = nullptr,
|
||||
.tracking_origin = hmd->tracking_origin,
|
||||
.orientation_tracking_supported = true,
|
||||
.position_tracking_supported = true,
|
||||
.update_inputs = method_pointer<&wivrn_generic_tracker::update_inputs>,
|
||||
.get_tracked_pose = method_pointer<&wivrn_generic_tracker::get_tracked_pose>,
|
||||
.destroy = [](xrt_device *) {},
|
||||
},
|
||||
cnx(cnx),
|
||||
index(index)
|
||||
{
|
||||
auto unique_name = std::format("WiVRn Generic Tracker #{}", index + 1);
|
||||
strlcpy(str, unique_name.c_str(), std::size(str));
|
||||
strlcpy(serial, unique_name.c_str(), std::size(serial));
|
||||
|
||||
pose_input.name = XRT_INPUT_GENERIC_TRACKER_POSE;
|
||||
pose_input.active = true;
|
||||
|
||||
inputs = &pose_input;
|
||||
input_count = 1;
|
||||
}
|
||||
|
||||
#define XRT_INPUT_NAME_CASE(NAME, VALUE) \
|
||||
case VALUE: \
|
||||
return #NAME;
|
||||
|
||||
const char * input_name_str(xrt_input_name name)
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
XRT_INPUT_LIST(XRT_INPUT_NAME_CASE)
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
xrt_result_t wivrn_generic_tracker::update_inputs()
|
||||
{
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
xrt_result_t wivrn_generic_tracker::get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * res)
|
||||
{
|
||||
std::chrono::nanoseconds extrapolation_time;
|
||||
|
||||
if (name == XRT_INPUT_GENERIC_TRACKER_POSE)
|
||||
{
|
||||
std::tie(extrapolation_time, *res) = poses.get_pose_at(at_timestamp_ns);
|
||||
|
||||
cnx.set_tracker_enabled(index, true);
|
||||
cnx.add_predict_offset(extrapolation_time);
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
|
||||
U_LOG_D("Unknown input name %s", input_name_str(name));
|
||||
return XRT_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void wivrn_generic_tracker::update_tracking(const from_headset::body_tracking & tracking, const from_headset::body_tracking::pose & pose, const clock_offset & offset)
|
||||
{
|
||||
if (!poses.update_tracking(tracking.production_timestamp, tracking.timestamp, pose, offset))
|
||||
cnx.set_tracker_enabled(index, false);
|
||||
}
|
||||
} // namespace wivrn
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Sapphire <imsapphire0@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "history.h"
|
||||
#include "xrt/xrt_device.h"
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
class wivrn_session;
|
||||
struct clock_offset;
|
||||
|
||||
class tracker_pose_list : public history<tracker_pose_list, xrt_space_relation>
|
||||
{
|
||||
public:
|
||||
static xrt_space_relation interpolate(const xrt_space_relation & a, const xrt_space_relation & b, float t);
|
||||
static xrt_space_relation extrapolate(const xrt_space_relation & a, const xrt_space_relation & b, int64_t ta, int64_t tb, int64_t t);
|
||||
|
||||
tracker_pose_list() = default;
|
||||
|
||||
bool update_tracking(XrTime produced_timestamp, XrTime timestamp, const from_headset::body_tracking::pose & pose, const clock_offset & offset);
|
||||
|
||||
std::pair<std::chrono::nanoseconds, xrt_space_relation> get_pose_at(XrTime at_timestamp_ns);
|
||||
|
||||
static xrt_space_relation convert_pose(const wivrn::from_headset::body_tracking::pose &);
|
||||
};
|
||||
|
||||
class wivrn_generic_tracker : public xrt_device
|
||||
{
|
||||
tracker_pose_list poses;
|
||||
xrt_input pose_input;
|
||||
|
||||
wivrn_session & cnx;
|
||||
int index;
|
||||
|
||||
public:
|
||||
using base = xrt_device;
|
||||
wivrn_generic_tracker(int index, xrt_device * hmd, wivrn_session & cnx);
|
||||
|
||||
xrt_result_t update_inputs();
|
||||
xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * out_relation);
|
||||
|
||||
void update_tracking(const from_headset::body_tracking & tracking, const from_headset::body_tracking::pose & pose, const clock_offset & offset);
|
||||
};
|
||||
} // namespace wivrn
|
||||
@@ -34,12 +34,15 @@
|
||||
#include "wivrn_config.h"
|
||||
#include "wivrn_eye_tracker.h"
|
||||
#include "wivrn_fb_face2_tracker.h"
|
||||
#include "wivrn_generic_tracker.h"
|
||||
#include "wivrn_htc_face_tracker.h"
|
||||
#include "wivrn_ipc.h"
|
||||
|
||||
#include "wivrn_packets.h"
|
||||
#include "xrt/xrt_device.h"
|
||||
#include "xrt/xrt_session.h"
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <magic_enum.hpp>
|
||||
#include <stdexcept>
|
||||
#include <string.h>
|
||||
@@ -116,12 +119,19 @@ void wivrn::tracking_control_t::send(wivrn_connection & connection, bool now)
|
||||
next_sample += std::chrono::seconds(1);
|
||||
}
|
||||
|
||||
bool wivrn::tracking_control_t::get_enabled(to_headset::tracking_control::id id)
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
return this->enabled[size_t(id)];
|
||||
}
|
||||
bool wivrn::tracking_control_t::set_enabled(to_headset::tracking_control::id id, bool enabled)
|
||||
{
|
||||
std::lock_guard lock(mutex);
|
||||
bool changed = enabled != this->enabled[size_t(id)];
|
||||
if (changed)
|
||||
U_LOG_I("%s tracking: %s", std::string(magic_enum::enum_name(id)).c_str(), enabled ? "enabled" : "disabled");
|
||||
if (!changed)
|
||||
return false;
|
||||
|
||||
U_LOG_I("%s tracking: %s", std::string(magic_enum::enum_name(id)).c_str(), enabled ? "enabled" : "disabled");
|
||||
this->enabled[size_t(id)] = enabled;
|
||||
return changed;
|
||||
}
|
||||
@@ -215,6 +225,21 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
|
||||
xdevs[xdev_count++] = htc_face_tracker.get();
|
||||
}
|
||||
|
||||
num_generic_trackers = get_info().num_generic_trackers;
|
||||
enabled_trackers.fill(false);
|
||||
if (num_generic_trackers > 0)
|
||||
{
|
||||
U_LOG_I("Creating %d generic trackers", num_generic_trackers);
|
||||
|
||||
for (int i = 0; i < num_generic_trackers; ++i)
|
||||
{
|
||||
auto dev = std::make_unique<wivrn_generic_tracker>(i, &hmd, *this);
|
||||
xdevs[xdev_count++] = dev.get();
|
||||
generic_trackers[i] = std::move(dev);
|
||||
enabled_trackers[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
#if WIVRN_FEATURE_SOLARXR
|
||||
uint32_t num_devs = solarxr_device_create_xdevs(&hmd.tracking_origin, &xdevs[xdev_count], ARRAY_SIZE(xdevs) - xdev_count);
|
||||
if (num_devs != 0)
|
||||
@@ -429,6 +454,19 @@ void wivrn_session::operator()(from_headset::hand_tracking && hand_tracking)
|
||||
left_hand.update_hand_tracking(hand_tracking, offset);
|
||||
right_hand.update_hand_tracking(hand_tracking, offset);
|
||||
}
|
||||
void wivrn_session::operator()(from_headset::body_tracking && body_tracking)
|
||||
{
|
||||
auto offset = offset_est.get_offset();
|
||||
|
||||
for (int i = 0; i < num_generic_trackers; i++)
|
||||
{
|
||||
auto pose = body_tracking.poses ? body_tracking.poses->at(i) : from_headset::body_tracking::pose{
|
||||
.pose = {},
|
||||
.flags = 0,
|
||||
};
|
||||
generic_trackers[i]->update_tracking(body_tracking, pose, offset);
|
||||
}
|
||||
}
|
||||
void wivrn_session::operator()(from_headset::inputs && inputs)
|
||||
{
|
||||
auto offset = get_offset();
|
||||
@@ -475,6 +513,14 @@ void wivrn_session::set_enabled(device_id id, bool enabled)
|
||||
if (tracking_control.set_enabled(to_tracking_control(id), enabled) and enabled)
|
||||
tracking_control.send(*connection, true);
|
||||
}
|
||||
void wivrn_session::set_tracker_enabled(int index, bool enabled)
|
||||
{
|
||||
assert(index < std::size(enabled_trackers));
|
||||
enabled_trackers[index] = enabled;
|
||||
bool keep_active = std::ranges::any_of(enabled_trackers, [](bool b) { return b; });
|
||||
if (tracking_control.set_enabled(to_headset::tracking_control::id::generic_tracker, keep_active))
|
||||
tracking_control.send(*connection, true);
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(from_headset::feedback && feedback)
|
||||
{
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
struct u_system;
|
||||
struct xrt_space_overseer;
|
||||
@@ -44,6 +45,7 @@ namespace wivrn
|
||||
class wivrn_eye_tracker;
|
||||
class wivrn_fb_face2_tracker;
|
||||
class wivrn_htc_face_tracker;
|
||||
class wivrn_generic_tracker;
|
||||
struct audio_device;
|
||||
struct wivrn_comp_target;
|
||||
struct wivrn_comp_target_factory;
|
||||
@@ -80,6 +82,7 @@ public:
|
||||
}
|
||||
void send(wivrn_connection & connection, bool now = false);
|
||||
|
||||
bool get_enabled(to_headset::tracking_control::id id);
|
||||
// Return true if value changed
|
||||
bool set_enabled(to_headset::tracking_control::id id, bool enabled);
|
||||
};
|
||||
@@ -107,6 +110,9 @@ class wivrn_session : public xrt_system_devices
|
||||
std::unique_ptr<wivrn_eye_tracker> eye_tracker;
|
||||
std::unique_ptr<wivrn_fb_face2_tracker> fb_face2_tracker;
|
||||
std::unique_ptr<wivrn_htc_face_tracker> htc_face_tracker;
|
||||
uint32_t num_generic_trackers;
|
||||
std::array<std::unique_ptr<wivrn_generic_tracker>, from_headset::body_tracking::max_tracked_poses> generic_trackers;
|
||||
std::array<bool, from_headset::body_tracking::max_tracked_poses> enabled_trackers;
|
||||
std::shared_ptr<wivrn_comp_target> comp_target;
|
||||
|
||||
clock_offset_estimator offset_est;
|
||||
@@ -152,6 +158,7 @@ public:
|
||||
|
||||
void set_enabled(to_headset::tracking_control::id id, bool enabled);
|
||||
void set_enabled(device_id id, bool enabled);
|
||||
void set_tracker_enabled(int index, bool enabled);
|
||||
|
||||
void operator()(from_headset::crypto_handshake &&) {}
|
||||
void operator()(from_headset::pin_check_1 &&) {}
|
||||
@@ -162,6 +169,7 @@ public:
|
||||
void operator()(const from_headset::tracking &);
|
||||
void operator()(from_headset::derived_pose &&);
|
||||
void operator()(from_headset::hand_tracking &&);
|
||||
void operator()(from_headset::body_tracking &&);
|
||||
void operator()(from_headset::inputs &&);
|
||||
void operator()(from_headset::timesync_response &&);
|
||||
void operator()(from_headset::feedback &&);
|
||||
|
||||
Reference in New Issue
Block a user