From 1e67a2732667f6121b6078dd2c2af5a1cdf56311 Mon Sep 17 00:00:00 2001 From: Korcan Hussein Date: Tue, 25 Jun 2024 17:59:21 +0100 Subject: [PATCH] cmake: change project c++-lang to c++20 Part-of: --- CMakeLists.txt | 2 +- src/xrt/drivers/steamvr_lh/device.hpp | 10 +++- .../steamvr_drv/ovrd_driver.cpp | 46 +++++++++++-------- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b81e580f..683904e00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) # We use C++17 -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) # So that clangd/Intellisense/Sourcetrail know how to parse our code. diff --git a/src/xrt/drivers/steamvr_lh/device.hpp b/src/xrt/drivers/steamvr_lh/device.hpp index 11a39b9d9..3b8570b64 100644 --- a/src/xrt/drivers/steamvr_lh/device.hpp +++ b/src/xrt/drivers/steamvr_lh/device.hpp @@ -25,11 +25,19 @@ struct InputClass; struct DeviceBuilder { - std::shared_ptr ctx; + using ContextPtr = std::shared_ptr; + ContextPtr ctx; vr::ITrackedDeviceServerDriver *driver; const char *serial; const std::string &steam_install; + DeviceBuilder(const ContextPtr &p_ctx, + vr::ITrackedDeviceServerDriver *p_driver, + const char *p_serial, + const std::string &p_stream_install) + : ctx{p_ctx}, driver{p_driver}, serial{p_serial}, steam_install{p_stream_install} + {} + // no copies! DeviceBuilder(const DeviceBuilder &) = delete; DeviceBuilder diff --git a/src/xrt/state_trackers/steamvr_drv/ovrd_driver.cpp b/src/xrt/state_trackers/steamvr_drv/ovrd_driver.cpp index 71e2a9436..451135c9d 100644 --- a/src/xrt/state_trackers/steamvr_drv/ovrd_driver.cpp +++ b/src/xrt/state_trackers/steamvr_drv/ovrd_driver.cpp @@ -1249,15 +1249,15 @@ CDeviceDriver_Monado::DebugRequest(const char *pchRequest, char *pchResponseBuff //! @todo } -static inline vr::HmdQuaternion_t +static constexpr inline vr::HmdQuaternion_t HmdQuaternion_Init(double w, double x, double y, double z) { - vr::HmdQuaternion_t quat; - quat.w = w; - quat.x = x; - quat.y = y; - quat.z = z; - return quat; + return vr::HmdQuaternion_t{ + .w = w, + .x = x, + .y = y, + .z = z, + }; } vr::DriverPose_t @@ -1275,23 +1275,31 @@ CDeviceDriver_Monado::GetPose() m_relation_chain_push_pose_if_not_identity(&chain, offset); m_relation_chain_resolve(&chain, &rel); - vr::DriverPose_t t = {}; + vr::DriverPose_t t = { + // monado predicts pose "now", see xrt_device_get_tracked_pose + .poseTimeOffset = 0, + .qWorldFromDriverRotation = HmdQuaternion_Init(1, 0, 0, 0), + .vecWorldFromDriverTranslation = {0, 0, 0}, + .qDriverFromHeadRotation = HmdQuaternion_Init(1, 0, 0, 0), + .vecDriverFromHeadTranslation = {0, 0, 0}, - // monado predicts pose "now", see xrt_device_get_tracked_pose - t.poseTimeOffset = 0; + .vecPosition = {0, 0, 0}, + .vecVelocity = {0, 0, 0}, + .vecAcceleration = {0, 0, 0}, - //! @todo: Monado head model? - t.shouldApplyHeadModel = !m_xdev->position_tracking_supported; - t.willDriftInYaw = !m_xdev->position_tracking_supported; + .qRotation = HmdQuaternion_Init(1, 0, 0, 0), - t.qWorldFromDriverRotation = HmdQuaternion_Init(1, 0, 0, 0); - t.qDriverFromHeadRotation = HmdQuaternion_Init(1, 0, 0, 0); - - t.poseIsValid = rel.relation_flags & XRT_SPACE_RELATION_ORIENTATION_VALID_BIT; - t.result = vr::TrackingResult_Running_OK; - t.deviceIsConnected = true; + .vecAngularVelocity = {0, 0, 0}, + .vecAngularAcceleration = {0, 0, 0}, + .result = vr::TrackingResult_Running_OK, + .poseIsValid = (rel.relation_flags & XRT_SPACE_RELATION_ORIENTATION_VALID_BIT) != 0, + .willDriftInYaw = !m_xdev->position_tracking_supported, + //! @todo: Monado head model? + .shouldApplyHeadModel = !m_xdev->position_tracking_supported, + .deviceIsConnected = true, + }; apply_pose(&rel, &t); #ifdef DUMP_POSE