diff options
Diffstat (limited to 'tracker-rift-140')
-rw-r--r-- | tracker-rift-140/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tracker-rift-140/dialog.cpp | 25 | ||||
-rw-r--r-- | tracker-rift-140/dialog.ui | 176 | ||||
-rw-r--r-- | tracker-rift-140/images/medium.png | bin | 0 -> 5764 bytes | |||
-rw-r--r-- | tracker-rift-140/images/rift_medium.png | bin | 0 -> 5764 bytes | |||
-rw-r--r-- | tracker-rift-140/images/rift_small.png | bin | 0 -> 1212 bytes | |||
-rw-r--r-- | tracker-rift-140/images/rift_tiny.png | bin | 0 -> 624 bytes | |||
-rw-r--r-- | tracker-rift-140/images/small.png | bin | 0 -> 1212 bytes | |||
-rw-r--r-- | tracker-rift-140/images/tiny.png | bin | 0 -> 624 bytes | |||
-rw-r--r-- | tracker-rift-140/impl.cpp | 97 | ||||
-rw-r--r-- | tracker-rift-140/rift-140.hpp | 60 | ||||
-rw-r--r-- | tracker-rift-140/rift-140.qrc | 7 |
12 files changed, 368 insertions, 0 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>UIRiftControls</class> + <widget class="QWidget" name="UIRiftControls"> + <property name="windowModality"> + <enum>Qt::NonModal</enum> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>218</width> + <height>200</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="windowTitle"> + <string>Oculus Rift tracker settings FaceTrackNoIR</string> + </property> + <property name="windowIcon"> + <iconset> + <normaloff>images/FaceTrackNoIR.png</normaloff>images/FaceTrackNoIR.png</iconset> + </property> + <property name="layoutDirection"> + <enum>Qt::LeftToRight</enum> + </property> + <property name="autoFillBackground"> + <bool>false</bool> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="0"> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Yaw spring</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QCheckBox" name="yawSpring"> + <property name="text"> + <string>Enable</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Persistence</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QDoubleSpinBox" name="persistence"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>23</height> + </size> + </property> + <property name="decimals"> + <number>5</number> + </property> + <property name="minimum"> + <double>0.900000000000000</double> + </property> + <property name="maximum"> + <double>1.000000000000000</double> + </property> + <property name="singleStep"> + <double>0.001000000000000</double> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Constant drift</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QDoubleSpinBox" name="constantDrift"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>23</height> + </size> + </property> + <property name="decimals"> + <number>5</number> + </property> + <property name="minimum"> + <double>0.000100000000000</double> + </property> + <property name="maximum"> + <double>0.100000000000000</double> + </property> + <property name="singleStep"> + <double>0.001000000000000</double> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Deadzone</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QDoubleSpinBox" name="deadzone"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>23</height> + </size> + </property> + <property name="decimals"> + <number>5</number> + </property> + <property name="maximum"> + <double>0.100000000000000</double> + </property> + <property name="singleStep"> + <double>0.010000000000000</double> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="1" column="0"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> + <slots> + <slot>startEngineClicked()</slot> + <slot>stopEngineClicked()</slot> + <slot>cameraSettingsClicked()</slot> + </slots> +</ui> diff --git a/tracker-rift-140/images/medium.png b/tracker-rift-140/images/medium.png Binary files differnew file mode 100644 index 00000000..a5ba49e7 --- /dev/null +++ b/tracker-rift-140/images/medium.png diff --git a/tracker-rift-140/images/rift_medium.png b/tracker-rift-140/images/rift_medium.png Binary files differnew file mode 100644 index 00000000..a5ba49e7 --- /dev/null +++ b/tracker-rift-140/images/rift_medium.png diff --git a/tracker-rift-140/images/rift_small.png b/tracker-rift-140/images/rift_small.png Binary files differnew file mode 100644 index 00000000..3f18080c --- /dev/null +++ b/tracker-rift-140/images/rift_small.png diff --git a/tracker-rift-140/images/rift_tiny.png b/tracker-rift-140/images/rift_tiny.png Binary files differnew file mode 100644 index 00000000..76fe0f58 --- /dev/null +++ b/tracker-rift-140/images/rift_tiny.png diff --git a/tracker-rift-140/images/small.png b/tracker-rift-140/images/small.png Binary files differnew file mode 100644 index 00000000..3f18080c --- /dev/null +++ b/tracker-rift-140/images/small.png diff --git a/tracker-rift-140/images/tiny.png b/tracker-rift-140/images/tiny.png Binary files differnew file mode 100644 index 00000000..76fe0f58 --- /dev/null +++ b/tracker-rift-140/images/tiny.png 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 <Extras/OVR_Math.h> + +#include <QString> + +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 <OVR_CAPI.h> +#include <cmath> +#include <QMessageBox> +#include <QWaitCondition> +using namespace options; + +struct settings : opts { + value<bool> useYawSpring; + value<double> 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 @@ +<RCC> + <qresource prefix="/"> + <file>images/rift_medium.png</file> + <file>images/rift_small.png</file> + <file>images/rift_tiny.png</file> + </qresource> +</RCC> |