From aa066bdd4622d4f6824fee864f6be6806813f04d Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 30 Oct 2015 07:37:41 +0100 Subject: move to subdirectory-based build system Closes #224 --- tracker-rift-025/ftnoir_tracker_rift_025.cpp | 92 ++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 tracker-rift-025/ftnoir_tracker_rift_025.cpp (limited to 'tracker-rift-025/ftnoir_tracker_rift_025.cpp') diff --git a/tracker-rift-025/ftnoir_tracker_rift_025.cpp b/tracker-rift-025/ftnoir_tracker_rift_025.cpp new file mode 100644 index 00000000..9588aaf8 --- /dev/null +++ b/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,"Error", "Unable to create Rift sensor",QMessageBox::Ok,QMessageBox::NoButton); + } + + } + else + { + QMessageBox::warning(0,"Error", "Unable to enumerate Rift tracker",QMessageBox::Ok,QMessageBox::NoButton); + } + } + else + { + QMessageBox::warning(0,"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) -- cgit v1.2.3