From 47c4dbe1fef2af9eaa7d38845e83544320bd0631 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 2 Nov 2016 11:55:41 +0100 Subject: tracker/rift-140: add --- tracker-rift-140/CMakeLists.txt | 3 + tracker-rift-140/dialog.cpp | 25 +++++ tracker-rift-140/dialog.ui | 176 ++++++++++++++++++++++++++++++++ tracker-rift-140/images/medium.png | Bin 0 -> 5764 bytes tracker-rift-140/images/rift_medium.png | Bin 0 -> 5764 bytes tracker-rift-140/images/rift_small.png | Bin 0 -> 1212 bytes tracker-rift-140/images/rift_tiny.png | Bin 0 -> 624 bytes tracker-rift-140/images/small.png | Bin 0 -> 1212 bytes tracker-rift-140/images/tiny.png | Bin 0 -> 624 bytes tracker-rift-140/impl.cpp | 97 ++++++++++++++++++ tracker-rift-140/rift-140.hpp | 60 +++++++++++ tracker-rift-140/rift-140.qrc | 7 ++ 12 files changed, 368 insertions(+) create mode 100644 tracker-rift-140/CMakeLists.txt create mode 100644 tracker-rift-140/dialog.cpp create mode 100644 tracker-rift-140/dialog.ui create mode 100644 tracker-rift-140/images/medium.png create mode 100644 tracker-rift-140/images/rift_medium.png create mode 100644 tracker-rift-140/images/rift_small.png create mode 100644 tracker-rift-140/images/rift_tiny.png create mode 100644 tracker-rift-140/images/small.png create mode 100644 tracker-rift-140/images/tiny.png create mode 100644 tracker-rift-140/impl.cpp create mode 100644 tracker-rift-140/rift-140.hpp create mode 100644 tracker-rift-140/rift-140.qrc diff --git a/tracker-rift-140/CMakeLists.txt b/tracker-rift-140/CMakeLists.txt new file mode 100644 index 00000000..55a6f9b4 --- /dev/null +++ b/tracker-rift-140/CMakeLists.txt @@ -0,0 +1,3 @@ +include(opentrack-rift) +opentrack_rift_boilerplate(opentrack-tracker-rift-140 SDK_RIFT_140) +SET(SDK_RIFT_140 "" CACHE PATH "libOVR 1.4.0 path for Oculus Rift") diff --git a/tracker-rift-140/dialog.cpp b/tracker-rift-140/dialog.cpp new file mode 100644 index 00000000..a6bf8126 --- /dev/null +++ b/tracker-rift-140/dialog.cpp @@ -0,0 +1,25 @@ +#include "rift-140.hpp" +#include "api/plugin-api.hpp" + +TrackerControls::TrackerControls() +{ + ui.setupUi( this ); + + connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); + connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); + + tie_setting(s.constant_drift, ui.constantDrift); + tie_setting(s.deadzone, ui.deadzone); + tie_setting(s.persistence, ui.persistence); + tie_setting(s.useYawSpring, ui.yawSpring); +} + +void TrackerControls::doOK() { + s.b->save(); + close(); +} + +void TrackerControls::doCancel() { + close(); +} + diff --git a/tracker-rift-140/dialog.ui b/tracker-rift-140/dialog.ui new file mode 100644 index 00000000..20c8f00b --- /dev/null +++ b/tracker-rift-140/dialog.ui @@ -0,0 +1,176 @@ + + + UIRiftControls + + + Qt::NonModal + + + + 0 + 0 + 218 + 200 + + + + + 0 + 0 + + + + Oculus Rift tracker settings FaceTrackNoIR + + + + images/FaceTrackNoIR.pngimages/FaceTrackNoIR.png + + + Qt::LeftToRight + + + false + + + + + + Yaw spring + + + + + + Enable + + + + + + + Persistence + + + + + + + + 0 + 0 + + + + + 0 + 23 + + + + 5 + + + 0.900000000000000 + + + 1.000000000000000 + + + 0.001000000000000 + + + + + + + Constant drift + + + + + + + + 0 + 0 + + + + + 0 + 23 + + + + 5 + + + 0.000100000000000 + + + 0.100000000000000 + + + 0.001000000000000 + + + + + + + Deadzone + + + + + + + + 0 + 0 + + + + + 0 + 23 + + + + 5 + + + 0.100000000000000 + + + 0.010000000000000 + + + + + + + + + + + 0 + 0 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + startEngineClicked() + stopEngineClicked() + cameraSettingsClicked() + + diff --git a/tracker-rift-140/images/medium.png b/tracker-rift-140/images/medium.png new file mode 100644 index 00000000..a5ba49e7 Binary files /dev/null and b/tracker-rift-140/images/medium.png differ diff --git a/tracker-rift-140/images/rift_medium.png b/tracker-rift-140/images/rift_medium.png new file mode 100644 index 00000000..a5ba49e7 Binary files /dev/null and b/tracker-rift-140/images/rift_medium.png differ diff --git a/tracker-rift-140/images/rift_small.png b/tracker-rift-140/images/rift_small.png new file mode 100644 index 00000000..3f18080c Binary files /dev/null and b/tracker-rift-140/images/rift_small.png differ diff --git a/tracker-rift-140/images/rift_tiny.png b/tracker-rift-140/images/rift_tiny.png new file mode 100644 index 00000000..76fe0f58 Binary files /dev/null and b/tracker-rift-140/images/rift_tiny.png differ diff --git a/tracker-rift-140/images/small.png b/tracker-rift-140/images/small.png new file mode 100644 index 00000000..3f18080c Binary files /dev/null and b/tracker-rift-140/images/small.png differ diff --git a/tracker-rift-140/images/tiny.png b/tracker-rift-140/images/tiny.png new file mode 100644 index 00000000..76fe0f58 Binary files /dev/null and b/tracker-rift-140/images/tiny.png differ diff --git a/tracker-rift-140/impl.cpp b/tracker-rift-140/impl.cpp new file mode 100644 index 00000000..964858ac --- /dev/null +++ b/tracker-rift-140/impl.cpp @@ -0,0 +1,97 @@ +/* Copyright: "i couldn't care less what anyone does with the 5 lines of code i wrote" - mm0zct */ +#include "rift-140.hpp" +#include "api/plugin-api.hpp" +#include "compat/util.hpp" +#include + +#include + +using namespace OVR; + +Rift_Tracker::Rift_Tracker() : old_yaw(0), hmd(nullptr) +{ +} + +Rift_Tracker::~Rift_Tracker() +{ + if (hmd) + { + ovr_Destroy(hmd); + ovr_Shutdown(); + } +} + +void Rift_Tracker::start_tracker(QFrame*) +{ + if (OVR_FAILURE(ovr_Initialize(nullptr))) + goto error; + + if(OVR_FAILURE(ovr_Create(&hmd, &luid))) + goto error; + + return; +error: + hmd = nullptr; + + ovrErrorInfo err; + ovr_GetLastErrorInfo(&err); + + QString strerror(err.ErrorString); + if (strerror.size() == 0) + strerror = QStringLiteral("Unknown reason #%1").arg(err.Result); + + ovr_Shutdown(); + + QMessageBox::warning(nullptr, + "Error", + QStringLiteral("Unable to start Rift tracker: %1").arg(strerror), + QMessageBox::Ok, + QMessageBox::NoButton); +} + +void Rift_Tracker::data(double *data) +{ + if (hmd) + { + ovrTrackingState ss = ovr_GetTrackingState(hmd, 0, false); + if (ss.StatusFlags & ovrStatus_OrientationTracked) + { + static constexpr float c_mult = 8; + static constexpr float c_div = 1/c_mult; + + Vector3f axis; + float angle; + + const Posef pose(ss.HeadPose.ThePose); + pose.Rotation.GetAxisAngle(&axis, &angle); + angle *= c_div; + + float yaw, pitch, roll; + Quatf(axis, angle).GetYawPitchRoll(&yaw, &pitch, &roll); + + yaw *= c_mult; + pitch *= c_mult; + roll *= c_mult; + + double yaw_ = double(yaw); + if (s.useYawSpring) + { + yaw_ = old_yaw*s.persistence + (yaw_-old_yaw); + if(yaw_ > s.deadzone) + yaw_ -= s.constant_drift; + if(yaw_ < -s.deadzone) + yaw_ += s.constant_drift; + old_yaw = yaw_; + } + static constexpr double d2r = 180 / M_PI; + data[Yaw] = yaw_ * -d2r; + data[Pitch] = double(pitch) * d2r; + data[Roll] = double(roll) * d2r; + data[TX] = double(pose.Translation.x) * -1e2; + data[TY] = double(pose.Translation.y) * 1e2; + data[TZ] = double(pose.Translation.z) * 1e2; + } + } +} + +OPENTRACK_DECLARE_TRACKER(Rift_Tracker, TrackerControls, FTNoIR_TrackerDll) diff --git a/tracker-rift-140/rift-140.hpp b/tracker-rift-140/rift-140.hpp new file mode 100644 index 00000000..912f8587 --- /dev/null +++ b/tracker-rift-140/rift-140.hpp @@ -0,0 +1,60 @@ +#pragma once +#include "ui_dialog.h" +#include "api/plugin-api.hpp" +#include "options/options.hpp" +#include +#include +#include +#include +using namespace options; + +struct settings : opts { + value useYawSpring; + value constant_drift, persistence, deadzone; + settings() : + opts("Rift-140"), + useYawSpring(b, "yaw-spring", false), + constant_drift(b, "constant-drift", 0.000005), + persistence(b, "persistence", 0.99999), + deadzone(b, "deadzone", 0.02) + {} +}; + +class Rift_Tracker : public ITracker +{ +public: + Rift_Tracker(); + ~Rift_Tracker() override; + void start_tracker(QFrame *) override; + void data(double *data) override; +private: + double old_yaw; + ovrSession hmd; + ovrGraphicsLuid luid; + settings s; +}; + +class TrackerControls: public ITrackerDialog +{ + Q_OBJECT +public: + TrackerControls(); + + void register_tracker(ITracker *) {} + void unregister_tracker() {} + +private: + Ui::UIRiftControls ui; + settings s; +private slots: + void doOK(); + void doCancel(); +}; + +class FTNoIR_TrackerDll : public Metadata +{ +public: + QString name() { return QString("Oculus Rift runtime 1.4.0 -- HMD"); } + QIcon icon() { return QIcon(":/images/rift_tiny.png"); } +}; + diff --git a/tracker-rift-140/rift-140.qrc b/tracker-rift-140/rift-140.qrc new file mode 100644 index 00000000..cd174fc4 --- /dev/null +++ b/tracker-rift-140/rift-140.qrc @@ -0,0 +1,7 @@ + + + images/rift_medium.png + images/rift_small.png + images/rift_tiny.png + + -- cgit v1.2.3