summaryrefslogtreecommitdiffhomepage
path: root/facetracknoir
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2013-07-18 15:11:54 +0200
committerStanislaw Halik <sthalik@misaki.pl>2013-07-18 15:11:54 +0200
commitcaf7361b7c41963643948cb03d19ad91b27ff0ae (patch)
tree69ab40b6f9880a9cc6d34919e981d6dd6c719f35 /facetracknoir
parent4e866b559a10a61d3645a47e7b0c4b2a85ff9424 (diff)
Proper fix for sleeping with a lock held
Diffstat (limited to 'facetracknoir')
-rw-r--r--facetracknoir/tracker.cpp117
1 files changed, 59 insertions, 58 deletions
diff --git a/facetracknoir/tracker.cpp b/facetracknoir/tracker.cpp
index 3b2562a8..7eedfea1 100644
--- a/facetracknoir/tracker.cpp
+++ b/facetracknoir/tracker.cpp
@@ -135,72 +135,73 @@ void Tracker::run() {
bTracker1Confid = Libraries->pTracker->GiveHeadPoseData(newpose);
}
- confid = bTracker1Confid || bTracker2Confid;
-
- if ( confid ) {
- for (int i = 0; i < 6; i++)
- mainApp->axis(i).headPos = newpose[i];
- }
-
- //
- // If Center is pressed, copy the current values to the offsets.
- //
- if (do_center) {
- //
- // Only copy valid values
- //
- if (confid) {
- for (int i = 0; i < 6; i++)
- offset_camera.axes[i] = mainApp->axis(i).headPos;
- }
-
- Tracker::do_center = false;
-
- if (Libraries->pTracker)
- Libraries->pTracker->NotifyCenter();
-
- if (Libraries->pSecondTracker)
- Libraries->pSecondTracker->NotifyCenter();
-
- if (Libraries->pFilter)
- Libraries->pFilter->Initialize();
- }
-
- if (getTrackingActive()) {
+ {
QMutexLocker foo(&mtx);
+ confid = bTracker1Confid || bTracker2Confid;
- // get values
- for (int i = 0; i < 6; i++)
- target_camera.axes[i] = mainApp->axis(i).headPos;
-
- // do the centering
- target_camera = target_camera - offset_camera;
-
- //
- // Use advanced filtering, when a filter was selected.
- //
- if (Libraries->pFilter) {
+ if ( confid ) {
for (int i = 0; i < 6; i++)
- last_post_filter[i] = gameoutput_camera.axes[i];
- Libraries->pFilter->FilterHeadPoseData(current_camera.axes, target_camera.axes, new_camera.axes, last_post_filter);
- }
- else {
- new_camera = target_camera;
- }
-
- for (int i = 0; i < 6; i++) {
- get_curve(new_camera.axes[i], output_camera.axes[i], mainApp->axis(i));
+ mainApp->axis(i).headPos = newpose[i];
}
-
+
//
- // Send the headpose to the game
+ // If Center is pressed, copy the current values to the offsets.
//
- if (Libraries->pProtocol) {
- gameoutput_camera = output_camera;
- Libraries->pProtocol->sendHeadposeToGame( gameoutput_camera.axes, newpose ); // degrees & centimeters
+ if (do_center) {
+ //
+ // Only copy valid values
+ //
+ if (confid) {
+ for (int i = 0; i < 6; i++)
+ offset_camera.axes[i] = mainApp->axis(i).headPos;
+ }
+
+ Tracker::do_center = false;
+
+ if (Libraries->pTracker)
+ Libraries->pTracker->NotifyCenter();
+
+ if (Libraries->pSecondTracker)
+ Libraries->pSecondTracker->NotifyCenter();
+
+ if (Libraries->pFilter)
+ Libraries->pFilter->Initialize();
+ }
+
+ if (getTrackingActive()) {
+ // get values
+ for (int i = 0; i < 6; i++)
+ target_camera.axes[i] = mainApp->axis(i).headPos;
+
+ // do the centering
+ target_camera = target_camera - offset_camera;
+
+ //
+ // Use advanced filtering, when a filter was selected.
+ //
+ if (Libraries->pFilter) {
+ for (int i = 0; i < 6; i++)
+ last_post_filter[i] = gameoutput_camera.axes[i];
+ Libraries->pFilter->FilterHeadPoseData(current_camera.axes, target_camera.axes, new_camera.axes, last_post_filter);
+ }
+ else {
+ new_camera = target_camera;
+ }
+
+ for (int i = 0; i < 6; i++) {
+ get_curve(new_camera.axes[i], output_camera.axes[i], mainApp->axis(i));
+ }
+
+ //
+ // Send the headpose to the game
+ //
+ if (Libraries->pProtocol) {
+ gameoutput_camera = output_camera;
+ Libraries->pProtocol->sendHeadposeToGame( gameoutput_camera.axes, newpose ); // degrees & centimeters
+ }
}
}
-
+
//for lower cpu load
msleep(1);
}