From 5049312cc8847f5bd8cc9cf32dd42e39ae0bb1f5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 29 Oct 2015 10:34:44 +0100 Subject: support rift 0.2.5, 0.4.2, 0.8.0 Issue: #263 --- ftnoir_tracker_rift_042/ftnoir_rift_042.qrc | 7 + .../ftnoir_rift_clientcontrols_042.ui | 176 +++++++++++++++++++++ .../ftnoir_tracker_rift_042.cpp | 71 +++++++++ ftnoir_tracker_rift_042/ftnoir_tracker_rift_042.h | 60 +++++++ .../ftnoir_tracker_rift_dialog_042.cpp | 26 +++ ftnoir_tracker_rift_042/images/medium.png | Bin 0 -> 5764 bytes ftnoir_tracker_rift_042/images/rift_medium.png | Bin 0 -> 5764 bytes ftnoir_tracker_rift_042/images/rift_small.png | Bin 0 -> 1212 bytes ftnoir_tracker_rift_042/images/rift_tiny.png | Bin 0 -> 624 bytes ftnoir_tracker_rift_042/images/small.png | Bin 0 -> 1212 bytes ftnoir_tracker_rift_042/images/tiny.png | Bin 0 -> 624 bytes 11 files changed, 340 insertions(+) create mode 100644 ftnoir_tracker_rift_042/ftnoir_rift_042.qrc create mode 100644 ftnoir_tracker_rift_042/ftnoir_rift_clientcontrols_042.ui create mode 100644 ftnoir_tracker_rift_042/ftnoir_tracker_rift_042.cpp create mode 100644 ftnoir_tracker_rift_042/ftnoir_tracker_rift_042.h create mode 100644 ftnoir_tracker_rift_042/ftnoir_tracker_rift_dialog_042.cpp create mode 100644 ftnoir_tracker_rift_042/images/medium.png create mode 100644 ftnoir_tracker_rift_042/images/rift_medium.png create mode 100644 ftnoir_tracker_rift_042/images/rift_small.png create mode 100644 ftnoir_tracker_rift_042/images/rift_tiny.png create mode 100644 ftnoir_tracker_rift_042/images/small.png create mode 100644 ftnoir_tracker_rift_042/images/tiny.png (limited to 'ftnoir_tracker_rift_042') diff --git a/ftnoir_tracker_rift_042/ftnoir_rift_042.qrc b/ftnoir_tracker_rift_042/ftnoir_rift_042.qrc new file mode 100644 index 00000000..cd174fc4 --- /dev/null +++ b/ftnoir_tracker_rift_042/ftnoir_rift_042.qrc @@ -0,0 +1,7 @@ + + + images/rift_medium.png + images/rift_small.png + images/rift_tiny.png + + diff --git a/ftnoir_tracker_rift_042/ftnoir_rift_clientcontrols_042.ui b/ftnoir_tracker_rift_042/ftnoir_rift_clientcontrols_042.ui new file mode 100644 index 00000000..20c8f00b --- /dev/null +++ b/ftnoir_tracker_rift_042/ftnoir_rift_clientcontrols_042.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_042/ftnoir_tracker_rift_042.cpp b/ftnoir_tracker_rift_042/ftnoir_tracker_rift_042.cpp new file mode 100644 index 00000000..655a014c --- /dev/null +++ b/ftnoir_tracker_rift_042/ftnoir_tracker_rift_042.cpp @@ -0,0 +1,71 @@ +/* Copyright: "i couldn't care less what anyone does with the 5 lines of code i wrote" - mm0zct */ +#include "ftnoir_tracker_rift_042.h" +#include "opentrack/plugin-api.hpp" +#include "OVR_CAPI.h" +#include "Kernel/OVR_Math.h" +#include + +using namespace OVR; + +Rift_Tracker::Rift_Tracker() : old_yaw(0), hmd(nullptr) +{ +} + +Rift_Tracker::~Rift_Tracker() +{ + ovrHmd_Destroy(hmd); + ovr_Shutdown(); +} + +void Rift_Tracker::start_tracker(QFrame*) +{ + ovr_Initialize(); + hmd = ovrHmd_Create(0); + if (hmd) + { + ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position, ovrTrackingCap_Orientation); + } + else + { + // XXX need change ITracker et al api to allow for failure reporting + // this qmessagebox doesn't give any relevant details either -sh 20141012 + QMessageBox::warning(0,"FaceTrackNoIR Error", "Unable to start Rift tracker",QMessageBox::Ok,QMessageBox::NoButton); + } +} + + +void Rift_Tracker::data(double *data) +{ + if (hmd) + { + ovrHSWDisplayState hsw; + if (ovrHmd_GetHSWDisplayState(hmd, &hsw), hsw.Displayed) + ovrHmd_DismissHSWDisplay(hmd); + ovrTrackingState ss = ovrHmd_GetTrackingState(hmd, 0); + if(ss.StatusFlags & ovrStatus_OrientationTracked) { + auto pose = ss.HeadPose.ThePose; + Quatf quat = pose.Orientation; + float yaw, pitch, roll; + quat.GetEulerAngles(&yaw, &pitch, &roll); + // XXX TODO move to core + 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; + } + constexpr double d2r = 57.295781; + data[Yaw] = yaw * -d2r; + data[Pitch] = pitch * d2r; + data[Roll] = roll * d2r; + data[TX] = pose.Position.x * -1e2; + data[TY] = pose.Position.y * 1e2; + data[TZ] = pose.Position.z * 1e2; + } + } +} + +OPENTRACK_DECLARE_TRACKER(Rift_Tracker, TrackerControls, FTNoIR_TrackerDll) diff --git a/ftnoir_tracker_rift_042/ftnoir_tracker_rift_042.h b/ftnoir_tracker_rift_042/ftnoir_tracker_rift_042.h new file mode 100644 index 00000000..437a2a39 --- /dev/null +++ b/ftnoir_tracker_rift_042/ftnoir_tracker_rift_042.h @@ -0,0 +1,60 @@ +#pragma once +#include "ui_ftnoir_rift_clientcontrols_042.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(); + virtual ~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 runtime 0.4.2 -- HMD"); } + QIcon icon() { return QIcon(":/images/rift_tiny.png"); } +}; + diff --git a/ftnoir_tracker_rift_042/ftnoir_tracker_rift_dialog_042.cpp b/ftnoir_tracker_rift_042/ftnoir_tracker_rift_dialog_042.cpp new file mode 100644 index 00000000..9a8b7549 --- /dev/null +++ b/ftnoir_tracker_rift_042/ftnoir_tracker_rift_dialog_042.cpp @@ -0,0 +1,26 @@ +#include "ftnoir_tracker_rift_042.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_042/images/medium.png b/ftnoir_tracker_rift_042/images/medium.png new file mode 100644 index 00000000..a5ba49e7 Binary files /dev/null and b/ftnoir_tracker_rift_042/images/medium.png differ diff --git a/ftnoir_tracker_rift_042/images/rift_medium.png b/ftnoir_tracker_rift_042/images/rift_medium.png new file mode 100644 index 00000000..a5ba49e7 Binary files /dev/null and b/ftnoir_tracker_rift_042/images/rift_medium.png differ diff --git a/ftnoir_tracker_rift_042/images/rift_small.png b/ftnoir_tracker_rift_042/images/rift_small.png new file mode 100644 index 00000000..3f18080c Binary files /dev/null and b/ftnoir_tracker_rift_042/images/rift_small.png differ diff --git a/ftnoir_tracker_rift_042/images/rift_tiny.png b/ftnoir_tracker_rift_042/images/rift_tiny.png new file mode 100644 index 00000000..76fe0f58 Binary files /dev/null and b/ftnoir_tracker_rift_042/images/rift_tiny.png differ diff --git a/ftnoir_tracker_rift_042/images/small.png b/ftnoir_tracker_rift_042/images/small.png new file mode 100644 index 00000000..3f18080c Binary files /dev/null and b/ftnoir_tracker_rift_042/images/small.png differ diff --git a/ftnoir_tracker_rift_042/images/tiny.png b/ftnoir_tracker_rift_042/images/tiny.png new file mode 100644 index 00000000..76fe0f58 Binary files /dev/null and b/ftnoir_tracker_rift_042/images/tiny.png differ -- cgit v1.2.3