diff --git a/server/driver/polynomial_interpolator.h b/server/driver/polynomial_interpolator.h index 94504482..6d366dde 100644 --- a/server/driver/polynomial_interpolator.h +++ b/server/driver/polynomial_interpolator.h @@ -100,7 +100,24 @@ public: } } - sample get_at(XrTime timestamp) + std::pair get_bounds() const + { + std::pair result{ + std::numeric_limits::max(), + std::numeric_limits::lowest(), + }; + for (const auto & sample: data) + { + if (sample.y) + { + result.first = std::min(result.first, sample.timestamp); + result.second = std::max(result.second, sample.timestamp); + } + } + return result; + } + + sample get_at(XrTime timestamp) const { Eigen::Matrix A; Eigen::Matrix b; diff --git a/server/driver/pose_list.cpp b/server/driver/pose_list.cpp index d4179106..a091c261 100644 --- a/server/driver/pose_list.cpp +++ b/server/driver/pose_list.cpp @@ -100,6 +100,11 @@ pose_list::pose_list(wivrn::device_id id) : device(id) dumper.emplace(dump); } +std::pair pose_list::get_bounds() const +{ + return positions.get_bounds(); +} + void pose_list::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset) { if (source) diff --git a/server/driver/pose_list.h b/server/driver/pose_list.h index d64151a8..da70e720 100644 --- a/server/driver/pose_list.h +++ b/server/driver/pose_list.h @@ -63,6 +63,8 @@ public: pose_list(wivrn::device_id id); + std::pair get_bounds() const; + void update_tracking(const wivrn::from_headset::tracking &, const clock_offset & offset); void set_derived(pose_list * source, xrt_pose offset, bool force = false); diff --git a/server/driver/wivrn_eye_tracker.cpp b/server/driver/wivrn_eye_tracker.cpp index 88d3866a..3b332cf6 100644 --- a/server/driver/wivrn_eye_tracker.cpp +++ b/server/driver/wivrn_eye_tracker.cpp @@ -72,6 +72,8 @@ xrt_result_t wivrn_eye_tracker::get_tracked_pose(xrt_input_name name, int64_t at { if (name == XRT_INPUT_GENERIC_EYE_GAZE_POSE) { + if (auto [min, max] = gaze.get_bounds(); min <= max) + at_timestamp_ns = std::clamp(at_timestamp_ns, min, max); auto [production_timestamp, relation] = gaze.get_at(at_timestamp_ns); *out_relation = relation; cnx.add_tracking_request(device_id::EYE_GAZE, at_timestamp_ns, production_timestamp);