From f79e3f588e8bb112420da3a3912ee83dc28370c7 Mon Sep 17 00:00:00 2001 From: Wim Vriend Date: Fri, 15 Apr 2011 17:21:31 +0000 Subject: 6DOF git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@75 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb --- FaceTrackNoIR/FaceTrackNoIR.cpp | 142 +++++-------- FaceTrackNoIR/FaceTrackNoIR.h | 2 +- FaceTrackNoIR/FaceTrackNoIR.ui | 398 ++++++++++++++++++++++--------------- FaceTrackNoIR/FaceTrackNoIR.vcproj | 259 +----------------------- FaceTrackNoIR/tracker.cpp | 368 +++++++++++++++------------------- FaceTrackNoIR/tracker.h | 20 +- 6 files changed, 458 insertions(+), 731 deletions(-) (limited to 'FaceTrackNoIR') diff --git a/FaceTrackNoIR/FaceTrackNoIR.cpp b/FaceTrackNoIR/FaceTrackNoIR.cpp index 49a6aab2..8646c248 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.cpp +++ b/FaceTrackNoIR/FaceTrackNoIR.cpp @@ -31,12 +31,6 @@ */ #include "FaceTrackNoIR.h" #include "tracker.h" -//#include "PPJoyServer.h" -#include "FSUIPCServer.h" -//#include "FTIRServer.h" -//#include "FGServer.h" -#include "FTNServer.h" - // // Setup the Main Dialog @@ -50,7 +44,6 @@ QMainWindow(parent, flags) // Initialize Widget handles, to prevent memory-access errors. // _engine_controls = 0; - _server_controls = 0; _keyboard_shortcuts = 0; _preferences = 0; _keyboard_shortcuts = 0; @@ -160,6 +153,8 @@ void FaceTrackNoIR::setupFaceTrackNoIR() { //Setup the timer for showing the headpose. timUpdateHeadPose = new QTimer(this); connect(timUpdateHeadPose, SIGNAL(timeout()), this, SLOT(showHeadPose())); + ui.txtTracking->setVisible(false); + ui.txtAxisReverse->setVisible(false); } /** destructor stops the engine and quits the faceapi **/ @@ -593,6 +588,8 @@ void FaceTrackNoIR::stopTracker( ) { ui.lcdNumOutputRotX->setVisible(false); ui.lcdNumOutputRotY->setVisible(false); ui.lcdNumOutputRotZ->setVisible(false); + ui.txtTracking->setVisible(false); + ui.txtAxisReverse->setVisible(false); // // Delete the tracker (after stopping things and all). @@ -689,6 +686,9 @@ THeadPoseData newdata; ui.lcdNumRotY->display((double) (((int)(newdata.pitch * 10.0f))/10.0f)); ui.lcdNumRotZ->display((double) (((int)(newdata.roll * 10.0f))/10.0f)); + ui.txtTracking->setVisible(Tracker::getTrackingActive()); + ui.txtAxisReverse->setVisible(Tracker::getAxisReverse()); + // // Get the output-pose and also display it. // @@ -816,104 +816,68 @@ QLibrary *trackerLib; void FaceTrackNoIR::showServerControls() { importGetProtocolDialog getIT; QLibrary *protocolLib; - +QString libName; // // Delete the existing QDialog // - if (_server_controls) { - delete _server_controls; - _server_controls = 0; + if (pProtocolDialog) { + pProtocolDialog.Release(); } - // Create if new - if (!_server_controls) - { + // Show the appropriate Protocol-server Settings + libName.clear(); + switch (ui.iconcomboBox->currentIndex()) { + case FREE_TRACK: + case SIMCONNECT: + break; - // Show the appropriate Protocol-server Settings - switch (ui.iconcomboBox->currentIndex()) { - case FREE_TRACK: - case SIMCONNECT: - break; + case PPJOY: + libName = QString("FTNoIR_Protocol_PPJOY.dll"); + break; - case PPJOY: - protocolLib = new QLibrary("FTNoIR_Protocol_PPJOY.dll"); + case FSUIPC: + libName = QString("FTNoIR_Protocol_FSUIPC.dll"); + break; - getIT = (importGetProtocolDialog) protocolLib->resolve("GetProtocolDialog"); - if (getIT) { - IProtocolDialogPtr ptrXyz(getIT()); - if (ptrXyz) - { - pProtocolDialog = ptrXyz; - pProtocolDialog->Initialize( this ); - qDebug() << "FaceTrackNoIR::showServerControls GetProtocolDialog Function Resolved!"; - } - else { - qDebug() << "FaceTrackNoIR::showServerControls Function NOT Resolved!"; - } - } - else { - QMessageBox::warning(0,"FaceTrackNoIR Error", "DLL not loaded",QMessageBox::Ok,QMessageBox::NoButton); - } - break; + case TRACKIR: + libName = QString("FTNoIR_Protocol_FTIR.dll"); + break; - case FSUIPC: - _server_controls = new FSUIPCControls( this, Qt::Dialog ); - break; - case TRACKIR: - protocolLib = new QLibrary("FTNoIR_Protocol_FTIR.dll"); + case FLIGHTGEAR: + libName = QString("FTNoIR_Protocol_FG.dll"); + break; - getIT = (importGetProtocolDialog) protocolLib->resolve("GetProtocolDialog"); - if (getIT) { - IProtocolDialogPtr ptrXyz(getIT()); - if (ptrXyz) - { - pProtocolDialog = ptrXyz; - pProtocolDialog->Initialize( this ); - qDebug() << "FaceTrackNoIR::showServerControls GetProtocolDialog Function Resolved!"; - } - else { - qDebug() << "FaceTrackNoIR::showServerControls Function NOT Resolved!"; - } - } - else { - QMessageBox::warning(0,"FaceTrackNoIR Error", "DLL not loaded",QMessageBox::Ok,QMessageBox::NoButton); - } - break; + case FTNOIR: + libName = QString("FTNoIR_Protocol_FTN.dll"); + break; - case FLIGHTGEAR: - protocolLib = new QLibrary("FTNoIR_Protocol_FG.dll"); + default: + break; + } - getIT = (importGetProtocolDialog) protocolLib->resolve("GetProtocolDialog"); - if (getIT) { - IProtocolDialogPtr ptrXyz(getIT()); - if (ptrXyz) - { - pProtocolDialog = ptrXyz; - pProtocolDialog->Initialize( this ); - qDebug() << "FaceTrackNoIR::showServerControls GetProtocolDialog Function Resolved!"; - } - else { - qDebug() << "FaceTrackNoIR::showServerControls Function NOT Resolved!"; - } + // + // Load the Server-settings dialog (if any) and show it. + // + if (!libName.isEmpty()) { + protocolLib = new QLibrary(libName); + + getIT = (importGetProtocolDialog) protocolLib->resolve("GetProtocolDialog"); + if (getIT) { + IProtocolDialogPtr ptrXyz(getIT()); + if (ptrXyz) + { + pProtocolDialog = ptrXyz; + pProtocolDialog->Initialize( this ); + qDebug() << "FaceTrackNoIR::showServerControls GetProtocolDialog Function Resolved!"; } else { - QMessageBox::warning(0,"FaceTrackNoIR Error", "DLL not loaded",QMessageBox::Ok,QMessageBox::NoButton); - } - break; - - case FTNOIR: - _server_controls = new FTNServerControls( this, Qt::Dialog ); - break; - default: - break; + qDebug() << "FaceTrackNoIR::showServerControls Function NOT Resolved!"; + } + } + else { + QMessageBox::warning(0,"FaceTrackNoIR Error", "DLL not loaded",QMessageBox::Ok,QMessageBox::NoButton); } - } - - // Show if already created - if (_server_controls) { - _server_controls->show(); - _server_controls->raise(); } } diff --git a/FaceTrackNoIR/FaceTrackNoIR.h b/FaceTrackNoIR/FaceTrackNoIR.h index cd9c925b..5ad2a348 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.h +++ b/FaceTrackNoIR/FaceTrackNoIR.h @@ -89,7 +89,7 @@ private: /** Widget variables **/ QVBoxLayout *l; QWidget *_engine_controls; - QWidget *_server_controls; +// QWidget *_server_controls; QWidget *_preferences; QWidget *_keyboard_shortcuts; QWidget *_curve_config; diff --git a/FaceTrackNoIR/FaceTrackNoIR.ui b/FaceTrackNoIR/FaceTrackNoIR.ui index 48d231ac..2cfe5fbc 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.ui +++ b/FaceTrackNoIR/FaceTrackNoIR.ui @@ -11,7 +11,7 @@ 0 0 925 - 396 + 411 @@ -58,6 +58,11 @@ QWidget#widget4logo { background-color: #000000; } +/* Specials for individual widget(s) */ +QWidget#headPoseWidget { + background-color: #595959; +} + QWidget#widget4video { /* background-color: #595959;*/ } @@ -331,197 +336,266 @@ Support FaceTrackNoIR! 0 - 100 + 160 16777215 - 100 + 160 - + 10 - 10 - 21 - 16 + 60 + 231 + 80 - - border:none; -color:white + + Raw Input - - X - - - - - - 10 - 40 - 21 - 16 - + + true - - border:none; + + + + 150 + 60 + 71 + 21 + + + + QFrame::NoFrame + + + + + + 150 + 20 + 71 + 21 + + + + QFrame::NoFrame + + + + + + 10 + 20 + 21 + 16 + + + + border:none; +color:white + + + X + + + + + + 10 + 40 + 21 + 16 + + + + border:none; color:white; - - - Y - - - - - - 10 - 70 - 21 - 16 - - - - color:white; + + + Y + + + + + + 30 + 60 + 61 + 21 + + + + QFrame::NoFrame + + + + + + 10 + 60 + 21 + 16 + + + + color:white; border:none; - - - Z - - - - - - 120 - 70 - 21 - 16 - - - - border:none; + + + Z + + + + + + 30 + 40 + 61 + 21 + + + + QFrame::NoFrame + + + + + + 120 + 60 + 21 + 16 + + + + border:none; color:white; - - - rotZ - - - - - - 120 - 40 - 21 - 16 - - - - color:white; + + + rotZ + + + + + + 120 + 40 + 21 + 16 + + + + color:white; border:none; - - - rotY - - - - - - 120 - 10 - 21 - 16 - - - - border:none; + + + rotY + + + + + + 120 + 20 + 21 + 16 + + + + border:none; color:white; - - - rotX - - - - - - 30 - 10 - 71 - 23 - - - - QFrame::NoFrame - - - - - - 30 - 40 - 71 - 23 - - - - QFrame::NoFrame - - - - - - 30 - 70 - 71 - 23 - - - - QFrame::NoFrame - + + + rotX + + + + + + 150 + 40 + 71 + 21 + + + + QFrame::NoFrame + + + + + + 30 + 20 + 61 + 21 + + + + QFrame::NoFrame + + + 5 + + - + - 150 + 10 10 - 71 - 23 - - - - QFrame::NoFrame - - - - - - 150 - 40 - 71 - 23 + 231 + 50 - - QFrame::NoFrame + + Status - - - - - 150 - 70 - 71 - 23 - - - - QFrame::NoFrame + + true + + + + 110 + 10 + 101 + 16 + + + + border:none; +color: rgb(0, 255, 0); + + + Tracking + + + + + + 110 + 30 + 101 + 16 + + + + border:none; +color: rgb(0, 255, 0); + + + Axis Reverse + + diff --git a/FaceTrackNoIR/FaceTrackNoIR.vcproj b/FaceTrackNoIR/FaceTrackNoIR.vcproj index 67546f1b..837d7f69 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.vcproj +++ b/FaceTrackNoIR/FaceTrackNoIR.vcproj @@ -70,7 +70,7 @@ /> - - - - @@ -227,10 +219,6 @@ RelativePath=".\main.cpp" > - - @@ -319,32 +307,6 @@ /> - - - - - - - - @@ -371,32 +333,6 @@ /> - - - - - - - - @@ -427,32 +363,6 @@ RelativePath=".\resource.h" > - - - - - - - - @@ -537,58 +447,6 @@ /> - - - - - - - - - - - - - - - - @@ -716,14 +574,6 @@ RelativePath=".\GeneratedFiles\ui_FTNoIR_Curves.h" > - - - - @@ -773,18 +623,6 @@ /> - - - - - @@ -797,18 +635,6 @@ /> - - - - - @@ -821,18 +647,6 @@ /> - - - - - @@ -898,29 +712,6 @@ /> - - - - - - - - @@ -933,29 +724,6 @@ /> - - - - - - - - @@ -979,29 +747,6 @@ /> - - - - - - - - diff --git a/FaceTrackNoIR/tracker.cpp b/FaceTrackNoIR/tracker.cpp index 0dd7311e..223d6d28 100644 --- a/FaceTrackNoIR/tracker.cpp +++ b/FaceTrackNoIR/tracker.cpp @@ -23,6 +23,9 @@ *********************************************************************************/ /* Modifications (last one on top): + 20110411 - WVR: Finished moving all Protocols to separate C++ projects. Every protocol now + has it's own Class, that's inside it's own DLL. This reduces the size of the program, + makes it more structured and enables a more sophisticated installer. 20110328 - WVR: Changed the camera-structs into class-instances. This makes initialisation easier and hopefully solves the remaining 'start-up problem'. 20110313 - WVR: Removed 'set_initial'. Less is more. @@ -63,16 +66,18 @@ bool Tracker::confid = false; bool Tracker::do_tracking = true; bool Tracker::do_center = false; bool Tracker::do_inhibit = false; +bool Tracker::do_axis_reverse = false; + bool Tracker::useFilter = false; bool Tracker::setZero = true; bool Tracker::setEngineStop = true; HANDLE Tracker::hTrackMutex = 0; -T6DOF Tracker::current_camera; // Used for filtering -T6DOF Tracker::target_camera; -T6DOF Tracker::new_camera; -T6DOF Tracker::output_camera; // Position sent to game protocol +T6DOF Tracker::current_camera(0,0,0,0,0,0); // Used for filtering +T6DOF Tracker::target_camera(0,0,0,0,0,0); +T6DOF Tracker::new_camera(0,0,0,0,0,0); +T6DOF Tracker::output_camera(0,0,0,0,0,0); // Position sent to game protocol THeadPoseDOF Tracker::Pitch; // One structure for each of 6DOF's THeadPoseDOF Tracker::Yaw; @@ -84,6 +89,7 @@ THeadPoseDOF Tracker::Z; TShortKey Tracker::CenterKey; // ShortKey to Center headposition TShortKey Tracker::StartStopKey; // ShortKey to Start/stop tracking TShortKey Tracker::InhibitKey; // ShortKey to inhibit axis while tracking +TShortKey Tracker::AxisReverseKey; // ShortKey to start/stop axis reverse while tracking ITrackerPtr Tracker::pTracker; // Pointer to Tracker instance (in DLL) IProtocolPtr Tracker::pProtocol; // Pointer to Protocol instance (in DLL) @@ -92,6 +98,7 @@ IFilterPtr Tracker::pFilter; // Pointer to Filter instance (in DLL) /** constructor **/ Tracker::Tracker( int clientID, int facetrackerID, FaceTrackNoIR *parent ) { +QString libName; importGetTracker getIT; QLibrary *trackerLib; importGetFilter getFilter; @@ -132,162 +139,73 @@ QFrame *video_frame; qDebug() << "Tracker::setup VideoFrame = " << video_frame; // - // Start the selected Tracker-engine + // Select the Tracker-engine DLL // switch (selectedTracker) { case FT_SM_FACEAPI: - trackerLib = new QLibrary("FTNoIR_Tracker_SM.dll"); - - getIT = (importGetTracker) trackerLib->resolve("GetTracker"); - - if (getIT) { - ITrackerPtr ptrXyz(getIT()); - if (ptrXyz) - { - pTracker = ptrXyz; - pTracker->Initialize( video_frame ); - qDebug() << "Tracker::setup Function Resolved!"; - } - } - else { - QMessageBox::warning(0,"FaceTrackNoIR Error", "DLL not loaded",QMessageBox::Ok,QMessageBox::NoButton); - } + libName = QString("FTNoIR_Tracker_SM.dll"); break; case FT_FTNOIR: - trackerLib = new QLibrary("FTNoIR_Tracker_UDP.dll"); - - getIT = (importGetTracker) trackerLib->resolve("GetTracker"); - - if (getIT) { - ITrackerPtr ptrXyz(getIT()); - if (ptrXyz) - { - pTracker = ptrXyz; - pTracker->Initialize( video_frame ); - qDebug() << "Tracker::setup Function Resolved!"; - } - } - else { - QMessageBox::warning(0,"FaceTrackNoIR Error", "DLL not loaded",QMessageBox::Ok,QMessageBox::NoButton); - } + libName = QString("FTNoIR_Tracker_UDP.dll"); break; default: break; } + // + // Load the Tracker-engine DLL, get the tracker-class from it and do stuff... + // + if (!libName.isEmpty()) { + trackerLib = new QLibrary(libName); + getIT = (importGetTracker) trackerLib->resolve("GetTracker"); + + if (getIT) { + ITrackerPtr ptrXyz(getIT()); // Get the Class + if (ptrXyz) + { + pTracker = ptrXyz; + pTracker->Initialize( video_frame ); + qDebug() << "Tracker::setup Function Resolved!"; + } + } + else { + QMessageBox::warning(0,"FaceTrackNoIR Error", "DLL not loaded",QMessageBox::Ok,QMessageBox::NoButton); + } + } // // Initialize all server-handles. Only start the server, that was selected in the GUI. // + libName.clear(); switch (selectedClient) { case FREE_TRACK: - server_Game = QSharedPointer(new FTNServer ( this )); // Create FaceTrackNoIR protocol-server - - // - // Load the DLL with the protocol-logic and retrieve a pointer to the Protocol-class. - // - protocolLib = new QLibrary("FTNoIR_Protocol_FT.dll"); - - getProtocol = (importGetProtocol) protocolLib->resolve("GetProtocol"); - if (getProtocol) { - IProtocolPtr ptrXyz(getProtocol()); - if (ptrXyz) - { - pProtocol = ptrXyz; - pProtocol->Initialize(); - qDebug() << "Protocol::setup Function Resolved!"; - } - } - else { - QMessageBox::warning(0,"FaceTrackNoIR Error", "Protocol-DLL not loaded",QMessageBox::Ok,QMessageBox::NoButton); - return; - } + libName = QString("FTNoIR_Protocol_FT.dll"); break; case FLIGHTGEAR: - server_Game = QSharedPointer(new FTNServer ( this )); // Create FaceTrackNoIR protocol-server - - // - // Load the DLL with the protocol-logic and retrieve a pointer to the Protocol-class. - // - protocolLib = new QLibrary("FTNoIR_Protocol_FG.dll"); - - getProtocol = (importGetProtocol) protocolLib->resolve("GetProtocol"); - if (getProtocol) { - IProtocolPtr ptrXyz(getProtocol()); - if (ptrXyz) - { - pProtocol = ptrXyz; - pProtocol->Initialize(); - qDebug() << "Protocol::setup Function Resolved!"; - } - } - else { - QMessageBox::warning(0,"FaceTrackNoIR Error", "Protocol-DLL not loaded",QMessageBox::Ok,QMessageBox::NoButton); - return; - } + libName = QString("FTNoIR_Protocol_FG.dll"); break; case FTNOIR: - server_Game = QSharedPointer(new FTNServer ( this )); // Create FaceTrackNoIR protocol-server + libName = QString("FTNoIR_Protocol_FTN.dll"); break; case PPJOY: - server_Game = QSharedPointer(new FTNServer ( this )); // Create FaceTrackNoIR protocol-server - - // - // Load the DLL with the protocol-logic and retrieve a pointer to the Protocol-class. - // - protocolLib = new QLibrary("FTNoIR_Protocol_PPJOY.dll"); - - getProtocol = (importGetProtocol) protocolLib->resolve("GetProtocol"); - if (getProtocol) { - IProtocolPtr ptrXyz(getProtocol()); - if (ptrXyz) - { - pProtocol = ptrXyz; - pProtocol->Initialize(); - qDebug() << "Protocol::setup Function Resolved!"; - } - } - else { - QMessageBox::warning(0,"FaceTrackNoIR Error", "Protocol-installation invalid",QMessageBox::Ok,QMessageBox::NoButton); - return; - } + libName = QString("FTNoIR_Protocol_PPJOY.dll"); break; case TRACKIR: - server_Game = QSharedPointer(new FTNServer ( this )); // Create FaceTrackNoIR protocol-server - - // - // Load the DLL with the protocol-logic and retrieve a pointer to the Protocol-class. - // - protocolLib = new QLibrary("FTNoIR_Protocol_FTIR.dll"); - - getProtocol = (importGetProtocol) protocolLib->resolve("GetProtocol"); - if (getProtocol) { - IProtocolPtr ptrXyz(getProtocol()); - if (ptrXyz) - { - pProtocol = ptrXyz; - pProtocol->Initialize(); - qDebug() << "Protocol::setup Function Resolved!"; - } - } - else { - QMessageBox::warning(0,"FaceTrackNoIR Error", "Protocol-DLL not loaded",QMessageBox::Ok,QMessageBox::NoButton); - return; - } + libName = QString("FTNoIR_Protocol_FTIR.dll"); break; case SIMCONNECT: - server_Game = QSharedPointer(new SCServer ( )); // Create SimConnect protocol-server + libName = QString("FTNoIR_Protocol_SC.dll"); break; case FSUIPC: - server_Game = QSharedPointer(new FSUIPCServer ( )); // Create FSUIPC protocol-server + libName = QString("FTNoIR_Protocol_FSUIPC.dll"); break; default: @@ -295,6 +213,27 @@ QFrame *video_frame; break; } + // + // Load the DLL with the protocol-logic and retrieve a pointer to the Protocol-class. + // + if (!libName.isEmpty()) { + protocolLib = new QLibrary(libName); + getProtocol = (importGetProtocol) protocolLib->resolve("GetProtocol"); + if (getProtocol) { + IProtocolPtr ptrXyz(getProtocol()); + if (ptrXyz) + { + pProtocol = ptrXyz; + pProtocol->Initialize(); + qDebug() << "Protocol::setup Function Resolved!"; + } + } + else { + QMessageBox::warning(0,"FaceTrackNoIR Error", "Protocol-DLL not loaded",QMessageBox::Ok,QMessageBox::NoButton); + return; + } + } + # ifdef USE_DEBUG_CLIENT debug_Client = QSharedPointer(new ExcelServer ( this )); // Create Excel protocol-server # endif @@ -346,11 +285,6 @@ Tracker::~Tracker() { ::CloseHandle( Tracker::hTrackMutex ); } - // Stop the started server(s) - if (server_Game) { - server_Game->deleteLater(); - } - # ifdef USE_DEBUG_CLIENT debug_Client->deleteLater(); // Delete Excel protocol-server # endif @@ -366,20 +300,6 @@ void Tracker::setup() { // retrieve pointers to the User Interface and the main Application pTracker->StartTracker( mainApp->winId() ); - // - // Check if the Protocol-server files were installed OK. - // Some servers also create a memory-mapping, for Inter Process Communication. - // The handle of the MainWindow is sent to 'The Game', so it can send a message back. - // - if (server_Game) { - - DLL_Ok = server_Game->checkServerInstallationOK( mainApp->winId() ); - if (!DLL_Ok) { - QMessageBox::information(mainApp, "FaceTrackNoIR error", "Protocol is not (correctly) installed!"); - } - - } - // // Check if the Protocol-server files were installed OK. // Some servers also create a memory-mapping, for Inter Process Communication. @@ -404,14 +324,18 @@ void Tracker::setup() { /** QThread run method @override **/ void Tracker::run() { - /** Direct Input variables **/ - LPDIRECTINPUT8 din; // the pointer to our DirectInput interface - LPDIRECTINPUTDEVICE8 dinkeyboard; // the pointer to the keyboard device - BYTE keystate[256]; // the storage for the key-information - HRESULT retAcquire; - bool lastCenterKey = false; // Remember state, to detect rising edge - bool lastStartStopKey = false; - bool lastInhibitKey = false; +/** Direct Input variables **/ +LPDIRECTINPUT8 din; // the pointer to our DirectInput interface +LPDIRECTINPUTDEVICE8 dinkeyboard; // the pointer to the keyboard device +BYTE keystate[256]; // the storage for the key-information +HRESULT retAcquire; +bool lastCenterKey = false; // Remember state, to detect rising edge +bool lastStartStopKey = false; +bool lastInhibitKey = false; +bool waitAxisReverse = false; +bool waitThroughZero = false; +double actualYaw = 0.0f; +T6DOF offset_camera(0,0,0,0,0,0); Tracker::do_center = true; // Center initially @@ -429,13 +353,6 @@ void Tracker::run() { qDebug() << "Tracker::run() FilterName = " << filterName; } - // - // Initialize all internal data of the Game-protocol. - // - if (server_Game) { - server_Game->resetProperties(); - } - // // Setup the DirectInput for keyboard strokes // @@ -519,6 +436,7 @@ void Tracker::run() { current_camera.initHeadPoseData(); target_camera.initHeadPoseData(); new_camera.initHeadPoseData(); + offset_camera.initHeadPoseData(); pTracker->StartTracker( mainApp->winId() ); } @@ -555,9 +473,25 @@ void Tracker::run() { } lastInhibitKey = isShortKeyPressed( &InhibitKey, &keystate[0] ); // Remember + // + // Check the state of the Axis Reverse key + // + if ( isShortKeyPressed( &AxisReverseKey, &keystate[0] ) ) { + if ((fabs(actualYaw) > 90.0f) && (!waitAxisReverse)) { + Tracker::do_axis_reverse = !Tracker::do_axis_reverse; + waitAxisReverse = true; + } + } } } + // + // Reset the 'wait' flag. Moving above 90 with the key pressed, will (de-)activate Axis Reverse. + // + if (fabs(actualYaw) < 85.0f) { + waitAxisReverse = false; + } + if (WaitForSingleObject(Tracker::hTrackMutex, 100) == WAIT_OBJECT_0) { THeadPoseData newpose; @@ -570,26 +504,34 @@ void Tracker::run() { // If Center is pressed, copy the current values to the offsets. // if (Tracker::confid && Tracker::do_center) { - Pitch.offset_headPos = getSmoothFromList( &Pitch.rawList ); - Yaw.offset_headPos = getSmoothFromList( &Yaw.rawList ); - Roll.offset_headPos = getSmoothFromList( &Roll.rawList ); - X.offset_headPos = getSmoothFromList( &X.rawList ); - Y.offset_headPos = getSmoothFromList( &Y.rawList ); - Z.offset_headPos = getSmoothFromList( &Z.rawList ); + //Pitch.offset_headPos = getSmoothFromList( &Pitch.rawList ); + //Yaw.offset_headPos = getSmoothFromList( &Yaw.rawList ); + //Roll.offset_headPos = getSmoothFromList( &Roll.rawList ); + //X.offset_headPos = getSmoothFromList( &X.rawList ); + //Y.offset_headPos = getSmoothFromList( &Y.rawList ); + //Z.offset_headPos = getSmoothFromList( &Z.rawList ); MessageBeep (MB_ICONASTERISK); + offset_camera.position.x = getSmoothFromList( &X.rawList ); + offset_camera.position.y = getSmoothFromList( &Y.rawList ); + offset_camera.position.z = getSmoothFromList( &Z.rawList ); + offset_camera.position.pitch = getSmoothFromList( &Pitch.rawList ); + offset_camera.position.yaw = getSmoothFromList( &Yaw.rawList ); + offset_camera.position.roll = getSmoothFromList( &Roll.rawList ); + Tracker::do_center = false; } if (Tracker::do_tracking && Tracker::confid) { // Pitch - target_camera.position.x = getSmoothFromList( &X.rawList ) - X.offset_headPos; - target_camera.position.y = getSmoothFromList( &Y.rawList ) - Y.offset_headPos; - target_camera.position.z = getSmoothFromList( &Z.rawList ) - Z.offset_headPos; - target_camera.position.pitch = getSmoothFromList( &Pitch.rawList ) - Pitch.offset_headPos; - target_camera.position.yaw = getSmoothFromList( &Yaw.rawList ) - Yaw.offset_headPos; - target_camera.position.roll = getSmoothFromList( &Roll.rawList ) - Roll.offset_headPos; + target_camera.position.x = getSmoothFromList( &X.rawList ); + target_camera.position.y = getSmoothFromList( &Y.rawList ); + target_camera.position.z = getSmoothFromList( &Z.rawList ); + target_camera.position.pitch = getSmoothFromList( &Pitch.rawList ); + target_camera.position.yaw = getSmoothFromList( &Yaw.rawList ); + target_camera.position.roll = getSmoothFromList( &Roll.rawList ); + target_camera = target_camera - offset_camera; if (Tracker::useFilter && pFilter) { pFilter->FilterHeadPoseData(¤t_camera.position, &target_camera.position, &new_camera.position, Tracker::Pitch.newSample); @@ -609,6 +551,33 @@ void Tracker::run() { output_camera.position.yaw = Yaw.invert * getOutputFromCurve(&Yaw.curve, new_camera.position.yaw, Yaw.NeutralZone, Yaw.MaxInput); output_camera.position.roll = Roll.invert * getOutputFromCurve(&Roll.curve, new_camera.position.roll, Roll.NeutralZone, Roll.MaxInput); + // + // Reverse Axis. + // + actualYaw = output_camera.position.yaw; // Save the actual Yaw, otherwise we can't check for +90 + if (Tracker::do_axis_reverse) { + if (fabs(actualYaw) < 5.0f) { + waitThroughZero = true; + } + if (waitThroughZero) { + output_camera.position.yaw *= -1.0f; + } + if (output_camera.position.yaw > 0.0f) { + output_camera.position.yaw = 180.0f - output_camera.position.yaw; + } + else { + output_camera.position.yaw = -180.0f - output_camera.position.yaw; + } + } + else { + if (fabs(actualYaw) < 5.0f) { + waitThroughZero = false; + } + if (waitThroughZero) { + output_camera.position.yaw *= -1.0f; + } + } + // // Reset value for the selected axis, if inhibition is active // @@ -621,44 +590,11 @@ void Tracker::run() { if (InhibitKey.doZ) output_camera.position.z = 0.0f; } - // - // Send the Virtual Pose to selected Protocol-Server - // - // Free-track - if (selectedClient == FREE_TRACK) { - server_Game->setHeadRotX( output_camera.position.pitch ); // degrees - server_Game->setHeadRotY( output_camera.position.yaw ); - server_Game->setHeadRotZ( output_camera.position.roll ); - - server_Game->setHeadPosX( output_camera.position.x ); // centimeters - server_Game->setHeadPosY( output_camera.position.y ); - server_Game->setHeadPosZ( output_camera.position.z ); - } - - // All Protocol server(s) - if (server_Game) { - server_Game->setVirtRotX ( output_camera.position.pitch ); // degrees - server_Game->setVirtRotY ( output_camera.position.yaw ); - server_Game->setVirtRotZ ( output_camera.position.roll ); - server_Game->setVirtPosX ( output_camera.position.x ); // centimeters - server_Game->setVirtPosY ( output_camera.position.y ); - server_Game->setVirtPosZ ( output_camera.position.z ); - } - // All Protocol server(s) if (pProtocol) { pProtocol->sendHeadposeToGame( &output_camera ); // degrees & centimeters } -// headRotXLine->setText(QString("%1").arg( new_camera.position.pitch, 0, 'f', 1)); // show degrees -// headRotYLine->setText(QString("%1").arg( new_camera.position.yaw, 0, 'f', 1)); -// headRotZLine->setText(QString("%1").arg( new_camera.position.roll, 0, 'f', 1)); -// -//// headXLine->setText(QString("%1").arg( new_camera.position.x, 0, 'f', 1)); // show centimeters -// headYLine->setText(QString("%1").arg( new_camera.position.y, 0, 'f', 1)); -// headZLine->setText(QString("%1").arg( new_camera.position.z, 0, 'f', 1)); - - # ifdef USE_DEBUG_CLIENT debug_Client->setHeadRotX( Tracker::Pitch.headPos ); // degrees debug_Client->setHeadRotY( Tracker::Yaw.headPos ); @@ -682,13 +618,14 @@ void Tracker::run() { // // Go to initial position // - if (server_Game && setZero) { - server_Game->setVirtRotX ( 0.0f ); - server_Game->setVirtRotY ( 0.0f ); - server_Game->setVirtRotZ ( 0.0f ); - server_Game->setVirtPosX ( 0.0f ); - server_Game->setVirtPosY ( 0.0f ); - server_Game->setVirtPosZ ( 0.0f ); + if (pProtocol && setZero) { + output_camera.position.pitch = 0.0f; + output_camera.position.yaw = 0.0f; + output_camera.position.roll = 0.0f; + output_camera.position.x = 0.0f; + output_camera.position.y = 0.0f; + output_camera.position.z = 0.0f; + pProtocol->sendHeadposeToGame( &output_camera ); // degrees & centimeters } } } @@ -705,7 +642,6 @@ void Tracker::run() { Tracker::Pitch.newSample = false; ReleaseMutex(Tracker::hTrackMutex); - server_Game->sendHeadposeToGame(); //for lower cpu load usleep(10000); @@ -749,7 +685,8 @@ void Tracker::addHeadPose( THeadPoseData head_pose ) QString Tracker::getGameProgramName() { QString str; - str = server_Game->GetProgramName(); +// str = server_Game->GetProgramName(); + str = QString(""); return str; } @@ -1100,6 +1037,13 @@ QPointF point1, point2, point3, point4; InhibitKey.doY = iniFile.value ( "Inhibit_Y", 0 ).toBool(); InhibitKey.doZ = iniFile.value ( "Inhibit_Z", 0 ).toBool(); + // Axis Reverse key + AxisReverseKey.keycode = DIK_R; + AxisReverseKey.shift = false; + AxisReverseKey.ctrl = false; + AxisReverseKey.alt = false; + + iniFile.endGroup (); } diff --git a/FaceTrackNoIR/tracker.h b/FaceTrackNoIR/tracker.h index 3440495f..a46bfa2e 100644 --- a/FaceTrackNoIR/tracker.h +++ b/FaceTrackNoIR/tracker.h @@ -35,14 +35,7 @@ #define DIRECTINPUT_VERSION 0x0800 #include -//#include "FTServer.h" // Freetrack-server -//#include "FGServer.h" // FlightGear-server -//#include "PPJoyServer.h" // Virtual Joystick -//#include "FTIRServer.h" // FakeTIR-server -#include "SCServer.h" // SimConnect-server (for MS Flight Simulator X) -#include "FSUIPCServer.h" // FSUIPC-server (for MS Flight Simulator 2004) #include "ExcelServer.h" // Excel-server (for analysing purposes) -#include "FTNServer.h" // FaceTrackNoIR-server (for client-server) #include "FTNoIR_cxx_protocolserver.h" #include "..\ftnoir_tracker_base\FTNoIR_Tracker_base.h" @@ -88,6 +81,11 @@ enum FTNoIR_Face_Tracker { FT_FTNOIR = 1 }; +enum FTNoIR_Tracker_Status { + TRACKER_OFF = 0, + TRACKER_ON = 1 +}; + class FaceTrackNoIR; // pre-define parent-class to avoid circular includes // @@ -179,13 +177,15 @@ private: static TShortKey CenterKey; // ShortKey to Center headposition static TShortKey StartStopKey; // ShortKey to Start/stop tracking - static TShortKey InhibitKey; // ShortKey to one or more axis during tracking + static TShortKey InhibitKey; // ShortKey to disable one or more axis during tracking + static TShortKey AxisReverseKey; // ShortKey to reverse axis during tracking // Flags to start/stop/reset tracking static bool confid; // Tracker data is OK static bool do_tracking; // Start/stop tracking, using the shortkey static bool do_center; // Center head-position, using the shortkey static bool do_inhibit; // Inhibit DOF-axis, using the shortkey + static bool do_axis_reverse; // Axis reverse, using the shortkey static HANDLE hTrackMutex; // Prevent reading/writing the headpose simultaneously @@ -195,7 +195,6 @@ private: FaceTrackNoIR *mainApp; - QSharedPointer server_Game; // Protocol Server to communicate headpose-data to the Game! QSharedPointer debug_Client; // Protocol Server to log debug-data protected: @@ -214,7 +213,8 @@ public: void loadSettings(); // Load settings from the INI-file bool isShortKeyPressed( TShortKey *key, BYTE *keystate ); -// QSharedPointer getEngine() { return _engine; }; + static bool getTrackingActive() { return do_tracking; } + static bool getAxisReverse() { return do_axis_reverse; } static bool getConfid() { return confid; } -- cgit v1.2.3