From 513f93b01ac22842746f493c23bb48eb36071dc5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 1 Nov 2013 23:16:11 +0100 Subject: spring v2: magic nums -> ui, squash uninit mem access -sthalik&mm0zct --- ftnoir_tracker_rift/ftnoir_rift_clientcontrols.ui | 110 +++++++++++++++++---- ftnoir_tracker_rift/ftnoir_tracker_rift.cpp | 17 +++- ftnoir_tracker_rift/ftnoir_tracker_rift.h | 3 +- ftnoir_tracker_rift/ftnoir_tracker_rift_dialog.cpp | 8 ++ 4 files changed, 118 insertions(+), 20 deletions(-) (limited to 'ftnoir_tracker_rift') diff --git a/ftnoir_tracker_rift/ftnoir_rift_clientcontrols.ui b/ftnoir_tracker_rift/ftnoir_rift_clientcontrols.ui index 9c3ec53a..38e745c9 100644 --- a/ftnoir_tracker_rift/ftnoir_rift_clientcontrols.ui +++ b/ftnoir_tracker_rift/ftnoir_rift_clientcontrols.ui @@ -9,10 +9,16 @@ 0 0 - 176 - 145 + 195 + 265 + + + 0 + 0 + + Oculus Rift tracker settings FaceTrackNoIR @@ -26,21 +32,9 @@ false - - + + - - - 0 - 0 - - - - - 0 - 0 - - Enable Axis @@ -159,7 +153,89 @@ - + + + + Yaw spring + + + + + + Enable + + + + + + + Persistence + + + + + + + 5 + + + 0.900000000000000 + + + 1.000000000000000 + + + 0.001000000000000 + + + + + + + Constant drift + + + + + + + 5 + + + 0.000100000000000 + + + 0.100000000000000 + + + 0.001000000000000 + + + + + + + Deadzone + + + + + + + 5 + + + 0.100000000000000 + + + 0.010000000000000 + + + + + + + diff --git a/ftnoir_tracker_rift/ftnoir_tracker_rift.cpp b/ftnoir_tracker_rift/ftnoir_tracker_rift.cpp index 7d567ca3..dc0892fe 100644 --- a/ftnoir_tracker_rift/ftnoir_tracker_rift.cpp +++ b/ftnoir_tracker_rift/ftnoir_tracker_rift.cpp @@ -21,6 +21,7 @@ Rift_Tracker::Rift_Tracker() pHMD = NULL; pSensor = NULL; pSFusion = NULL; + old_yaw = 0; } Rift_Tracker::~Rift_Tracker() @@ -87,9 +88,17 @@ bool Rift_Tracker::GiveHeadPoseData(double *data) float pitch = 0.0f; float roll = 0.0f; hmdOrient.GetEulerAngles(&yaw, &pitch , &roll); - newHeadPose[Yaw] = yaw; - newHeadPose[Pitch] =pitch; + newHeadPose[Pitch] = pitch; newHeadPose[Roll] = roll; + newHeadPose[Yaw] = yaw; + if (useYawSpring) + { + newHeadPose[Yaw] = newHeadPose[Yaw]*persistence + (yaw-old_yaw); + if(newHeadPose[Yaw]>deadzone)newHeadPose[Yaw]-= constant_drift; + if(newHeadPose[Yaw]<-deadzone)newHeadPose[Yaw]+= constant_drift; + old_yaw=yaw; + } + else #if 0 newHeadPose[TX] = acd.controllers[0].pos[0]/50.0f; @@ -142,6 +151,10 @@ void Rift_Tracker::loadSettings() { bEnableY = iniFile.value ( "EnableY", 1 ).toBool(); bEnableZ = iniFile.value ( "EnableZ", 1 ).toBool(); #endif + useYawSpring = iniFile.value("yaw-spring", false).toBool(); + constant_drift = iniFile.value("constant-drift", 0.000005).toDouble(); + persistence = iniFile.value("persistence", 0.99999).toDouble(); + deadzone = iniFile.value("deadzone", 0.02).toDouble(); iniFile.endGroup (); } diff --git a/ftnoir_tracker_rift/ftnoir_tracker_rift.h b/ftnoir_tracker_rift/ftnoir_tracker_rift.h index 55fa99e3..bd295838 100644 --- a/ftnoir_tracker_rift/ftnoir_tracker_rift.h +++ b/ftnoir_tracker_rift/ftnoir_tracker_rift.h @@ -35,7 +35,8 @@ private: bool bEnableY; bool bEnableZ; #endif - + bool useYawSpring; + double old_yaw, constant_drift, persistence, deadzone; }; // Widget that has controls for FTNoIR protocol client-settings. diff --git a/ftnoir_tracker_rift/ftnoir_tracker_rift_dialog.cpp b/ftnoir_tracker_rift/ftnoir_tracker_rift_dialog.cpp index 6b1a559d..2efefbb3 100644 --- a/ftnoir_tracker_rift/ftnoir_tracker_rift_dialog.cpp +++ b/ftnoir_tracker_rift/ftnoir_tracker_rift_dialog.cpp @@ -117,6 +117,10 @@ void TrackerControls::loadSettings() { ui.chkEnableY->setChecked(iniFile.value ( "EnableY", 1 ).toBool()); ui.chkEnableZ->setChecked(iniFile.value ( "EnableZ", 1 ).toBool()); #endif + ui.yawSpring->setChecked(iniFile.value("yaw-spring", true).toBool()); + ui.deadzone->setValue(iniFile.value("deadzone", 0.02).toDouble()); + ui.constantDrift->setValue(iniFile.value("constant-drift", 0.000005).toDouble()); + ui.persistence->setValue(iniFile.value("persistence", 0.9999).toDouble()); iniFile.endGroup (); settingsDirty = false; @@ -140,6 +144,10 @@ void TrackerControls::save() { iniFile.setValue ( "EnableY", ui.chkEnableY->isChecked() ); iniFile.setValue ( "EnableZ", ui.chkEnableZ->isChecked() ); #endif + iniFile.setValue("yaw-spring", ui.yawSpring->isChecked()); + iniFile.setValue("deadzone", ui.deadzone->value()); + iniFile.setValue("constant-drift", ui.constantDrift->value()); + iniFile.setValue("persistence", ui.persistence->value()); iniFile.endGroup (); settingsDirty = false; -- cgit v1.2.3