From f3e5ceffbceaf6f9931ad2ac6bad69732d37dd4c Mon Sep 17 00:00:00 2001 From: Wim Vriend Date: Sat, 23 Oct 2010 15:36:16 +0000 Subject: Built in support of TIRViews. Older games like CFS3 require this to be in the program-folder. git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@25 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb --- FaceTrackNoIR.suo | Bin 268288 -> 268288 bytes FaceTrackNoIR/FTIRServer.cpp | 192 +++++++++++++++++++++++++++-- FaceTrackNoIR/FTIRServer.h | 35 +++++- FaceTrackNoIR/FTIRTypes.h | 15 +-- FaceTrackNoIR/FTNoIR_FSUIPCcontrols.ui | 217 +++++++++++++++++++++++++++++++++ FaceTrackNoIR/FTNoIR_FTIRcontrols.ui | 194 +++++++++++++++++++++++++++++ FaceTrackNoIR/FTServer.cpp | 1 + FaceTrackNoIR/FaceTrackNoIR.cpp | 17 ++- FaceTrackNoIR/FaceTrackNoIR.ui | 5 +- FaceTrackNoIR/FaceTrackNoIR.vcproj | 30 +++++ FaceTrackNoIR/tracker.cpp | 13 +- List of compatible games.xls | Bin 0 -> 21504 bytes List of compatible webcams.xls | Bin 0 -> 19456 bytes bin/FaceTrackNoIR.exe | Bin 655360 -> 667648 bytes bin/TIRViews.dll | Bin 0 -> 109568 bytes 15 files changed, 677 insertions(+), 42 deletions(-) create mode 100644 FaceTrackNoIR/FTNoIR_FSUIPCcontrols.ui create mode 100644 FaceTrackNoIR/FTNoIR_FTIRcontrols.ui create mode 100644 List of compatible games.xls create mode 100644 List of compatible webcams.xls create mode 100644 bin/TIRViews.dll diff --git a/FaceTrackNoIR.suo b/FaceTrackNoIR.suo index 0989d334..b3bb6fca 100644 Binary files a/FaceTrackNoIR.suo and b/FaceTrackNoIR.suo differ diff --git a/FaceTrackNoIR/FTIRServer.cpp b/FaceTrackNoIR/FTIRServer.cpp index a3298ace..1de4ee87 100644 --- a/FaceTrackNoIR/FTIRServer.cpp +++ b/FaceTrackNoIR/FTIRServer.cpp @@ -21,6 +21,7 @@ ********************************************************************************/ /* Modifications (last one on top): + 20101023 - WVR: Added TIRViews for FS2004, Combat FS3, etc... */ #include "FTIRServer.h" @@ -40,6 +41,7 @@ FTIRServer::FTIRServer() { m_StopThread = CreateEvent(0, TRUE, FALSE, 0); m_WaitThread = CreateEvent(0, TRUE, FALSE, 0); + loadSettings(); ProgramName = ""; } @@ -57,9 +59,10 @@ FTIRServer::~FTIRServer() { ::CloseHandle(m_WaitThread); // - // Free the DLL + // Free the DLL's // FTIRClientLib.unload(); + FTIRViewsLib.unload(); //terminates the QThread and waits for finishing the QThread terminate(); @@ -68,7 +71,9 @@ FTIRServer::~FTIRServer() { /** QThread run @override **/ void FTIRServer::run() { - importSetPosition setposition; + importSetPosition setposition; // Inside NPClient.dll + importTIRViewsStart viewsStart = NULL; // Inside TIRViews.dll + importTIRViewsStop viewsStop = NULL; // // Get the setposition function from the DLL and use it! @@ -82,11 +87,40 @@ void FTIRServer::run() { setposition (7.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f); } + // + // Load the Start function from TIRViews.dll and call it, to start compatibility with older games + // + if (useTIRViews) { + viewsStart = (importTIRViewsStart) FTIRViewsLib.resolve("TIRViewsStart"); + if (viewsStart == NULL) { + qDebug() << "FTIRServer::run() says: TIRViewsStart function not found in DLL!"; + } + else { + qDebug() << "FTIRServer::run() says: TIRViewsStart executed!"; + viewsStart(); + } + + // + // Load the Stop function from TIRViews.dll. Call it when terminating the thread. + // + viewsStop = (importTIRViewsStop) FTIRViewsLib.resolve("TIRViewsStop"); + if (viewsStop == NULL) { + qDebug() << "FTIRServer::run() says: TIRViewsStop function not found in DLL!"; + } + } + + // + // Run, until termination + // forever { // Check event for stop thread if(::WaitForSingleObject(m_StopThread, 0) == WAIT_OBJECT_0) { + if (viewsStop != NULL) { + viewsStop(); + } + // Set event ::SetEvent(m_WaitThread); return; @@ -224,16 +258,22 @@ bool FTIRServer::FTIRCheckClientDLL() // FTIRClientLib.setFileName(aFileName); FTIRClientLib.load(); - //provider = (importProvider) FTIRClientLib.resolve("FTProvider"); - //if (provider) { - // pProvider = provider(); - // qDebug() << "FTCheckClientDLL says: Provider =" << pProvider; - //} } else { QMessageBox::information(0, "FaceTrackNoIR error", QString("Necessary file (NPClient.dll) was NOT found!\n")); return false; } + + // + // Also load TIRViews.dll, to support some older games + // + if (useTIRViews) { + aFileName = aLocation; + aFileName.append(FTIR_VIEWS_FILENAME); + FTIRViewsLib.setFileName(aFileName); + FTIRViewsLib.load(); + } + } catch(...) { settings.~QSettings(); } @@ -259,4 +299,142 @@ double local_x; return (float) y; } +// +// Load the current Settings from the currently 'active' INI-file. +// +void FTIRServer::loadSettings() { + + QSettings settings("Abbequerque Inc.", "FaceTrackNoIR"); // Registry settings (in HK_USER) + + QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/Settings/default.ini" ).toString(); + QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) + + iniFile.beginGroup ( "FTIR" ); + useTIRViews = iniFile.value ( "useTIRViews", 0 ).toBool(); + iniFile.endGroup (); +} + +// +// Constructor for server-settings-dialog +// +FTIRControls::FTIRControls( QWidget *parent, Qt::WindowFlags f ) : +QWidget( parent , f) +{ + QString aFileName; // File Path and Name + + ui.setupUi( this ); + + QPoint offsetpos(100, 100); + this->move(parent->pos() + offsetpos); + + // Connect Qt signals to member-functions + connect(ui.btnOK, SIGNAL(clicked()), this, SLOT(doOK())); + connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(doCancel())); + connect(ui.chkTIRViews, SIGNAL(stateChanged(int)), this, SLOT(chkTIRViewsChanged())); + + aFileName = QCoreApplication::applicationDirPath() + "/"; + aFileName.append(FTIR_VIEWS_FILENAME); + if ( !QFile::exists( aFileName ) ) { + ui.chkTIRViews->setChecked( false ); + ui.chkTIRViews->setEnabled ( false ); + } + else { + ui.chkTIRViews->setEnabled ( true ); + } + + // Load the settings from the current .INI-file + loadSettings(); +} + +// +// Destructor for server-dialog +// +FTIRControls::~FTIRControls() { + qDebug() << "~FTIRControls() says: started"; +} + +// +// OK clicked on server-dialog +// +void FTIRControls::doOK() { + save(); + this->close(); +} + +// override show event +void FTIRControls::showEvent ( QShowEvent * event ) { + loadSettings(); +} + +// +// Cancel clicked on server-dialog +// +void FTIRControls::doCancel() { + // + // Ask if changed Settings should be saved + // + if (settingsDirty) { + int ret = QMessageBox::question ( this, "Settings have changed", "Do you want to save the settings?", QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard ); + + qDebug() << "doCancel says: answer =" << ret; + + switch (ret) { + case QMessageBox::Save: + save(); + this->close(); + break; + case QMessageBox::Discard: + this->close(); + break; + case QMessageBox::Cancel: + // Cancel was clicked + break; + default: + // should never be reached + break; + } + } + else { + this->close(); + } +} + +// +// Load the current Settings from the currently 'active' INI-file. +// +void FTIRControls::loadSettings() { + + qDebug() << "loadSettings says: Starting "; + QSettings settings("Abbequerque Inc.", "FaceTrackNoIR"); // Registry settings (in HK_USER) + + QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/Settings/default.ini" ).toString(); + QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) + + qDebug() << "loadSettings says: iniFile = " << currentFile; + + iniFile.beginGroup ( "FTIR" ); + ui.chkTIRViews->setChecked (iniFile.value ( "useTIRViews", 0 ).toBool()); + iniFile.endGroup (); + + settingsDirty = false; + +} + +// +// Save the current Settings to the currently 'active' INI-file. +// +void FTIRControls::save() { + + QSettings settings("Abbequerque Inc.", "FaceTrackNoIR"); // Registry settings (in HK_USER) + + QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/Settings/default.ini" ).toString(); + QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) + + iniFile.beginGroup ( "FTIR" ); + iniFile.setValue ( "useTIRViews", ui.chkTIRViews->isChecked() ); + iniFile.endGroup (); + + settingsDirty = false; +} + //END diff --git a/FaceTrackNoIR/FTIRServer.h b/FaceTrackNoIR/FTIRServer.h index 503514ec..8585b30f 100644 --- a/FaceTrackNoIR/FTIRServer.h +++ b/FaceTrackNoIR/FTIRServer.h @@ -23,7 +23,6 @@ #ifndef INCLUDED_FTIRSERVER_H #define INCLUDED_FTIRSERVER_H -//#include "Windows.h" #include "FTIRTypes.h" #include #include @@ -37,8 +36,10 @@ #include typedef void (WINAPI *importSetPosition)(float x, float y, float z, float xRot, float yRot, float zRot); -//typedef bool (WINAPI *importGetData)(TFreeTrackData * data); -//typedef HANDLE (WINAPI *importGetMapHandle)(void); +typedef void (WINAPI *importTIRViewsStart)(void); +typedef void (WINAPI *importTIRViewsStop)(void); + +#include "ui_FTNoIR_FTIRcontrols.h" using namespace std; @@ -71,7 +72,11 @@ private: // Private properties QString ProgramName; QLibrary FTIRClientLib; + QLibrary FTIRViewsLib; + bool useTIRViews; + static float scale2AnalogLimits( float x, float min_x, float max_x ); + void loadSettings(); public: @@ -94,6 +99,30 @@ public: }; +// Widget that has controls for FTIR server-settings. +class FTIRControls: public QWidget, public Ui::UICFTIRControls +{ + Q_OBJECT +public: + + explicit FTIRControls( QWidget *parent=0, Qt::WindowFlags f=0 ); + virtual ~FTIRControls(); + void showEvent ( QShowEvent * event ); + +private: + Ui::UICFTIRControls ui; + void loadSettings(); + void save(); + + /** helper **/ + bool settingsDirty; + +private slots: + void doOK(); + void doCancel(); + void chkTIRViewsChanged() { settingsDirty = true; }; +}; + #endif//INCLUDED_FTIRSERVER_H //END diff --git a/FaceTrackNoIR/FTIRTypes.h b/FaceTrackNoIR/FTIRTypes.h index 6402245e..bd19769b 100644 --- a/FaceTrackNoIR/FTIRTypes.h +++ b/FaceTrackNoIR/FTIRTypes.h @@ -28,8 +28,6 @@ #include #include -//#include "Registry.h" - // // Versioning hasn't been worked out yet... // @@ -92,13 +90,10 @@ typedef enum tagNPResult NP_ERR_INTERNAL_DATA } NPRESULT; -// static const char* FTIR_CLIENT_LOCATION = "Software\\NaturalPoint\\NATURALPOINT\\NPClient Location"; static const char* FTIR_CLIENT_FILENAME = "NPClient.dll"; + static const char* FTIR_VIEWS_FILENAME = "TIRViews.dll"; static const char* FTIR_MM_DATA = "{0F98177E-0E5C-4F86-8837-229D19B1701D}"; -// static const char* FTIR_MM_DATA = "FT_TIR_SharedMem"; -// static const char* FREETRACK = "Freetrack"; static const char* FTIR_MUTEX = "FT_TIR_Mutex"; -// static const char* FT_PROGRAMID = "FT_ProgramID"; static const char* FTIR_REGISTER_PROGRAMHANDLE = "FT_Register_Program_Handle"; static const char* FTIR_UNREGISTER_PROGRAMHANDLE = "FT_UnRegister_Program_Handle"; @@ -123,14 +118,6 @@ typedef struct tagTrackIRData float fNPSmoothX; float fNPSmoothY; float fNPSmoothZ; - - //// unsigned short wError; - //// short iFrame; - //// unsigned short wUnknown3; - ////float xRot, yRot, zRot; - //// float x,y,z; - ////int iPadding[9]; - } TRACKIRDATA, *LPTRACKIRDATA; struct FTIRMemMap { diff --git a/FaceTrackNoIR/FTNoIR_FSUIPCcontrols.ui b/FaceTrackNoIR/FTNoIR_FSUIPCcontrols.ui new file mode 100644 index 00000000..7dc627b0 --- /dev/null +++ b/FaceTrackNoIR/FTNoIR_FSUIPCcontrols.ui @@ -0,0 +1,217 @@ + + + UICFSUIPCControls + + + + 0 + 0 + 541 + 127 + + + + FSUIPC settings FaceTrackNoIR + + + + images/FaceTrackNoIR.icoimages/FaceTrackNoIR.ico + + + Qt::LeftToRight + + + false + + + + + + + + + 0 + 0 + + + + Location of FSUIPC.dll: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 230 + 0 + + + + Location of FSUIPC.dll + + + QFrame::Box + + + QFrame::Sunken + + + 1 + + + Location of FSUIPC.dll + + + + + + + + 35 + 16777215 + + + + ... + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + OK + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + Cancel + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + + + + + + + startEngineClicked() + stopEngineClicked() + cameraSettingsClicked() + + diff --git a/FaceTrackNoIR/FTNoIR_FTIRcontrols.ui b/FaceTrackNoIR/FTNoIR_FTIRcontrols.ui new file mode 100644 index 00000000..a2d06d2a --- /dev/null +++ b/FaceTrackNoIR/FTNoIR_FTIRcontrols.ui @@ -0,0 +1,194 @@ + + + UICFTIRControls + + + + 0 + 0 + 411 + 157 + + + + FTIR settings FaceTrackNoIR + + + + images/FaceTrackNoIR.icoimages/FaceTrackNoIR.ico + + + Qt::LeftToRight + + + false + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::RightToLeft + + + Use TIRViews + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + TIRViews is only required for some older games (like CFS3). + + + + + + + For it to work, TIRViews.dll must be placed in the FaceTrackNoIR program folder. + + + true + + + + + + + If the checkbox is disabled, the DLL was not found. + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + OK + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + Cancel + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + + + + + + + startEngineClicked() + stopEngineClicked() + cameraSettingsClicked() + + diff --git a/FaceTrackNoIR/FTServer.cpp b/FaceTrackNoIR/FTServer.cpp index ff273cc3..2bd3d5f5 100644 --- a/FaceTrackNoIR/FTServer.cpp +++ b/FaceTrackNoIR/FTServer.cpp @@ -30,6 +30,7 @@ // // The FaceAPI only runs in the 'Release' configuration. It may have something to // do with compiler-settings, but for now it's not solved... +// --> WVR 20101023: This was solved by downgrading to VS2005... // // Connecting with the Freetrack DLL only seems to work, when UNICODE is OFF. // That's strange, isn't it? diff --git a/FaceTrackNoIR/FaceTrackNoIR.cpp b/FaceTrackNoIR/FaceTrackNoIR.cpp index ffa38344..3f3d3018 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.cpp +++ b/FaceTrackNoIR/FaceTrackNoIR.cpp @@ -26,6 +26,7 @@ #include "tracker.h" #include "PPJoyServer.h" #include "FSUIPCServer.h" +#include "FTIRServer.h" using namespace sm::faceapi; using namespace sm::faceapi::qt; @@ -661,7 +662,6 @@ void FaceTrackNoIR::showServerControls() { case FREE_TRACK: case FLIGHTGEAR: case FTNOIR: - case TRACKIR: case SIMCONNECT: break; case PPJOY: @@ -670,6 +670,9 @@ void FaceTrackNoIR::showServerControls() { case FSUIPC: _server_controls = new FSUIPCControls( this, Qt::Dialog ); break; + case TRACKIR: + _server_controls = new FTIRControls( this, Qt::Dialog ); + break; default: break; } @@ -757,16 +760,16 @@ void FaceTrackNoIR::createIconGroupBox() // void FaceTrackNoIR::createActions() { - minimizeAction = new QAction(tr("Mi&nimize"), this); + minimizeAction = new QAction(tr("Mi&nimize FaceTrackNoIR"), this); connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide())); //maximizeAction = new QAction(tr("Ma&ximize"), this); //connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized())); - restoreAction = new QAction(tr("&Restore"), this); + restoreAction = new QAction(tr("&Restore FaceTrackNoIR"), this); connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal())); - quitAction = new QAction(tr("&Quit"), this); + quitAction = new QAction(tr("&Quit FaceTrackNoIR"), this); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); } @@ -810,16 +813,12 @@ void FaceTrackNoIR::setIcon(int index) case FREE_TRACK: case FLIGHTGEAR: case FTNOIR: - case TRACKIR: case SIMCONNECT: ui.btnShowServerControls->hide(); break; case PPJOY: - ui.btnShowServerControls->show(); - ui.btnShowServerControls->setEnabled ( true ); - break; - case FSUIPC: + case TRACKIR: ui.btnShowServerControls->show(); ui.btnShowServerControls->setEnabled ( true ); break; diff --git a/FaceTrackNoIR/FaceTrackNoIR.ui b/FaceTrackNoIR/FaceTrackNoIR.ui index 042a11b9..3ef87463 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.ui +++ b/FaceTrackNoIR/FaceTrackNoIR.ui @@ -934,7 +934,7 @@ color:#000; - Change tracker settings + Change game protocol settings @@ -947,6 +947,9 @@ color:#000; + + Edit the Curve settings + Curves diff --git a/FaceTrackNoIR/FaceTrackNoIR.vcproj b/FaceTrackNoIR/FaceTrackNoIR.vcproj index ae73dc1c..417ebb20 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.vcproj +++ b/FaceTrackNoIR/FaceTrackNoIR.vcproj @@ -577,6 +577,32 @@ /> + + + + + + + + @@ -714,6 +740,10 @@ RelativePath=".\GeneratedFiles\ui_FTNoIR_FSUIPCcontrols.h" > + + diff --git a/FaceTrackNoIR/tracker.cpp b/FaceTrackNoIR/tracker.cpp index 374b45b2..4c6d619b 100644 --- a/FaceTrackNoIR/tracker.cpp +++ b/FaceTrackNoIR/tracker.cpp @@ -262,7 +262,7 @@ void Tracker::setup(QWidget *head, FaceTrackNoIR *parent) { server_FSUIPC->start(); // Start the thread } else { - QMessageBox::information(mainApp, "FaceTrackNoIR error", "FSUIPC is not (correctly) installed!"); + QMessageBox::information(mainApp, "FaceTrackNoIR error", "FSUIPC is not (correctly) installed!\nIt should be placed in the Modules folder of FS!"); } } @@ -340,13 +340,7 @@ void Tracker::run() { } else { // - // Check the state of the BACK key (= Start/Stop tracking) and EQUALS key (= Center) - // - if ( isShortKeyPressed( &CenterKey, &keystate[0] ) ) { - qDebug() << "Tracker::run Shortkey Center pressed!" << GetLastError(); - } - // - // Check the state of the BACK key (= Start/Stop tracking) and EQUALS key (= Center) + // Check the state of the Start/Stop key // if ( isShortKeyPressed( &StartStopKey, &keystate[0] ) && (!lastBackKey) ) { Tracker::do_tracking = !Tracker::do_tracking; @@ -382,6 +376,9 @@ void Tracker::run() { } lastBackKey = isShortKeyPressed( &StartStopKey, &keystate[0] ); // Remember + // + // Check the state of the Center key + // if ( isShortKeyPressed( &CenterKey, &keystate[0] ) && (!lastEqualsKey) ) { Tracker::do_center = true; qDebug() << "Tracker::run() says Center pressed"; diff --git a/List of compatible games.xls b/List of compatible games.xls new file mode 100644 index 00000000..8aecccd9 Binary files /dev/null and b/List of compatible games.xls differ diff --git a/List of compatible webcams.xls b/List of compatible webcams.xls new file mode 100644 index 00000000..4e704e3c Binary files /dev/null and b/List of compatible webcams.xls differ diff --git a/bin/FaceTrackNoIR.exe b/bin/FaceTrackNoIR.exe index 46ab694a..c8ae7003 100644 Binary files a/bin/FaceTrackNoIR.exe and b/bin/FaceTrackNoIR.exe differ diff --git a/bin/TIRViews.dll b/bin/TIRViews.dll new file mode 100644 index 00000000..a1fb306f Binary files /dev/null and b/bin/TIRViews.dll differ -- cgit v1.2.3