summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_tracker_rift
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2014-07-11 11:32:17 +0200
committerStanislaw Halik <sthalik@misaki.pl>2014-07-11 11:38:21 +0200
commit23614e1e5aa464e91abba2bfe9d902392bd40c46 (patch)
treeefbe67ad09046b2b364c8bc44692a5b29cb0cd9e /ftnoir_tracker_rift
parent790cb945566e0575cbdd2962cc3189db26f0c0ee (diff)
adapt rift to needlessly changed api in sdk 0.3.x
Diffstat (limited to 'ftnoir_tracker_rift')
-rw-r--r--ftnoir_tracker_rift/ftnoir_tracker_rift.cpp100
-rw-r--r--ftnoir_tracker_rift/ftnoir_tracker_rift.h9
2 files changed, 45 insertions, 64 deletions
diff --git a/ftnoir_tracker_rift/ftnoir_tracker_rift.cpp b/ftnoir_tracker_rift/ftnoir_tracker_rift.cpp
index b548db71..14b8db67 100644
--- a/ftnoir_tracker_rift/ftnoir_tracker_rift.cpp
+++ b/ftnoir_tracker_rift/ftnoir_tracker_rift.cpp
@@ -1,53 +1,31 @@
/* 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 "OVR_CAPI.h"
+#include "Kernel/OVR_Math.h"
#include <cstdio>
using namespace OVR;
-Rift_Tracker::Rift_Tracker()
+Rift_Tracker::Rift_Tracker() :
+ should_quit(false), 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);
- }
+ ovrHmd_GetDesc(hmd, &hmdDesc);
+ ovrHmd_StartSensor(hmd, ovrSensorCap_Orientation| ovrSensorCap_YawCorrection | ovrSensorCap_Position, ovrSensorCap_Orientation);
}else{
QMessageBox::warning(0,"FaceTrackNoIR Error", "Unable to start Rift tracker",QMessageBox::Ok,QMessageBox::NoButton);
}
@@ -56,32 +34,36 @@ void Rift_Tracker::StartTracker(QFrame*)
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)
+ {
+ frameTiming = ovrHmd_BeginFrameTiming(hmd, 0);
+ ovrSensorState ss = ovrHmd_GetSensorState(hmd, frameTiming.ScanoutMidpointSeconds);
+ if(ss.StatusFlags & (ovrStatus_OrientationTracked | ovrStatus_PositionTracked)){
+ ovrPosef pose = ss.Predicted.Pose;
+ Quatf quat = pose.Orientation;
+ float yaw, pitch, roll;
+ double newHeadPose[6] = {0};
+ quat.GetEulerAngles<Axis_Y, Axis_X, Axis_Z>(&yaw, &pitch, &roll);
+ 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;
+ }
+ ovrHmd_EndFrameTiming(hmd);
+ newHeadPose[Pitch] = pitch;
+ newHeadPose[Roll] = roll;
+ newHeadPose[Yaw] = yaw;
}
}
}
diff --git a/ftnoir_tracker_rift/ftnoir_tracker_rift.h b/ftnoir_tracker_rift/ftnoir_tracker_rift.h
index 7162b7ca..26496bc2 100644
--- a/ftnoir_tracker_rift/ftnoir_tracker_rift.h
+++ b/ftnoir_tracker_rift/ftnoir_tracker_rift.h
@@ -40,12 +40,11 @@ protected:
void run(); // qthread override run method
private:
- static bool isInitialised;
- OVR::DeviceManager* pManager;
- OVR::SensorDevice* pSensor;
- OVR::SensorFusion* pSFusion;
- settings s;
double old_yaw;
+ ovrHmd hmd;
+ ovrHmdDesc hmdDesc;
+ ovrFrameTiming frameTiming;
+ settings s;
};
class TrackerControls: public QWidget, public ITrackerDialog