mirror of
https://github.com/WiVRn/WiVRn.git
synced 2026-11-20 09:01:39 -08:00
94 lines
3.1 KiB
C++
94 lines
3.1 KiB
C++
/*
|
|
* WiVRn VR streaming
|
|
* Copyright (C) 2024 Guillaume Meunier <[email protected]>
|
|
* Copyright (C) 2024 Patrick Nicolas <[email protected]>
|
|
* Copyright (C) 2024 galister <[email protected]>
|
|
*
|
|
* 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_eye_tracker.h"
|
|
|
|
#include "wivrn_packets.h"
|
|
#include "wivrn_session.h"
|
|
#include "xrt/xrt_defines.h"
|
|
#include "xrt/xrt_device.h"
|
|
|
|
#include "util/u_device_id.h"
|
|
#include "util/u_logging.h"
|
|
#include "utils/method.h"
|
|
|
|
#include <cstdint>
|
|
#include <openxr/openxr.h>
|
|
|
|
namespace wivrn
|
|
{
|
|
|
|
wivrn_eye_tracker::wivrn_eye_tracker(wivrn_session & cnx) :
|
|
xrt_device{
|
|
.id = u_device_id_generate(),
|
|
.name = XRT_DEVICE_EYE_GAZE_INTERACTION,
|
|
.device_type = XRT_DEVICE_TYPE_EYE_TRACKER,
|
|
.str = "WiVRn Eye Tracker",
|
|
.serial = "WiVRn Eye Tracker",
|
|
.tracking_origin = &origin,
|
|
.input_count = 1,
|
|
.inputs = &gaze_input,
|
|
.supported = {
|
|
.eye_gaze = true,
|
|
},
|
|
.update_inputs = method_pointer<&wivrn_eye_tracker::update_inputs>,
|
|
.get_tracked_pose = method_pointer<&wivrn_eye_tracker::get_tracked_pose>,
|
|
.destroy = [](xrt_device *) {},
|
|
},
|
|
origin{
|
|
.type = XRT_TRACKING_TYPE_ATTACHABLE,
|
|
.initial_offset = XRT_POSE_IDENTITY,
|
|
},
|
|
gaze_input{
|
|
.active = true,
|
|
.name = XRT_INPUT_GENERIC_EYE_GAZE_POSE,
|
|
},
|
|
gaze(device_id::EYE_GAZE),
|
|
cnx(cnx)
|
|
{
|
|
}
|
|
|
|
xrt_result_t wivrn_eye_tracker::update_inputs()
|
|
{
|
|
return XRT_SUCCESS;
|
|
}
|
|
|
|
xrt_result_t wivrn_eye_tracker::get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * out_relation)
|
|
{
|
|
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);
|
|
return XRT_SUCCESS;
|
|
}
|
|
|
|
U_LOG_XDEV_UNSUPPORTED_INPUT(this, u_log_get_global_level(), name);
|
|
return XRT_ERROR_INPUT_UNSUPPORTED;
|
|
}
|
|
|
|
void wivrn_eye_tracker::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset)
|
|
{
|
|
gaze.update_tracking(tracking, offset);
|
|
}
|
|
} // namespace wivrn
|