From b0fbe9605b47437d06694a747e607a1b9558c8b3 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 29 Oct 2015 07:25:52 +0100 Subject: rift: finish 0.2.5 support --- CMakeLists.txt | 2 +- ftnoir_tracker_rift/ftnoir_tracker_rift.h | 2 +- ftnoir_tracker_rift_025/ftnoir_rift.qrc | 7 - ftnoir_tracker_rift_025/ftnoir_rift_025.qrc | 7 + .../ftnoir_rift_clientcontrols.ui | 176 --------------------- .../ftnoir_rift_clientcontrols_025.ui | 176 +++++++++++++++++++++ ftnoir_tracker_rift_025/ftnoir_tracker_rift.cpp | 102 ------------ ftnoir_tracker_rift_025/ftnoir_tracker_rift.h | 60 ------- .../ftnoir_tracker_rift_025.cpp | 92 +++++++++++ ftnoir_tracker_rift_025/ftnoir_tracker_rift_025.h | 63 ++++++++ .../ftnoir_tracker_rift_dialog.cpp | 26 --- .../ftnoir_tracker_rift_dialog_025.cpp | 26 +++ 12 files changed, 366 insertions(+), 373 deletions(-) delete mode 100644 ftnoir_tracker_rift_025/ftnoir_rift.qrc create mode 100644 ftnoir_tracker_rift_025/ftnoir_rift_025.qrc delete mode 100644 ftnoir_tracker_rift_025/ftnoir_rift_clientcontrols.ui create mode 100644 ftnoir_tracker_rift_025/ftnoir_rift_clientcontrols_025.ui delete mode 100644 ftnoir_tracker_rift_025/ftnoir_tracker_rift.cpp delete mode 100644 ftnoir_tracker_rift_025/ftnoir_tracker_rift.h create mode 100644 ftnoir_tracker_rift_025/ftnoir_tracker_rift_025.cpp create mode 100644 ftnoir_tracker_rift_025/ftnoir_tracker_rift_025.h delete mode 100644 ftnoir_tracker_rift_025/ftnoir_tracker_rift_dialog.cpp create mode 100644 ftnoir_tracker_rift_025/ftnoir_tracker_rift_dialog_025.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 766d23cb..e447c4b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -438,7 +438,7 @@ if(SDK_RIFT_025) set(c-flags "-fno-strict-aliasing") endif() endif() - opentrack_library(opentrack-tracker-rift-025 ftnoir_tracker_rift-025 LINK ${link-flags} COMPILE ${c-flags}) + opentrack_library(opentrack-tracker-rift-025 ftnoir_tracker_rift_025 LINK ${link-flags} COMPILE ${c-flags}) target_include_directories(opentrack-tracker-rift-025 SYSTEM PUBLIC ${SDK_RIFT_025}/Include ${SDK_RIFT_025}/Src) if(WIN32) if(MSVC) diff --git a/ftnoir_tracker_rift/ftnoir_tracker_rift.h b/ftnoir_tracker_rift/ftnoir_tracker_rift.h index 231648dd..f4458413 100644 --- a/ftnoir_tracker_rift/ftnoir_tracker_rift.h +++ b/ftnoir_tracker_rift/ftnoir_tracker_rift.h @@ -54,7 +54,7 @@ private slots: class FTNoIR_TrackerDll : public Metadata { public: - QString name() { return QString("Oculus Rift -- HMD"); } + QString name() { return QString("Oculus Rift DK2 -- HMD"); } QIcon icon() { return QIcon(":/images/rift_tiny.png"); } }; diff --git a/ftnoir_tracker_rift_025/ftnoir_rift.qrc b/ftnoir_tracker_rift_025/ftnoir_rift.qrc deleted file mode 100644 index cd174fc4..00000000 --- a/ftnoir_tracker_rift_025/ftnoir_rift.qrc +++ /dev/null @@ -1,7 +0,0 @@ - - - images/rift_medium.png - images/rift_small.png - images/rift_tiny.png - - diff --git a/ftnoir_tracker_rift_025/ftnoir_rift_025.qrc b/ftnoir_tracker_rift_025/ftnoir_rift_025.qrc new file mode 100644 index 00000000..cd174fc4 --- /dev/null +++ b/ftnoir_tracker_rift_025/ftnoir_rift_025.qrc @@ -0,0 +1,7 @@ + + + images/rift_medium.png + images/rift_small.png + images/rift_tiny.png + + diff --git a/ftnoir_tracker_rift_025/ftnoir_rift_clientcontrols.ui b/ftnoir_tracker_rift_025/ftnoir_rift_clientcontrols.ui deleted file mode 100644 index 20c8f00b..00000000 --- a/ftnoir_tracker_rift_025/ftnoir_rift_clientcontrols.ui +++ /dev/null @@ -1,176 +0,0 @@ - - - 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/ftnoir_tracker_rift_025/ftnoir_rift_clientcontrols_025.ui b/ftnoir_tracker_rift_025/ftnoir_rift_clientcontrols_025.ui new file mode 100644 index 00000000..20c8f00b --- /dev/null +++ b/ftnoir_tracker_rift_025/ftnoir_rift_clientcontrols_025.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/ftnoir_tracker_rift_025/ftnoir_tracker_rift.cpp b/ftnoir_tracker_rift_025/ftnoir_tracker_rift.cpp deleted file mode 100644 index 549b5ca2..00000000 --- a/ftnoir_tracker_rift_025/ftnoir_tracker_rift.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* Copyright: "i couldn't care less what anyone does with the 5 lines of code i wrote" - mm0zct */ -#include "ftnoir_tracker_rift.h" -#include "facetracknoir/global-settings.h" -#include "OVR.h" -#include - -using namespace OVR; - -Rift_Tracker::Rift_Tracker() -{ - should_quit = false; - pManager = NULL; - pSensor = NULL; - pSFusion = NULL; - old_yaw = 0; -} - -Rift_Tracker::~Rift_Tracker() -{ - if (pSensor) - pSensor->Release(); - if (pSFusion) - delete pSFusion; - if (pManager) - pManager->Release(); - System::Destroy(); -} - -void Rift_Tracker::start_tracker(QFrame*) -{ - System::Init(Log::ConfigureDefaultLog(LogMask_All)); - pManager = DeviceManager::Create(); - if (pManager != NULL) - { - DeviceEnumerator enumerator = pManager->EnumerateDevices(); - if (enumerator.IsAvailable()) - { - pSensor = enumerator.CreateDevice(); - - if (pSensor) - { - pSFusion = new OVR::SensorFusion(); - pSFusion->Reset(); - pSFusion->AttachToSensor(pSensor); - } - else - { - QMessageBox::warning(0,"FaceTrackNoIR Error", "Unable to create Rift sensor",QMessageBox::Ok,QMessageBox::NoButton); - } - - } - else - { - QMessageBox::warning(0,"FaceTrackNoIR Error", "Unable to enumerate Rift tracker",QMessageBox::Ok,QMessageBox::NoButton); - } - } - else - { - QMessageBox::warning(0,"FaceTrackNoIR Error", "Unable to start Rift tracker",QMessageBox::Ok,QMessageBox::NoButton); - } -} - - -void Rift_Tracker::data(double *data) -{ - if (pSFusion != NULL && pSensor != NULL) - { - Quatf hmdOrient = pSFusion->GetOrientation(); - double newHeadPose[6]; - - float yaw = 0.0f; - float pitch = 0.0f; - float roll = 0.0f; - hmdOrient.GetEulerAngles(&yaw, &pitch , &roll); - newHeadPose[Pitch] = pitch; - newHeadPose[Roll] = roll; - newHeadPose[Yaw] = yaw; - if (s.useYawSpring) - { - newHeadPose[Yaw] = old_yaw*s.persistence + (yaw-old_yaw); - if(newHeadPose[Yaw] > s.deadzone) - newHeadPose[Yaw] -= s.constant_drift; - if(newHeadPose[Yaw] < -s.deadzone) - newHeadPose[Yaw] += s.constant_drift; - old_yaw=yaw; - } - if (s.bEnableYaw) - { - data[Yaw] = newHeadPose[Yaw] * 57.295781f; - } - if (s.bEnablePitch) - { - data[Pitch] = newHeadPose[Pitch] * 57.295781f; - } - if (s.bEnableRoll) - { - data[Roll] = newHeadPose[Roll] * 57.295781f; - } - } -} - -OPENTRACK_DECLARE_TRACKER(Rift_Tracker, TrackerControls, FTNoIR_TrackerDll) diff --git a/ftnoir_tracker_rift_025/ftnoir_tracker_rift.h b/ftnoir_tracker_rift_025/ftnoir_tracker_rift.h deleted file mode 100644 index 231648dd..00000000 --- a/ftnoir_tracker_rift_025/ftnoir_tracker_rift.h +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once -#include "ui_ftnoir_rift_clientcontrols.h" -#include -#include -#include -#include "opentrack/plugin-api.hpp" -#include "OVR.h" -#include -#include "opentrack/options.hpp" -using namespace options; - -struct settings : opts { - value useYawSpring; - value constant_drift, persistence, deadzone; - settings() : - opts("Rift"), - 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; - ovrHmd hmd; - 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 -- HMD"); } - QIcon icon() { return QIcon(":/images/rift_tiny.png"); } -}; - diff --git a/ftnoir_tracker_rift_025/ftnoir_tracker_rift_025.cpp b/ftnoir_tracker_rift_025/ftnoir_tracker_rift_025.cpp new file mode 100644 index 00000000..75940697 --- /dev/null +++ b/ftnoir_tracker_rift_025/ftnoir_tracker_rift_025.cpp @@ -0,0 +1,92 @@ +/* Copyright: "i couldn't care less what anyone does with the 5 lines of code i wrote" - mm0zct */ +#include "ftnoir_tracker_rift_025.h" +#include "opentrack/plugin-api.hpp" +#include "OVR.h" +#include + +using namespace OVR; + +Rift_Tracker::Rift_Tracker() +{ + pManager = NULL; + pSensor = NULL; + pSFusion = NULL; + old_yaw = 0; +} + +Rift_Tracker::~Rift_Tracker() +{ + if (pSensor) + pSensor->Release(); + if (pSFusion) + delete pSFusion; + if (pManager) + pManager->Release(); + System::Destroy(); +} + +void Rift_Tracker::start_tracker(QFrame*) +{ + System::Init(Log::ConfigureDefaultLog(LogMask_All)); + pManager = DeviceManager::Create(); + if (pManager != NULL) + { + DeviceEnumerator enumerator = pManager->EnumerateDevices(); + if (enumerator.IsAvailable()) + { + pSensor = enumerator.CreateDevice(); + + if (pSensor) + { + pSFusion = new OVR::SensorFusion(); + pSFusion->Reset(); + pSFusion->AttachToSensor(pSensor); + } + else + { + QMessageBox::warning(0,"FaceTrackNoIR Error", "Unable to create Rift sensor",QMessageBox::Ok,QMessageBox::NoButton); + } + + } + else + { + QMessageBox::warning(0,"FaceTrackNoIR Error", "Unable to enumerate Rift tracker",QMessageBox::Ok,QMessageBox::NoButton); + } + } + else + { + QMessageBox::warning(0,"FaceTrackNoIR Error", "Unable to start Rift tracker",QMessageBox::Ok,QMessageBox::NoButton); + } +} + + +void Rift_Tracker::data(double *data) +{ + if (pSFusion != NULL && pSensor != NULL) + { + Quatf hmdOrient = pSFusion->GetOrientation(); + double newHeadPose[6]; + + float yaw = 0.0f; + float pitch = 0.0f; + float roll = 0.0f; + hmdOrient.GetEulerAngles(&yaw, &pitch , &roll); + newHeadPose[Pitch] = pitch; + newHeadPose[Roll] = roll; + newHeadPose[Yaw] = yaw; + if (s.useYawSpring) + { + newHeadPose[Yaw] = old_yaw*s.persistence + (yaw-old_yaw); + if(newHeadPose[Yaw] > s.deadzone) + newHeadPose[Yaw] -= s.constant_drift; + if(newHeadPose[Yaw] < -s.deadzone) + newHeadPose[Yaw] += s.constant_drift; + old_yaw=yaw; + } + data[Yaw] = newHeadPose[Yaw] * 57.295781f; + data[Pitch] = newHeadPose[Pitch] * 57.295781f; + data[Roll] = newHeadPose[Roll] * 57.295781f; + } +} + +OPENTRACK_DECLARE_TRACKER(Rift_Tracker, TrackerControls, FTNoIR_TrackerDll) diff --git a/ftnoir_tracker_rift_025/ftnoir_tracker_rift_025.h b/ftnoir_tracker_rift_025/ftnoir_tracker_rift_025.h new file mode 100644 index 00000000..ca3068bc --- /dev/null +++ b/ftnoir_tracker_rift_025/ftnoir_tracker_rift_025.h @@ -0,0 +1,63 @@ +#pragma once +#include "ui_ftnoir_rift_clientcontrols_025.h" +#include +#include +#include +#include "opentrack/plugin-api.hpp" +#include "OVR.h" +#include +#include "opentrack/options.hpp" +using namespace options; + +struct settings : opts { + value useYawSpring; + value constant_drift, persistence, deadzone; + settings() : + opts("Rift-025"), + 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; + settings s; + static bool isInitialised; + OVR::DeviceManager* pManager; + OVR::SensorDevice* pSensor; + OVR::SensorFusion* pSFusion; +}; + +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 DK1 -- HMD"); } + QIcon icon() { return QIcon(":/images/rift_tiny.png"); } +}; + diff --git a/ftnoir_tracker_rift_025/ftnoir_tracker_rift_dialog.cpp b/ftnoir_tracker_rift_025/ftnoir_tracker_rift_dialog.cpp deleted file mode 100644 index 6c8e9cd7..00000000 --- a/ftnoir_tracker_rift_025/ftnoir_tracker_rift_dialog.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "ftnoir_tracker_rift.h" -#include "opentrack/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(); - this->close(); -} - -void TrackerControls::doCancel() { - s.b->reload(); - close(); -} - diff --git a/ftnoir_tracker_rift_025/ftnoir_tracker_rift_dialog_025.cpp b/ftnoir_tracker_rift_025/ftnoir_tracker_rift_dialog_025.cpp new file mode 100644 index 00000000..8100e362 --- /dev/null +++ b/ftnoir_tracker_rift_025/ftnoir_tracker_rift_dialog_025.cpp @@ -0,0 +1,26 @@ +#include "ftnoir_tracker_rift_025.h" +#include "opentrack/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(); + this->close(); +} + +void TrackerControls::doCancel() { + s.b->reload(); + close(); +} + -- cgit v1.2.3