From 16fc21fdc3d849de801064b06c507cb504ae314c Mon Sep 17 00:00:00 2001 From: Wim Vriend Date: Tue, 26 Apr 2011 19:15:59 +0000 Subject: Start on Mouse Look git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@76 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb --- FaceTrackNoIR/FTNoIR_KeyboardShortcuts.ui | 131 +++++++++++++++++++++++------- FaceTrackNoIR/FaceTrackNoIR.cpp | 49 ++++++++--- FaceTrackNoIR/FaceTrackNoIR.qrc | 31 ++++--- FaceTrackNoIR/FaceTrackNoIR.ui | 2 +- FaceTrackNoIR/tracker.cpp | 41 ++++++++-- FaceTrackNoIR/tracker.h | 8 +- 6 files changed, 196 insertions(+), 66 deletions(-) (limited to 'FaceTrackNoIR') diff --git a/FaceTrackNoIR/FTNoIR_KeyboardShortcuts.ui b/FaceTrackNoIR/FTNoIR_KeyboardShortcuts.ui index 3a8b98a8..2de9eede 100644 --- a/FaceTrackNoIR/FTNoIR_KeyboardShortcuts.ui +++ b/FaceTrackNoIR/FTNoIR_KeyboardShortcuts.ui @@ -7,7 +7,7 @@ 0 0 558 - 270 + 308 @@ -28,14 +28,14 @@ - + Disables: - + When OFF: @@ -58,7 +58,7 @@ - + Axis Inhibitor @@ -78,7 +78,7 @@ - + @@ -91,7 +91,7 @@ - + @@ -117,7 +117,7 @@ - + @@ -130,7 +130,7 @@ - + @@ -143,20 +143,7 @@ - - - - - 50 - 16777215 - - - - Alt - - - - + @@ -169,7 +156,7 @@ - + @@ -198,7 +185,7 @@ - + @@ -208,7 +195,7 @@ - + @@ -218,7 +205,7 @@ - + @@ -291,7 +278,7 @@ - + @@ -333,7 +320,7 @@ - + Start/stop @@ -343,7 +330,7 @@ - + color: rgb(0, 0, 0); @@ -410,7 +397,7 @@ - + @@ -452,6 +439,90 @@ + + + + + 0 + 0 + + + + Game Zero + + + false + + + + + + + + 50 + 16777215 + + + + Shift + + + + + + + + 50 + 16777215 + + + + Ctrl + + + + + + + + 50 + 16777215 + + + + Alt + + + + + + + + 50 + 16777215 + + + + Alt + + + + + + + + 90 + 0 + + + + Select Number + + + QComboBox::InsertAlphabetically + + + diff --git a/FaceTrackNoIR/FaceTrackNoIR.cpp b/FaceTrackNoIR/FaceTrackNoIR.cpp index 8646c248..79c3969b 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.cpp +++ b/FaceTrackNoIR/FaceTrackNoIR.cpp @@ -852,6 +852,10 @@ QString libName; libName = QString("FTNoIR_Protocol_FTN.dll"); break; + case MOUSE: + libName = QString("FTNoIR_Protocol_MOUSE.dll"); + break; + default: break; } @@ -939,16 +943,17 @@ void FaceTrackNoIR::exit() { // void FaceTrackNoIR::createIconGroupBox() { - ui.iconcomboBox->addItem(QIcon(QCoreApplication::applicationDirPath() + "/images/Freetrack.ico"), tr("Freetrack")); - ui.iconcomboBox->addItem(QIcon(QCoreApplication::applicationDirPath() + "/images/FlightGear.ico"), tr("FlightGear")); - ui.iconcomboBox->addItem(QIcon(QCoreApplication::applicationDirPath() + "/images/FaceTrackNoIR.ico"), tr("FTNoir client")); - ui.iconcomboBox->addItem(QIcon(QCoreApplication::applicationDirPath() + "/images/PPJoy.ico"), tr("Virtual Joystick")); - ui.iconcomboBox->addItem(QIcon(QCoreApplication::applicationDirPath() + "/images/TrackIR.ico"), tr("Fake TrackIR")); - ui.iconcomboBox->addItem(QIcon(QCoreApplication::applicationDirPath() + "/images/FSX.ico"), tr("SimConnect (FSX)")); - ui.iconcomboBox->addItem(QIcon(QCoreApplication::applicationDirPath() + "/images/FS9.ico"), tr("FS2002/FS2004")); + ui.iconcomboBox->addItem(QIcon(":/images/Freetrack.ico"), tr("Freetrack")); + ui.iconcomboBox->addItem(QIcon(":/images/FlightGear.ico"), tr("FlightGear")); + ui.iconcomboBox->addItem(QIcon(":/images/FaceTrackNoIR.ico"), tr("FTNoir client")); + ui.iconcomboBox->addItem(QIcon(":/images/PPJoy.ico"), tr("Virtual Joystick")); + ui.iconcomboBox->addItem(QIcon(":/images/TrackIR.ico"), tr("Fake TrackIR")); + ui.iconcomboBox->addItem(QIcon(":/images/FSX.ico"), tr("SimConnect (FSX)")); + ui.iconcomboBox->addItem(QIcon(":/images/FS9.ico"), tr("FS2002/FS2004")); + ui.iconcomboBox->addItem(QIcon(":/images/Mouse.ico"), tr("Mouse look")); - ui.iconcomboTrackerSource->addItem(QIcon(QCoreApplication::applicationDirPath() + "/images/SeeingMachines.ico"), tr("Face API")); - ui.iconcomboTrackerSource->addItem(QIcon(QCoreApplication::applicationDirPath() + "/images/FaceTrackNoIR.ico"), tr("FTNoir server")); + ui.iconcomboTrackerSource->addItem(QIcon(":/images/SeeingMachines.ico"), tr("Face API")); + ui.iconcomboTrackerSource->addItem(QIcon(":/images/FaceTrackNoIR.ico"), tr("FTNoir server")); } // @@ -1000,7 +1005,7 @@ void FaceTrackNoIR::setIcon(int index) trayIcon->show(); trayIcon->showMessage( "FaceTrackNoIR", ui.iconcomboBox->itemText(index)); } - setWindowIcon(QIcon(QCoreApplication::applicationDirPath() + "/images/FaceTrackNoIR.ico")); + setWindowIcon(QIcon(":/images/FaceTrackNoIR.ico")); ui.btnShowServerControls->setIcon(icon); settingsDirty = true; @@ -1016,6 +1021,7 @@ void FaceTrackNoIR::setIcon(int index) case TRACKIR: case FLIGHTGEAR: case FTNOIR: + case MOUSE: ui.btnShowServerControls->show(); ui.btnShowServerControls->setEnabled ( true ); break; @@ -1219,6 +1225,11 @@ QWidget( parent , f) connect(ui.chkCenterCtrl, SIGNAL(stateChanged(int)), this, SLOT(keyChanged(int))); connect(ui.chkCenterAlt, SIGNAL(stateChanged(int)), this, SLOT(keyChanged(int))); + connect(ui.cbxGameZeroKey, SIGNAL(currentIndexChanged(int)), this, SLOT(keyChanged( int ))); + connect(ui.chkGameZeroShift, SIGNAL(stateChanged(int)), this, SLOT(keyChanged(int))); + connect(ui.chkGameZeroCtrl, SIGNAL(stateChanged(int)), this, SLOT(keyChanged(int))); + connect(ui.chkGameZeroAlt, SIGNAL(stateChanged(int)), this, SLOT(keyChanged(int))); + connect(ui.cbxStartStopKey, SIGNAL(currentIndexChanged(int)), this, SLOT(keyChanged( int ))); connect(ui.chkStartStopShift, SIGNAL(stateChanged(int)), this, SLOT(keyChanged(int))); connect(ui.chkStartStopCtrl, SIGNAL(stateChanged(int)), this, SLOT(keyChanged(int))); @@ -1376,6 +1387,7 @@ QWidget( parent , f) // for ( int i = 0; i < stringList.size(); i++) { ui.cbxCenterKey->addItem(stringList.at(i)); + ui.cbxGameZeroKey->addItem(stringList.at(i)); ui.cbxStartStopKey->addItem(stringList.at(i)); ui.cbxInhibitKey->addItem(stringList.at(i)); } @@ -1465,6 +1477,18 @@ int keyindex; ui.chkCenterCtrl->setChecked (iniFile.value ( "Ctrl_Center", 0 ).toBool()); ui.chkCenterAlt->setChecked (iniFile.value ( "Alt_Center", 0 ).toBool()); + // GameZero key + keyindex = keyList.indexOf ( iniFile.value ( "Keycode_GameZero", 1 ).toInt() ); + if ( keyindex > 0 ) { + ui.cbxGameZeroKey->setCurrentIndex( keyindex ); + } + else { + ui.cbxGameZeroKey->setCurrentIndex( 0 ); + } + ui.chkGameZeroShift->setChecked (iniFile.value ( "Shift_GameZero", 0 ).toBool()); + ui.chkGameZeroCtrl->setChecked (iniFile.value ( "Ctrl_GameZero", 0 ).toBool()); + ui.chkGameZeroAlt->setChecked (iniFile.value ( "Alt_GameZero", 0 ).toBool()); + // Start/stop key keyindex = keyList.indexOf ( iniFile.value ( "Keycode_StartStop", 1 ).toInt() ); if ( keyindex > 0 ) { @@ -1524,6 +1548,11 @@ void KeyboardShortcutDialog::save() { iniFile.setValue ( "Ctrl_Center", ui.chkCenterCtrl->isChecked() ); iniFile.setValue ( "Alt_Center", ui.chkCenterAlt->isChecked() ); + iniFile.setValue ( "Keycode_GameZero", keyList.at( ui.cbxGameZeroKey->currentIndex() ) ); + iniFile.setValue ( "Shift_GameZero", ui.chkGameZeroShift->isChecked() ); + iniFile.setValue ( "Ctrl_GameZero", ui.chkGameZeroCtrl->isChecked() ); + iniFile.setValue ( "Alt_GameZero", ui.chkGameZeroAlt->isChecked() ); + iniFile.setValue ( "Keycode_StartStop", keyList.at( ui.cbxStartStopKey->currentIndex() ) ); iniFile.setValue ( "Shift_StartStop", ui.chkStartStopShift->isChecked() ); iniFile.setValue ( "Ctrl_StartStop", ui.chkStartStopCtrl->isChecked() ); diff --git a/FaceTrackNoIR/FaceTrackNoIR.qrc b/FaceTrackNoIR/FaceTrackNoIR.qrc index 17aa1be6..10cdcd14 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.qrc +++ b/FaceTrackNoIR/FaceTrackNoIR.qrc @@ -1,15 +1,20 @@ - - images/Settings16.png - images/SettingsOpen16.png - UIElements/Donate.png - UIElements/Curves.png - images/rotation_DOFs.png - images/translation_DOFs.png - images/FlightGear.ico - images/330px-6DOF_en.png - images/Freetrack.ico - images/FaceTrackNoIR.ico - images/SeeingMachines.ico - + + images/Settings16.png + images/SettingsOpen16.png + UIElements/Donate.png + UIElements/Curves.png + images/rotation_DOFs.png + images/translation_DOFs.png + images/FlightGear.ico + images/330px-6DOF_en.png + images/Freetrack.ico + images/FaceTrackNoIR.ico + images/SeeingMachines.ico + images/Mouse.ico + images/FS9.ico + images/FSX.ico + images/PPJoy.ico + images/TrackIR.ico + diff --git a/FaceTrackNoIR/FaceTrackNoIR.ui b/FaceTrackNoIR/FaceTrackNoIR.ui index 2cfe5fbc..c4c6b228 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.ui +++ b/FaceTrackNoIR/FaceTrackNoIR.ui @@ -1108,7 +1108,7 @@ color: rgb(0, 255, 0); -1 - 6 + 7 diff --git a/FaceTrackNoIR/tracker.cpp b/FaceTrackNoIR/tracker.cpp index 223d6d28..e88c2634 100644 --- a/FaceTrackNoIR/tracker.cpp +++ b/FaceTrackNoIR/tracker.cpp @@ -66,6 +66,7 @@ bool Tracker::confid = false; bool Tracker::do_tracking = true; bool Tracker::do_center = false; bool Tracker::do_inhibit = false; +bool Tracker::do_game_zero = false; bool Tracker::do_axis_reverse = false; bool Tracker::useFilter = false; @@ -89,6 +90,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::GameZeroKey; // ShortKey to Set Game Zero TShortKey Tracker::AxisReverseKey; // ShortKey to start/stop axis reverse while tracking ITrackerPtr Tracker::pTracker; // Pointer to Tracker instance (in DLL) @@ -332,10 +334,13 @@ HRESULT retAcquire; bool lastCenterKey = false; // Remember state, to detect rising edge bool lastStartStopKey = false; bool lastInhibitKey = false; +bool lastGameZeroKey = false; bool waitAxisReverse = false; bool waitThroughZero = false; double actualYaw = 0.0f; T6DOF offset_camera(0,0,0,0,0,0); +T6DOF gamezero_camera(0,0,0,0,0,0); +T6DOF gameoutput_camera(0,0,0,0,0,0); Tracker::do_center = true; // Center initially @@ -458,6 +463,15 @@ T6DOF offset_camera(0,0,0,0,0,0); } lastCenterKey = isShortKeyPressed( &CenterKey, &keystate[0] ); // Remember + // + // Check the state of the GameZero key + // + if ( isShortKeyPressed( &GameZeroKey, &keystate[0] ) && (!lastGameZeroKey) ) { + Tracker::do_game_zero = true; + qDebug() << "Tracker::run() says GameZero pressed"; + } + lastGameZeroKey = isShortKeyPressed( &GameZeroKey, &keystate[0] ); // Remember + // // Check the state of the Inhibit key // @@ -504,12 +518,6 @@ T6DOF offset_camera(0,0,0,0,0,0); // 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 ); MessageBeep (MB_ICONASTERISK); offset_camera.position.x = getSmoothFromList( &X.rawList ); @@ -522,6 +530,15 @@ T6DOF offset_camera(0,0,0,0,0,0); Tracker::do_center = false; } + // + // If Set Game Zero is pressed, copy the current values to the offsets. + // + if (Tracker::confid && Tracker::do_game_zero) { + gamezero_camera.position = gameoutput_camera.position; + + Tracker::do_game_zero = false; + } + if (Tracker::do_tracking && Tracker::confid) { // Pitch @@ -592,7 +609,8 @@ T6DOF offset_camera(0,0,0,0,0,0); // All Protocol server(s) if (pProtocol) { - pProtocol->sendHeadposeToGame( &output_camera ); // degrees & centimeters + gameoutput_camera = output_camera + gamezero_camera; + pProtocol->sendHeadposeToGame( &gameoutput_camera ); // degrees & centimeters } # ifdef USE_DEBUG_CLIENT @@ -625,7 +643,8 @@ T6DOF offset_camera(0,0,0,0,0,0); output_camera.position.x = 0.0f; output_camera.position.y = 0.0f; output_camera.position.z = 0.0f; - pProtocol->sendHeadposeToGame( &output_camera ); // degrees & centimeters + gameoutput_camera = output_camera + gamezero_camera; + pProtocol->sendHeadposeToGame( &gameoutput_camera ); // degrees & centimeters } } } @@ -1037,6 +1056,12 @@ QPointF point1, point2, point3, point4; InhibitKey.doY = iniFile.value ( "Inhibit_Y", 0 ).toBool(); InhibitKey.doZ = iniFile.value ( "Inhibit_Z", 0 ).toBool(); + // Game Zero key + GameZeroKey.keycode = iniFile.value ( "Keycode_GameZero", 0 ).toInt(); + GameZeroKey.shift = iniFile.value ( "Shift_GameZero", 0 ).toBool(); + GameZeroKey.ctrl = iniFile.value ( "Ctrl_GameZero", 0 ).toBool(); + GameZeroKey.alt = iniFile.value ( "Alt_GameZero", 0 ).toBool(); + // Axis Reverse key AxisReverseKey.keycode = DIK_R; AxisReverseKey.shift = false; diff --git a/FaceTrackNoIR/tracker.h b/FaceTrackNoIR/tracker.h index a46bfa2e..924f5542 100644 --- a/FaceTrackNoIR/tracker.h +++ b/FaceTrackNoIR/tracker.h @@ -73,7 +73,8 @@ enum FTNoIR_Client { PPJOY = 3, TRACKIR = 4, SIMCONNECT = 5, - FSUIPC = 6 + FSUIPC = 6, + MOUSE = 7 }; enum FTNoIR_Face_Tracker { @@ -95,7 +96,6 @@ class THeadPoseDOF { public: void initHeadPoseData(){ headPos = 0.0f; -// initial_headPos = 0.0f; offset_headPos = 0.0f; invert = 0.0f; red = 0.0f; @@ -103,14 +103,12 @@ public: maxItems = 10.0f; prevPos = 0.0f; prevRawPos = 0.0f; -// curve.??? NeutralZone = 0; MaxInput = 0; confidence = 0.0f; newSample = FALSE; } float headPos; // Current position (from faceTracker, radials or meters) -// float initial_headPos; // Position on startup (first valid value) float offset_headPos; // Offset for centering float invert; // Invert measured value (= 1.0f or -1.0f) float red; // Reduction factor (used for EWMA-filtering, between 0.0f and 1.0f) @@ -178,6 +176,7 @@ private: static TShortKey CenterKey; // ShortKey to Center headposition static TShortKey StartStopKey; // ShortKey to Start/stop tracking static TShortKey InhibitKey; // ShortKey to disable one or more axis during tracking + static TShortKey GameZeroKey; // ShortKey to Set Game Zero static TShortKey AxisReverseKey; // ShortKey to reverse axis during tracking // Flags to start/stop/reset tracking @@ -185,6 +184,7 @@ private: 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_game_zero; // Set in-game zero, using the shortkey static bool do_axis_reverse; // Axis reverse, using the shortkey static HANDLE hTrackMutex; // Prevent reading/writing the headpose simultaneously -- cgit v1.2.3