diff options
Diffstat (limited to 'ftnoir_tracker_rift')
-rw-r--r-- | ftnoir_tracker_rift/ftnoir_rift_clientcontrols.ui | 126 | ||||
-rw-r--r-- | ftnoir_tracker_rift/ftnoir_tracker_rift.cpp | 110 | ||||
-rw-r--r-- | ftnoir_tracker_rift/ftnoir_tracker_rift.h | 57 | ||||
-rw-r--r-- | ftnoir_tracker_rift/ftnoir_tracker_rift_dialog.cpp | 13 | ||||
-rw-r--r-- | ftnoir_tracker_rift/ftnoir_tracker_rift_dll.cpp | 4 |
5 files changed, 77 insertions, 233 deletions
diff --git a/ftnoir_tracker_rift/ftnoir_rift_clientcontrols.ui b/ftnoir_tracker_rift/ftnoir_rift_clientcontrols.ui index a9168239..20c8f00b 100644 --- a/ftnoir_tracker_rift/ftnoir_rift_clientcontrols.ui +++ b/ftnoir_tracker_rift/ftnoir_rift_clientcontrols.ui @@ -9,8 +9,8 @@ <rect> <x>0</x> <y>0</y> - <width>209</width> - <height>288</height> + <width>218</width> + <height>200</height> </rect> </property> <property name="sizePolicy"> @@ -34,126 +34,6 @@ </property> <layout class="QGridLayout" name="gridLayout_2"> <item row="0" column="0"> - <widget class="QGroupBox" name="groupBox_3"> - <property name="title"> - <string>Enable Axis</string> - </property> - <property name="flat"> - <bool>false</bool> - </property> - <layout class="QFormLayout" name="formLayout_2"> - <item row="0" column="0"> - <widget class="QLabel" name="label_6"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Pitch:</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QCheckBox" name="chkEnablePitch"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="maximumSize"> - <size> - <width>20</width> - <height>16777215</height> - </size> - </property> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="styleSheet"> - <string notr="true"/> - </property> - <property name="text"> - <string/> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_9"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Yaw:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QCheckBox" name="chkEnableYaw"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="maximumSize"> - <size> - <width>20</width> - <height>16777215</height> - </size> - </property> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="text"> - <string/> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_11"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Roll:</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QCheckBox" name="chkEnableRoll"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="maximumSize"> - <size> - <width>20</width> - <height>16777215</height> - </size> - </property> - <property name="layoutDirection"> - <enum>Qt::LeftToRight</enum> - </property> - <property name="text"> - <string/> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="1" column="0"> <widget class="QGroupBox" name="groupBox"> <property name="title"> <string>Yaw spring</string> @@ -271,7 +151,7 @@ </layout> </widget> </item> - <item row="2" column="0"> + <item row="1" column="0"> <widget class="QDialogButtonBox" name="buttonBox"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> diff --git a/ftnoir_tracker_rift/ftnoir_tracker_rift.cpp b/ftnoir_tracker_rift/ftnoir_tracker_rift.cpp index b548db71..68a520ad 100644 --- a/ftnoir_tracker_rift/ftnoir_tracker_rift.cpp +++ b/ftnoir_tracker_rift/ftnoir_tracker_rift.cpp @@ -1,92 +1,74 @@ /* 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 "facetracknoir/plugin-support.h" +#include "OVR_CAPI.h" +#include "Kernel/OVR_Math.h" #include <cstdio> using namespace OVR; -Rift_Tracker::Rift_Tracker() +Rift_Tracker::Rift_Tracker() : old_yaw(0), hmd(nullptr) { - 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(); + ovrHmd_Destroy(hmd); + ovr_Shutdown(); } void Rift_Tracker::StartTracker(QFrame*) { - System::Init(Log::ConfigureDefaultLog(LogMask_All)); - pManager = DeviceManager::Create(); - if (pManager != NULL) + ovr_Initialize(); + hmd = ovrHmd_Create(0); + if (hmd) { - DeviceEnumerator<OVR::SensorDevice> enumerator = pManager->EnumerateDevices<OVR::SensorDevice>(); - 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); - } + 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::GetHeadPoseData(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<Axis_Y, Axis_X, Axis_Z>(&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; + 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<Axis_Y, Axis_X, Axis_Z>(&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; } } } -extern "C" FTNOIR_TRACKER_BASE_EXPORT ITracker* CALLING_CONVENTION GetConstructor() +extern "C" OPENTRACK_EXPORT ITracker* GetConstructor() { return new Rift_Tracker; } diff --git a/ftnoir_tracker_rift/ftnoir_tracker_rift.h b/ftnoir_tracker_rift/ftnoir_tracker_rift.h index 7162b7ca..b862555c 100644 --- a/ftnoir_tracker_rift/ftnoir_tracker_rift.h +++ b/ftnoir_tracker_rift/ftnoir_tracker_rift.h @@ -1,10 +1,9 @@ #pragma once -#include "ftnoir_tracker_base/ftnoir_tracker_base.h" #include "ui_ftnoir_rift_clientcontrols.h" #include <QMessageBox> #include <QWaitCondition> #include <cmath> -#include "facetracknoir/global-settings.h" +#include "facetracknoir/plugin-api.hpp" #include "OVR.h" #include <memory> #include "facetracknoir/options.h" @@ -12,13 +11,10 @@ using namespace options; struct settings { pbundle b; - value<bool> bEnableYaw, bEnablePitch, bEnableRoll, useYawSpring; + value<bool> useYawSpring; value<double> constant_drift, persistence, deadzone; settings() : b(bundle("Rift")), - bEnableYaw(b, "EnableYaw", true), - bEnablePitch(b, "EnablePitch", true), - bEnableRoll(b, "EnableRoll", true), useYawSpring(b, "yaw-spring", false), constant_drift(b, "constant-drift", 0.000005), persistence(b, "persistence", 0.99999), @@ -29,55 +25,46 @@ struct settings { class Rift_Tracker : public ITracker { public: - Rift_Tracker(); - virtual ~Rift_Tracker() virt_override; - - void StartTracker(QFrame *) virt_override; - void GetHeadPoseData(double *data) virt_override; - virtual int preferredHz() virt_override { return 250; } - volatile bool should_quit; -protected: - void run(); // qthread override run method - + Rift_Tracker(); + ~Rift_Tracker() override; + void StartTracker(QFrame *) override; + void GetHeadPoseData(double *data) override; private: - static bool isInitialised; - OVR::DeviceManager* pManager; - OVR::SensorDevice* pSensor; - OVR::SensorFusion* pSFusion; - settings s; double old_yaw; + ovrHmd hmd; + settings s; }; class TrackerControls: public QWidget, public ITrackerDialog { Q_OBJECT public: - explicit TrackerControls(); + explicit TrackerControls(); void registerTracker(ITracker *) {} - void unRegisterTracker() {} + void unRegisterTracker() {} private: - Ui::UIRiftControls ui; + Ui::UIRiftControls ui; settings s; private slots: - void doOK(); - void doCancel(); + void doOK(); + void doCancel(); }; class FTNoIR_TrackerDll : public Metadata { public: - FTNoIR_TrackerDll(); - ~FTNoIR_TrackerDll(); - void getFullName(QString *strToBeFilled); - void getShortName(QString *strToBeFilled); - void getDescription(QString *strToBeFilled); - void getIcon(QIcon *icon); + FTNoIR_TrackerDll(); + ~FTNoIR_TrackerDll(); + void getFullName(QString *strToBeFilled); + void getShortName(QString *strToBeFilled); + void getDescription(QString *strToBeFilled); + void getIcon(QIcon *icon); private: - QString trackerFullName; // Trackers' name and description - QString trackerShortName; - QString trackerDescription; + QString trackerFullName; // Trackers' name and description + QString trackerShortName; + QString trackerDescription; }; diff --git a/ftnoir_tracker_rift/ftnoir_tracker_rift_dialog.cpp b/ftnoir_tracker_rift/ftnoir_tracker_rift_dialog.cpp index ad532100..38c7457e 100644 --- a/ftnoir_tracker_rift/ftnoir_tracker_rift_dialog.cpp +++ b/ftnoir_tracker_rift/ftnoir_tracker_rift_dialog.cpp @@ -1,19 +1,14 @@ #include "ftnoir_tracker_rift.h" -#include "facetracknoir/global-settings.h" +#include "facetracknoir/plugin-support.h" TrackerControls::TrackerControls() : QWidget() { - ui.setupUi( this ); + ui.setupUi( this ); - // Connect Qt signals to member-functions connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); - tie_setting(s.bEnableYaw, ui.chkEnableYaw); - tie_setting(s.bEnablePitch, ui.chkEnablePitch); - tie_setting(s.bEnableRoll, ui.chkEnableRoll); - tie_setting(s.constant_drift, ui.constantDrift); tie_setting(s.deadzone, ui.deadzone); tie_setting(s.persistence, ui.persistence); @@ -26,11 +21,11 @@ void TrackerControls::doOK() { } void TrackerControls::doCancel() { - s.b->revert(); + s.b->reload(); close(); } -extern "C" FTNOIR_TRACKER_BASE_EXPORT ITrackerDialog* CALLING_CONVENTION GetDialog( ) +extern "C" OPENTRACK_EXPORT ITrackerDialog* GetDialog() { return new TrackerControls; } diff --git a/ftnoir_tracker_rift/ftnoir_tracker_rift_dll.cpp b/ftnoir_tracker_rift/ftnoir_tracker_rift_dll.cpp index 2b24411c..902c8051 100644 --- a/ftnoir_tracker_rift/ftnoir_tracker_rift_dll.cpp +++ b/ftnoir_tracker_rift/ftnoir_tracker_rift_dll.cpp @@ -1,7 +1,7 @@ /* Copyright: "i couldn't care less what anyone does with the 5 lines of code i wrote" - mm0zct */ #include "ftnoir_tracker_rift.h" #include <QDebug> -#include "facetracknoir/global-settings.h" +#include "facetracknoir/plugin-support.h" FTNoIR_TrackerDll::FTNoIR_TrackerDll() { //populate the description strings @@ -35,7 +35,7 @@ void FTNoIR_TrackerDll::getIcon(QIcon *icon) *icon = QIcon(":/images/rift_tiny.png"); } -extern "C" FTNOIR_TRACKER_BASE_EXPORT Metadata* CALLING_CONVENTION GetMetadata() +extern "C" OPENTRACK_EXPORT Metadata* GetMetadata() { return new FTNoIR_TrackerDll; } |