diff --git a/alvr/server_openvr/cpp/alvr_server/Controller.cpp b/alvr/server_openvr/cpp/alvr_server/Controller.cpp index 25237c6170..e6df500154 100644 --- a/alvr/server_openvr/cpp/alvr_server/Controller.cpp +++ b/alvr/server_openvr/cpp/alvr_server/Controller.cpp @@ -8,40 +8,22 @@ #include #include -vr::ETrackedDeviceClass Controller::getControllerDeviceClass() { - if (Settings::Instance().m_controllerIsTracker) - return vr::TrackedDeviceClass_GenericTracker; - return vr::TrackedDeviceClass_Controller; -} - Controller::Controller(uint64_t deviceID, vr::EVRSkeletalTrackingLevel skeletonLevel) - : TrackedDevice(deviceID) + : TrackedDevice( + deviceID, + Settings::Instance().m_controllerIsTracker ? vr::TrackedDeviceClass_GenericTracker + : vr::TrackedDeviceClass_Controller + ) , m_skeletonLevel(skeletonLevel) { Debug("Controller::constructor deviceID=%llu", deviceID); - - m_pose = vr::DriverPose_t {}; - m_pose.poseIsValid = false; - m_pose.deviceIsConnected = false; - m_pose.result = vr::TrackingResult_Uninitialized; - - m_pose.qDriverFromHeadRotation = HmdQuaternion_Init(1, 0, 0, 0); - m_pose.qWorldFromDriverRotation = HmdQuaternion_Init(1, 0, 0, 0); - m_pose.qRotation = HmdQuaternion_Init(1, 0, 0, 0); } -// -// ITrackedDeviceServerDriver -// - -vr::EVRInitError Controller::Activate(vr::TrackedDeviceIndex_t unObjectId) { +bool Controller::activate() { Debug("Controller::Activate deviceID=%llu", this->device_id); auto vr_properties = vr::VRProperties(); auto vr_driver_input = vr::VRDriverInput(); - this->object_id = unObjectId; - this->prop_container = vr_properties->TrackedDeviceToPropertyContainer(this->object_id); - SetOpenvrProps(this->device_id); RegisterButtons(this->device_id); @@ -120,38 +102,9 @@ vr::EVRInitError Controller::Activate(vr::TrackedDeviceIndex_t unObjectId) { ); } - return vr::VRInitError_None; -} - -void Controller::Deactivate() { - Debug("Controller::Deactivate deviceID=%llu", this->device_id); - this->object_id = vr::k_unTrackedDeviceIndexInvalid; -} - -void Controller::EnterStandby() { } - -void* Controller::GetComponent(const char* pchComponentNameAndVersion) { - Debug( - "Controller::GetComponent deviceID=%llu Name=%hs", - this->device_id, - pchComponentNameAndVersion - ); - - return NULL; + return true; } -void PowerOff() { } - -/** debug request from a client */ -void Controller::DebugRequest( - const char* /*pchRequest*/, char* pchResponseBuffer, uint32_t unResponseBufferSize -) { - if (unResponseBufferSize >= 1) - pchResponseBuffer[0] = 0; -} - -vr::DriverPose_t Controller::GetPose() { return m_pose; } - vr::VRInputComponentHandle_t Controller::getHapticComponent() { return m_compHaptic; } void Controller::RegisterButton(uint64_t id) { @@ -190,7 +143,7 @@ void Controller::RegisterButton(uint64_t id) { void Controller::SetButton(uint64_t id, FfiButtonValue value) { Debug("Controller::SetButton deviceID=%llu buttonID=%llu", this->device_id, id); - if (!this->isEnabled()) { + if (!this->last_pose.poseIsValid) { return; } @@ -220,7 +173,7 @@ void Controller::SetButton(uint64_t id, FfiButtonValue value) { } } -bool Controller::onPoseUpdate(uint64_t targetTimestampNs, float predictionS, FfiHandData handData) { +bool Controller::OnPoseUpdate(uint64_t targetTimestampNs, float predictionS, FfiHandData handData) { if (this->object_id == vr::k_unTrackedDeviceIndexInvalid) { return false; } @@ -287,14 +240,15 @@ bool Controller::onPoseUpdate(uint64_t targetTimestampNs, float predictionS, Ffi double linearVelocity[3] = { 0.0, 0.0, 0.0 }; vr::HmdVector3d_t angularVelocity = { 0.0, 0.0, 0.0 }; - if (m_pose.poseIsValid) { + if (this->last_pose.poseIsValid) { double dt = ((double)targetTimestampNs - (double)m_poseTargetTimestampNs) / NS_PER_S; if (dt > 0.0) { - linearVelocity[0] = (pose.vecPosition[0] - m_pose.vecPosition[0]) / dt; - linearVelocity[1] = (pose.vecPosition[1] - m_pose.vecPosition[1]) / dt; - linearVelocity[2] = (pose.vecPosition[2] - m_pose.vecPosition[2]) / dt; - angularVelocity = AngularVelocityBetweenQuats(m_pose.qRotation, pose.qRotation, dt); + linearVelocity[0] = (pose.vecPosition[0] - this->last_pose.vecPosition[0]) / dt; + linearVelocity[1] = (pose.vecPosition[1] - this->last_pose.vecPosition[1]) / dt; + linearVelocity[2] = (pose.vecPosition[2] - this->last_pose.vecPosition[2]) / dt; + angularVelocity + = AngularVelocityBetweenQuats(this->last_pose.qRotation, pose.qRotation, dt); } } @@ -309,12 +263,9 @@ bool Controller::onPoseUpdate(uint64_t targetTimestampNs, float predictionS, Ffi pose.poseTimeOffset = predictionS; - m_pose = pose; - m_poseTargetTimestampNs = targetTimestampNs; + this->submit_pose(pose); - vr::VRServerDriverHost()->TrackedDevicePoseUpdated( - this->object_id, pose, sizeof(vr::DriverPose_t) - ); + m_poseTargetTimestampNs = targetTimestampNs; // Early return to skip updating the skeleton if (!enabled) { diff --git a/alvr/server_openvr/cpp/alvr_server/Controller.h b/alvr/server_openvr/cpp/alvr_server/Controller.h index 975b51a0fc..10caa39bdb 100644 --- a/alvr/server_openvr/cpp/alvr_server/Controller.h +++ b/alvr/server_openvr/cpp/alvr_server/Controller.h @@ -5,43 +5,13 @@ #include "openvr_driver.h" #include -class Controller : public TrackedDevice, public vr::ITrackedDeviceServerDriver { +class Controller : public TrackedDevice { public: Controller(uint64_t deviceID, vr::EVRSkeletalTrackingLevel skeletonLevel); - virtual ~Controller() {}; - - // - // ITrackedDeviceServerDriver - // - - virtual vr::EVRInitError Activate(vr::TrackedDeviceIndex_t unObjectId); - - virtual void Deactivate(); - - virtual void EnterStandby(); - - void* GetComponent(const char* pchComponentNameAndVersion); - - virtual void PowerOff() {}; - - /** debug request from a client */ - virtual void - DebugRequest(const char* pchRequest, char* pchResponseBuffer, uint32_t unResponseBufferSize); - - virtual vr::DriverPose_t GetPose(); - - vr::VRInputComponentHandle_t getHapticComponent(); - void RegisterButton(uint64_t id); - void SetButton(uint64_t id, FfiButtonValue value); - - bool onPoseUpdate(uint64_t targetTimestampNs, float predictionS, FfiHandData handData); - - void GetBoneTransform(bool withController, vr::VRBoneTransform_t outBoneTransform[]); - - vr::ETrackedDeviceClass getControllerDeviceClass(); + bool OnPoseUpdate(uint64_t targetTimestampNs, float predictionS, FfiHandData handData); private: static const int SKELETON_BONE_COUNT = 31; @@ -53,7 +23,6 @@ class Controller : public TrackedDevice, public vr::ITrackedDeviceServerDriver { vr::VRInputComponentHandle_t m_compSkeleton = vr::k_ulInvalidInputComponentHandle; vr::EVRSkeletalTrackingLevel m_skeletonLevel; - vr::DriverPose_t m_pose; uint64_t m_poseTargetTimestampNs; // These variables are used for controller hand animation @@ -67,5 +36,10 @@ class Controller : public TrackedDevice, public vr::ITrackedDeviceServerDriver { float m_triggerValue = 0; float m_gripValue = 0; - bool isEnabled() { return m_pose.deviceIsConnected; } + vr::VRInputComponentHandle_t getHapticComponent(); + void GetBoneTransform(bool withController, vr::VRBoneTransform_t outBoneTransform[]); + + // TrackedDevice + bool activate() final; + void* get_component(const char* component_name_and_version) final { return nullptr; } }; diff --git a/alvr/server_openvr/cpp/alvr_server/HMD.cpp b/alvr/server_openvr/cpp/alvr_server/HMD.cpp index 43b716c92b..72d9db461d 100644 --- a/alvr/server_openvr/cpp/alvr_server/HMD.cpp +++ b/alvr/server_openvr/cpp/alvr_server/HMD.cpp @@ -32,7 +32,11 @@ vr::HmdRect2_t fov_to_projection(FfiFov fov) { } Hmd::Hmd() - : TrackedDevice(HEAD_ID) + : TrackedDevice( + HEAD_ID, + Settings::Instance().m_TrackingRefOnly ? vr::TrackedDeviceClass_TrackingReference + : vr::TrackedDeviceClass_HMD + ) , m_baseComponentsInitialized(false) , m_streamComponentsInitialized(false) { Debug("Hmd::constructor"); @@ -44,20 +48,8 @@ Hmd::Hmd() this->views_config.fov[0] = dummy_fov; this->views_config.fov[1] = dummy_fov; - m_pose = vr::DriverPose_t {}; - m_pose.poseIsValid = true; - m_pose.result = vr::TrackingResult_Running_OK; - m_pose.deviceIsConnected = true; - m_pose.qWorldFromDriverRotation = HmdQuaternion_Init(1, 0, 0, 0); - m_pose.qDriverFromHeadRotation = HmdQuaternion_Init(1, 0, 0, 0); - m_pose.qRotation = HmdQuaternion_Init(1, 0, 0, 0); - m_poseHistory = std::make_shared(); - m_deviceClass = Settings::Instance().m_TrackingRefOnly - ? vr::TrackedDeviceClass_TrackingReference - : vr::TrackedDeviceClass_HMD; - if (Settings::Instance().m_enableViveTrackerProxy) { m_viveTrackerProxy = std::make_unique(*this); if (!vr::VRServerDriverHost()->TrackedDeviceAdded( @@ -87,14 +79,11 @@ Hmd::~Hmd() { #endif } -vr::EVRInitError Hmd::Activate(vr::TrackedDeviceIndex_t unObjectId) { +bool Hmd::activate() { Debug("Hmd::Activate"); auto vr_properties = vr::VRProperties(); - this->object_id = unObjectId; - this->prop_container = vr_properties->TrackedDeviceToPropertyContainer(this->object_id); - SetOpenvrProps(this->device_id); vr_properties->SetFloatProperty( @@ -133,7 +122,7 @@ vr::EVRInitError Hmd::Activate(vr::TrackedDeviceIndex_t unObjectId) { if (!m_baseComponentsInitialized) { m_baseComponentsInitialized = true; - if (IsHMD()) { + if (this->device_class == vr::TrackedDeviceClass_HMD) { #ifdef _WIN32 m_D3DRender = std::make_shared(); @@ -150,13 +139,13 @@ vr::EVRInitError Hmd::Activate(vr::TrackedDeviceIndex_t unObjectId) { "graphics cards.\n", Settings::Instance().m_nAdapterIndex ); - return vr::VRInitError_Driver_Failed; + return false; } int32_t nDisplayAdapterIndex; if (!m_D3DRender->GetAdapterInfo(&nDisplayAdapterIndex, m_adapterName)) { Error("Failed to get primary adapter info!\n"); - return vr::VRInitError_Driver_Failed; + return false; } Info("Using %ls as primary graphics adapter.\n", m_adapterName.c_str()); @@ -167,10 +156,10 @@ vr::EVRInitError Hmd::Activate(vr::TrackedDeviceIndex_t unObjectId) { #endif } - DriverReadyIdle(IsHMD()); + DriverReadyIdle(this->device_class == vr::TrackedDeviceClass_HMD); } - if (IsHMD()) { + if (this->device_class == vr::TrackedDeviceClass_HMD) { vr::VREvent_Data_t eventData; eventData.ipd = { 0.063 }; vr::VRServerDriverHost()->VendorSpecificEvent( @@ -178,17 +167,10 @@ vr::EVRInitError Hmd::Activate(vr::TrackedDeviceIndex_t unObjectId) { ); } - return vr::VRInitError_None; -} - -void Hmd::Deactivate() { - Debug("Hmd::Deactivate"); - - this->object_id = vr::k_unTrackedDeviceIndexInvalid; - this->prop_container = vr::k_ulInvalidPropertyContainer; + return true; } -void* Hmd::GetComponent(const char* component_name_and_version) { +void* Hmd::get_component(const char* component_name_and_version) { Debug("Hmd::GetComponent %s", component_name_and_version); // NB: "this" pointer needs to be statically cast to point to the correct vtable @@ -207,8 +189,6 @@ void* Hmd::GetComponent(const char* component_name_and_version) { return nullptr; } -vr::DriverPose_t Hmd::GetPose() { return m_pose; } - void Hmd::OnPoseUpdated(uint64_t targetTimestampNs, FfiDeviceMotion motion) { Debug("Hmd::OnPoseUpdated"); @@ -231,14 +211,10 @@ void Hmd::OnPoseUpdated(uint64_t targetTimestampNs, FfiDeviceMotion motion) { pose.vecPosition[1] = motion.position[1]; pose.vecPosition[2] = motion.position[2]; - m_pose = pose; + this->submit_pose(pose); m_poseHistory->OnPoseUpdated(targetTimestampNs, motion); - vr::VRServerDriverHost()->TrackedDevicePoseUpdated( - this->object_id, pose, sizeof(vr::DriverPose_t) - ); - if (m_viveTrackerProxy) m_viveTrackerProxy->update(); @@ -266,7 +242,7 @@ void Hmd::StartStreaming() { } // Spin up a separate thread to handle the overlapped encoding/transmit step. - if (IsHMD()) { + if (this->device_class == vr::TrackedDeviceClass_HMD) { #ifdef _WIN32 m_encoder = std::make_shared(); try { diff --git a/alvr/server_openvr/cpp/alvr_server/HMD.h b/alvr/server_openvr/cpp/alvr_server/HMD.h index 9395386ad1..d5502b4639 100644 --- a/alvr/server_openvr/cpp/alvr_server/HMD.h +++ b/alvr/server_openvr/cpp/alvr_server/HMD.h @@ -18,55 +18,25 @@ class CD3DRender; #endif class PoseHistory; -class Hmd : public TrackedDevice, public vr::ITrackedDeviceServerDriver, vr::IVRDisplayComponent { +class Hmd : public TrackedDevice, vr::IVRDisplayComponent { public: - Hmd(); + std::shared_ptr m_poseHistory; + std::shared_ptr m_encoder; + Hmd(); virtual ~Hmd(); - - virtual vr::EVRInitError Activate(vr::TrackedDeviceIndex_t unObjectId); - virtual void Deactivate(); - virtual void EnterStandby() { } - void* GetComponent(const char* pchComponentNameAndVersion); - virtual void DebugRequest(const char*, char*, uint32_t) { } - virtual vr::DriverPose_t GetPose(); - void OnPoseUpdated(uint64_t targetTimestampNs, FfiDeviceMotion motion); - void StartStreaming(); - void StopStreaming(); - void SetViewsConfig(FfiViewsConfig config); - vr::ETrackedDeviceClass GetDeviceClass() const { return m_deviceClass; } - bool IsTrackingRef() const { return m_deviceClass == vr::TrackedDeviceClass_TrackingReference; } - bool IsHMD() const { return m_deviceClass == vr::TrackedDeviceClass_HMD; } - - // IVRDisplayComponent - - virtual void GetWindowBounds(int32_t* x, int32_t* y, uint32_t* width, uint32_t* height); - virtual bool IsDisplayOnDesktop() { return false; } - virtual bool IsDisplayRealDisplay(); - virtual void GetRecommendedRenderTargetSize(uint32_t* width, uint32_t* height); - virtual void GetEyeOutputViewport( - vr::EVREye eye, uint32_t* x, uint32_t* y, uint32_t* width, uint32_t* height - ); - virtual void - GetProjectionRaw(vr::EVREye eEye, float* pfLeft, float* pfRight, float* pfTop, float* pfBottom); - virtual vr::DistortionCoordinates_t ComputeDistortion(vr::EVREye eEye, float fU, float fV); - +private: vr::VRInputComponentHandle_t m_proximity; - std::shared_ptr m_encoder; - std::shared_ptr m_poseHistory; - -private: FfiViewsConfig views_config; bool m_baseComponentsInitialized; bool m_streamComponentsInitialized; - vr::ETrackedDeviceClass m_deviceClass; vr::HmdMatrix34_t m_eyeToHeadLeft; vr::HmdMatrix34_t m_eyeToHeadRight; @@ -85,9 +55,23 @@ class Hmd : public TrackedDevice, public vr::ITrackedDeviceServerDriver, vr::IVR std::shared_ptr m_viveTrackerProxy; - vr::DriverPose_t m_pose = {}; - #ifndef _WIN32 bool m_refreshRateSet = false; #endif + + // TrackedDevice + virtual bool activate() final; + virtual void* get_component(const char* component_name_and_version) final; + + // IVRDisplayComponent + virtual void GetWindowBounds(int32_t* x, int32_t* y, uint32_t* width, uint32_t* height); + virtual bool IsDisplayOnDesktop() { return false; } + virtual bool IsDisplayRealDisplay(); + virtual void GetRecommendedRenderTargetSize(uint32_t* width, uint32_t* height); + virtual void GetEyeOutputViewport( + vr::EVREye eye, uint32_t* x, uint32_t* y, uint32_t* width, uint32_t* height + ); + virtual void + GetProjectionRaw(vr::EVREye eEye, float* pfLeft, float* pfRight, float* pfTop, float* pfBottom); + virtual vr::DistortionCoordinates_t ComputeDistortion(vr::EVREye eEye, float fU, float fV); }; diff --git a/alvr/server_openvr/cpp/alvr_server/TrackedDevice.cpp b/alvr/server_openvr/cpp/alvr_server/TrackedDevice.cpp index 3d18e40978..9926bdf555 100644 --- a/alvr/server_openvr/cpp/alvr_server/TrackedDevice.cpp +++ b/alvr/server_openvr/cpp/alvr_server/TrackedDevice.cpp @@ -1,5 +1,19 @@ #include "TrackedDevice.h" #include "Logger.h" +#include "Utils.h" + +TrackedDevice::TrackedDevice(uint64_t device_id, vr::ETrackedDeviceClass device_class) + : device_id(device_id) + , device_class(device_class) { + this->last_pose = vr::DriverPose_t {}; + this->last_pose.poseIsValid = false; + this->last_pose.deviceIsConnected = false; + this->last_pose.result = vr::TrackingResult_Uninitialized; + + this->last_pose.qDriverFromHeadRotation = HmdQuaternion_Init(1, 0, 0, 0); + this->last_pose.qWorldFromDriverRotation = HmdQuaternion_Init(1, 0, 0, 0); + this->last_pose.qRotation = HmdQuaternion_Init(1, 0, 0, 0); +} std::string TrackedDevice::get_serial_number() { auto size = GetSerialNumber(this->device_id, nullptr); @@ -10,6 +24,16 @@ std::string TrackedDevice::get_serial_number() { return std::string(&buffer[0]); } +void TrackedDevice::register_device() { + if (!vr::VRServerDriverHost()->TrackedDeviceAdded( + this->get_serial_number().c_str(), + this->device_class, + (vr::ITrackedDeviceServerDriver*)this + )) { + Error("Failed to register device"); + } +} + void TrackedDevice::set_prop(FfiOpenvrProperty prop) { if (this->object_id == vr::k_unTrackedDeviceIndexInvalid) { return; @@ -59,3 +83,17 @@ void TrackedDevice::set_prop(FfiOpenvrProperty prop) { this->object_id, vr::VREvent_PropertyChanged, event_data, 0. ); } + +void TrackedDevice::submit_pose(vr::DriverPose_t pose) { + this->last_pose = pose; + vr::VRServerDriverHost()->TrackedDevicePoseUpdated( + this->object_id, pose, sizeof(vr::DriverPose_t) + ); +} + +vr::EVRInitError TrackedDevice::Activate(vr::TrackedDeviceIndex_t object_id) { + this->object_id = object_id; + this->prop_container = vr::VRProperties()->TrackedDeviceToPropertyContainer(this->object_id); + + return activate() ? vr::VRInitError_None : vr::VRInitError_Driver_Failed; +} diff --git a/alvr/server_openvr/cpp/alvr_server/TrackedDevice.h b/alvr/server_openvr/cpp/alvr_server/TrackedDevice.h index 86adcc23f8..0bfc3b0430 100644 --- a/alvr/server_openvr/cpp/alvr_server/TrackedDevice.h +++ b/alvr/server_openvr/cpp/alvr_server/TrackedDevice.h @@ -4,16 +4,39 @@ #include "openvr_driver.h" #include -class TrackedDevice { +class TrackedDevice : vr::ITrackedDeviceServerDriver { public: - uint64_t device_id; vr::TrackedDeviceIndex_t object_id = vr::k_unTrackedDeviceIndexInvalid; vr::PropertyContainerHandle_t prop_container = vr::k_ulInvalidPropertyContainer; + vr::DriverPose_t last_pose; - TrackedDevice(uint64_t device_id) - : device_id(device_id) { } + void register_device(); + void set_prop(FfiOpenvrProperty prop); +protected: + uint64_t device_id; + vr::ETrackedDeviceClass device_class; + + TrackedDevice(uint64_t device_id, vr::ETrackedDeviceClass device_class); std::string get_serial_number(); + void submit_pose(vr::DriverPose_t pose); + virtual bool activate() = 0; + virtual void* get_component(const char*) = 0; - void set_prop(FfiOpenvrProperty prop); +private: + // ITrackedDeviceServerDriver + vr::EVRInitError Activate(vr::TrackedDeviceIndex_t object_id) final; + void Deactivate() final { + this->device_id = vr::k_unTrackedDeviceIndexInvalid; + this->prop_container = vr::k_ulInvalidPropertyContainer; + } + void EnterStandby() final { } + void* GetComponent(const char* component_name_and_version) final { + return get_component(component_name_and_version); + } + void DebugRequest(const char*, char* buffer, uint32_t buffer_size) final { + if (buffer_size >= 1) + buffer[0] = 0; + } + vr::DriverPose_t GetPose() final { return this->last_pose; } }; diff --git a/alvr/server_openvr/cpp/alvr_server/ViveTrackerProxy.cpp b/alvr/server_openvr/cpp/alvr_server/ViveTrackerProxy.cpp index f51f8aac5f..b05f808e36 100644 --- a/alvr/server_openvr/cpp/alvr_server/ViveTrackerProxy.cpp +++ b/alvr/server_openvr/cpp/alvr_server/ViveTrackerProxy.cpp @@ -10,7 +10,7 @@ ViveTrackerProxy::ViveTrackerProxy(Hmd& owner) vr::DriverPose_t ViveTrackerProxy::GetPose() { assert(m_HMDOwner != nullptr); - return m_HMDOwner->GetPose(); + return m_HMDOwner->last_pose; } vr::EVRInitError ViveTrackerProxy::Activate(vr::TrackedDeviceIndex_t unObjectId) { diff --git a/alvr/server_openvr/cpp/alvr_server/alvr_server.cpp b/alvr/server_openvr/cpp/alvr_server/alvr_server.cpp index ee85748464..eb73b64abc 100644 --- a/alvr/server_openvr/cpp/alvr_server/alvr_server.cpp +++ b/alvr/server_openvr/cpp/alvr_server/alvr_server.cpp @@ -95,12 +95,7 @@ class DriverProvider : public vr::IServerTrackedDeviceProvider { this->hmd = std::make_unique(); this->tracked_devices.insert({ HEAD_ID, (TrackedDevice*)this->hmd.get() }); - if (vr::VRServerDriverHost()->TrackedDeviceAdded( - this->hmd->get_serial_number().c_str(), this->hmd->GetDeviceClass(), this->hmd.get() - )) { - } else { - Warn("Failed to register HMD device"); - } + this->hmd->register_device(); if (Settings::Instance().m_enableControllers) { auto controllerSkeletonLevel = Settings::Instance().m_useSeparateHandTrackers @@ -116,20 +111,8 @@ class DriverProvider : public vr::IServerTrackedDeviceProvider { this->tracked_devices.insert({ HAND_RIGHT_ID, (TrackedDevice*)this->right_controller.get() }); - if (!vr::VRServerDriverHost()->TrackedDeviceAdded( - this->left_controller->get_serial_number().c_str(), - this->left_controller->getControllerDeviceClass(), - this->left_controller.get() - )) { - Warn("Failed to register left controller"); - } - if (!vr::VRServerDriverHost()->TrackedDeviceAdded( - this->right_controller->get_serial_number().c_str(), - this->right_controller->getControllerDeviceClass(), - this->right_controller.get() - )) { - Warn("Failed to register right controller"); - } + this->left_controller->register_device(); + this->right_controller->register_device(); if (Settings::Instance().m_useSeparateHandTrackers) { this->left_hand_tracker = std::make_unique( @@ -144,20 +127,8 @@ class DriverProvider : public vr::IServerTrackedDeviceProvider { this->tracked_devices.insert({ HAND_TRACKER_RIGHT_ID, (TrackedDevice*)this->right_hand_tracker.get() }); - if (!vr::VRServerDriverHost()->TrackedDeviceAdded( - this->left_hand_tracker->get_serial_number().c_str(), - this->left_hand_tracker->getControllerDeviceClass(), - this->left_hand_tracker.get() - )) { - Warn("Failed to register left full skeletal controller"); - } - if (!vr::VRServerDriverHost()->TrackedDeviceAdded( - this->right_hand_tracker->get_serial_number().c_str(), - this->right_hand_tracker->getControllerDeviceClass(), - this->right_hand_tracker.get() - )) { - Warn("Failed to register right full skeletal controller"); - } + this->left_hand_tracker->register_device(); + this->right_hand_tracker->register_device(); } } @@ -417,25 +388,25 @@ void SetTracking( } if (g_driver_provider.left_hand_tracker) { - g_driver_provider.left_hand_tracker->onPoseUpdate( + g_driver_provider.left_hand_tracker->OnPoseUpdate( targetTimestampNs, controllerPoseTimeOffsetS, leftHandData ); } if (g_driver_provider.left_controller) { - g_driver_provider.left_controller->onPoseUpdate( + g_driver_provider.left_controller->OnPoseUpdate( targetTimestampNs, controllerPoseTimeOffsetS, leftHandData ); } if (g_driver_provider.right_hand_tracker) { - g_driver_provider.right_hand_tracker->onPoseUpdate( + g_driver_provider.right_hand_tracker->OnPoseUpdate( targetTimestampNs, controllerPoseTimeOffsetS, rightHandData ); } if (g_driver_provider.right_controller) { - g_driver_provider.right_controller->onPoseUpdate( + g_driver_provider.right_controller->OnPoseUpdate( targetTimestampNs, controllerPoseTimeOffsetS, rightHandData ); }