diff options
Diffstat (limited to 'tracker-steamvr')
-rw-r--r-- | tracker-steamvr/CMakeLists.txt | 26 | ||||
-rw-r--r-- | tracker-steamvr/steamvr.cpp | 41 | ||||
-rw-r--r-- | tracker-steamvr/steamvr.hpp | 22 |
3 files changed, 45 insertions, 44 deletions
diff --git a/tracker-steamvr/CMakeLists.txt b/tracker-steamvr/CMakeLists.txt index 512a49ff..dc487cba 100644 --- a/tracker-steamvr/CMakeLists.txt +++ b/tracker-steamvr/CMakeLists.txt @@ -2,10 +2,13 @@ set(steamvr-dir "") set(steamvr-dll "") set(steamvr-lib "") -if(LINUX AND opentrack-64bit) - set(steamvr-dir "linux64") +if(LINUX) + if (opentrack-64bit) + set(steamvr-dir "linux64") + else() + set(steamvr-dir "linux32") + endif() set(steamvr-dll "libopenvr_api.so") - set(steamvr-lib "${steamvr-dll}") endif() if(WIN32) @@ -18,19 +21,26 @@ if(WIN32) set(steamvr-lib "openvr_api.lib") endif() -if(APPLE AND NOT opentrack-64bit) - set(steamvr-dir "osx32") +if(APPLE) + # expect user compiled it as a non-framework version + if(opentrack-64bit) + set(steamvr-dir "osx64") + else() + set(steamvr-dir "osx32") + endif() set(steamvr-dll "libopenvr_api.dylib") - set(steamvr-lib "${steamvr-dll}") endif() -if(steamvr-dll) +if(steamvr-dll AND opentrack-intel) + if(steamvr-lib STREQUAL "") + set(steamvr-lib "${steamvr-dll}") + endif() SET(SDK_VALVE_STEAMVR "" CACHE PATH "Valve's SteamVR") if(SDK_VALVE_STEAMVR) otr_module(tracker-steamvr) install(FILES "${SDK_VALVE_STEAMVR}/bin/${steamvr-dir}/${steamvr-dll}" DESTINATION "${opentrack-hier-pfx}") - target_include_directories(opentrack-tracker-steamvr SYSTEM PUBLIC "${SDK_VALVE_STEAMVR}/headers") + target_include_directories(opentrack-tracker-steamvr SYSTEM PRIVATE "${SDK_VALVE_STEAMVR}/headers") target_link_libraries(opentrack-tracker-steamvr "${SDK_VALVE_STEAMVR}/lib/${steamvr-dir}/${steamvr-lib}") endif() endif() diff --git a/tracker-steamvr/steamvr.cpp b/tracker-steamvr/steamvr.cpp index 04ae691e..9a845d55 100644 --- a/tracker-steamvr/steamvr.cpp +++ b/tracker-steamvr/steamvr.cpp @@ -20,10 +20,8 @@ #include "api/plugin-api.hpp" -#include <cstdlib> #include <cmath> -#include <type_traits> -#include <algorithm> +#include <cstdlib> #include <QMessageBox> #include <QDebug> @@ -59,13 +57,13 @@ void device_list::fill_device_specs(QList<device_spec>& list) { if (v->GetTrackedDeviceClass(k) == vr::ETrackedDeviceClass::TrackedDeviceClass_Invalid) { - qDebug() << "no device with index"; + qDebug() << "steamvr: no device with index"; continue; } if (!device_states[k].bDeviceIsConnected) { - qDebug() << "device not connected but proceeding"; + qDebug() << "steamvr: device not connected but proceeding"; continue; } @@ -170,14 +168,19 @@ tt device_list::vr_init_() QString device_list::error_string(vr_error_t err) { - const char* str(vr::VR_GetVRInitErrorAsSymbol(err)); - return QString(str ? str : "No description"); -} + const char* str = vr::VR_GetVRInitErrorAsSymbol(err); + const char* desc = vr::VR_GetVRInitErrorAsEnglishDescription(err); -steamvr::steamvr() : device_index(-1) -{ + if (!desc) + desc = "No description"; + + if (str) + return QStringLiteral("%1: %2").arg(str, desc); + else + return { "Unknown error" }; } +steamvr::steamvr() = default; steamvr::~steamvr() = default; module_status steamvr::start_tracker(QFrame*) @@ -200,18 +203,16 @@ module_status steamvr::start_tracker(QFrame*) if (sz == 0) err = tr("No HMD connected"); - device_index = -1; - for (const device_spec& spec : specs) { if (serial == "" || serial == spec.to_string()) { - device_index = int(spec.k); + device_index = spec.k; break; } } - if (device_index == -1 && err.isEmpty()) + if (device_index == UINT_MAX && err.isEmpty()) err = tr("Can't find device with that serial"); if (err.isEmpty()) @@ -223,7 +224,7 @@ module_status steamvr::start_tracker(QFrame*) void steamvr::data(double* data) { - if (device_index != -1) + if (device_index != UINT_MAX) { auto [ok, pose] = device_list::get_pose(device_index); if (ok) @@ -269,15 +270,11 @@ bool steamvr::center() void steamvr::matrix_to_euler(double& yaw, double& pitch, double& roll, const vr::HmdMatrix34_t& result) { - using std::atan2; - using std::sqrt; - using std::asin; - using d = double; - yaw = atan2(d(result.m[2][0]), d(result.m[0][0])); - pitch = atan2(-d(result.m[1][2]), d(result.m[1][1])); - roll = asin(d(result.m[1][0])); + yaw = std::atan2(d(result.m[2][0]), d(result.m[0][0])); + pitch = std::atan2(-d(result.m[1][2]), d(result.m[1][1])); + roll = std::asin(d(result.m[1][0])); } steamvr_dialog::steamvr_dialog() diff --git a/tracker-steamvr/steamvr.hpp b/tracker-steamvr/steamvr.hpp index 8c76ad17..61da2e05 100644 --- a/tracker-steamvr/steamvr.hpp +++ b/tracker-steamvr/steamvr.hpp @@ -1,25 +1,19 @@ #pragma once -#include "api/plugin-api.hpp" + #include "ui_dialog.h" +#include "api/plugin-api.hpp" #include "options/options.hpp" -#include "compat/euler.hpp" - -#include <openvr.h> - -#include <cmath> -#include <memory> #include <tuple> +#include <climits> #include <QString> #include <QMutex> -#include <QMutexLocker> #include <QList> -using namespace options; +#include <openvr.h> -using rmat = euler::rmat; -using euler_t = euler::euler_t; +using namespace options; using vr_error_t = vr::EVRInitError; using vr_t = vr::IVRSystem*; @@ -54,9 +48,9 @@ struct device_list final void refresh_device_list(); const QList<device_spec>& devices() const { return device_specs; } - static cc_noinline maybe_pose get_pose(int k); + static never_inline maybe_pose get_pose(int k); static QString error_string(vr_error_t error); - static constexpr inline unsigned max_devices = vr::k_unMaxTrackedDeviceCount; + static constexpr unsigned max_devices = vr::k_unMaxTrackedDeviceCount; template<typename F> friend auto with_vr_lock(F&& fun) -> decltype(fun(vr_t(), vr_error_t())); @@ -76,7 +70,7 @@ class steamvr : public QObject, public ITracker static void matrix_to_euler(double& yaw, double& pitch, double& roll, const vr::HmdMatrix34_t& result); settings s; - int device_index; + unsigned device_index{UINT_MAX}; public: steamvr(); |