From be9d1d42a340bad458173992b219def3dfed03ae Mon Sep 17 00:00:00 2001 From: Wim Vriend Date: Fri, 15 Oct 2010 15:40:49 +0000 Subject: SimConnect interface toegevoegd voor Microsoft FSX... Werkt al! git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@23 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb --- FaceTrackNoIR.suo | Bin 257536 -> 264192 bytes FaceTrackNoIR/FTNoIR_Curves.ui | 847 +++++++++++++++++++++++++++++++++++++ FaceTrackNoIR/FaceTrackNoIR.aps | Bin 42020 -> 41984 bytes FaceTrackNoIR/FaceTrackNoIR.cpp | 4 + FaceTrackNoIR/FaceTrackNoIR.ui | 375 +++++++++------- FaceTrackNoIR/FaceTrackNoIR.vcproj | 69 ++- FaceTrackNoIR/SCServer.cpp | 203 +++++++++ FaceTrackNoIR/SCServer.h | 99 +++++ FaceTrackNoIR/SCServer.manifest | 13 + FaceTrackNoIR/postbuild.bat | 27 ++ FaceTrackNoIR/tracker.cpp | 113 ++++- FaceTrackNoIR/tracker.h | 21 +- bin/FaceTrackNoIR.exe | Bin 626688 -> 630784 bytes bin/Settings/ArmA.ini | 32 +- bin/Settings/FF5.ini | 25 ++ bin/Settings/GlovePIE.ini | 25 ++ bin/Settings/SimConnect.ini | 28 ++ 17 files changed, 1669 insertions(+), 212 deletions(-) create mode 100644 FaceTrackNoIR/FTNoIR_Curves.ui create mode 100644 FaceTrackNoIR/SCServer.cpp create mode 100644 FaceTrackNoIR/SCServer.h create mode 100644 FaceTrackNoIR/SCServer.manifest create mode 100644 FaceTrackNoIR/postbuild.bat create mode 100644 bin/Settings/FF5.ini create mode 100644 bin/Settings/GlovePIE.ini create mode 100644 bin/Settings/SimConnect.ini diff --git a/FaceTrackNoIR.suo b/FaceTrackNoIR.suo index 98df33d0..cf018c87 100644 Binary files a/FaceTrackNoIR.suo and b/FaceTrackNoIR.suo differ diff --git a/FaceTrackNoIR/FTNoIR_Curves.ui b/FaceTrackNoIR/FTNoIR_Curves.ui new file mode 100644 index 00000000..762ff059 --- /dev/null +++ b/FaceTrackNoIR/FTNoIR_Curves.ui @@ -0,0 +1,847 @@ + + + UICCurveConfigurationDialog + + + + 0 + 0 + 681 + 728 + + + + FaceTrackNoIR tracking curves + + + + images/FaceTrackNoIR.icoimages/FaceTrackNoIR.ico + + + Qt::LeftToRight + + + false + + + /* Customize any plain widget that is a child of a QMainWindow. */ +QMainWindow > .QWidget { +background-color: rgb(100, 100, 100); +} + +/* Set the selection colors for all widgets. */ +QWidget { +selection-color: black; +selection-background-color: Silver; +color: black; +} + +/* Specials for individual widget(s) */ +QWidget#UICCurveConfigurationDialog { +background-color: #484848; +} + +QWidget#tabWidget { +background-color: #595959; +} + +/* +QWidget#widgetTop { +background-color: #595959; +border-bottom: 1px solid #000; +} +*/ + +/* Make text in message boxes selectable. */ +QMessageBox { +/* LinksAccessibleByMouse | TextSelectableByMouse */ +messagebox-text-interaction-flags: 5; +} +/* Make the entire row selected in item views. */ +QAbstractItemView { +show-decoration-selected: 1; +} + +/* Nice WindowsXP-style password character for password line edits. */ +QLineEdit[echoMode="2"] { +lineedit-password-character: 9679; +} + +/* Customize tooltips. */ +QToolTip { +background-color: rgb(170, 255, 127); +opacity: 200; +} + +/* Customize push buttons and comboboxes. Our read-only combobox +is very similar to a push button, so they share the same border image. */ + +QPushButton { +min-width: 4em; +} + +QPushButton:disabled { +color: rgb(128, 128, 128); +} + +QGroupBox { +color: rgb(255, 255, 255); +} + + + + + + + + + + + 1 + + + + + :/images/rotation_DOFs.png:/images/rotation_DOFs.png + + + Rotations + + + + + 10 + 10 + 643 + 627 + + + + + + + 50 + + + 180 + + + + 255 + 170 + 0 + + + + + 192 + 192 + 192 + + + + Input Yaw (degr.) + + + Output Yaw (degr.) + + + Yaw (left and right) + + + + 0.000000000000000 + 0.000000000000000 + + + + + 90.000000000000000 + 0.000000000000000 + + + + + + + + 50 + + + 180 + + + + 0 + 255 + 255 + + + + + 192 + 192 + 192 + + + + Input Pitch (degr.) + + + Output Pitch (degr.) + + + Pitch (forward and backward) + + + + 0.000000000000000 + 0.000000000000000 + + + + + 90.000000000000000 + 0.000000000000000 + + + + + + + + 50 + + + 180 + + + + 0 + 255 + 0 + + + + + 192 + 192 + 192 + + + + Input Roll (degr.) + + + Output Roll (degr.) + + + Roll (left and right) + + + + 0.000000000000000 + 0.000000000000000 + + + + + 90.000000000000000 + 0.000000000000000 + + + + + + + + 50 + + + + + + + NeutralZone + + + + + + + + + + 170 + 140 + + + + + 170 + 140 + + + + image: url(:/images/rotation_DOFs.png); +background-color: rgb(255, 255, 255); + + + + + + + + + NeutralZone + + + + + + + NeutralZone + + + + + + + 50 + + + + + + + 50 + + + + + + + + + + :/images/translation_DOFs.png:/images/translation_DOFs.png + + + Translations + + + + + 10 + 10 + 593 + 633 + + + + + + + 50 + + + 180 + + + + 0 + 0 + 255 + + + + + 192 + 192 + 192 + + + + Input Move (cm) + + + Output Move (cm) + + + Move (up and down) + + + + 0.000000000000000 + 0.000000000000000 + + + + + 90.000000000000000 + 0.000000000000000 + + + + + + + + 50 + + + 180 + + + + 255 + 0 + 0 + + + + + 192 + 192 + 192 + + + + Input Move (cm) + + + Output Move (cm) + + + Move (forward and backward) + + + + 0.000000000000000 + 0.000000000000000 + + + + + 90.000000000000000 + 0.000000000000000 + + + + + + + + + + + 170 + 140 + + + + image: url(:/images/translation_DOFs.png); + + + + + + + + + 50 + + + 180 + + + + 255 + 255 + 0 + + + + + 192 + 192 + 192 + + + + Input Move (cm) + + + Output Move (cm) + + + Move (left and right) + + + + 0.000000000000000 + 0.000000000000000 + + + + + 90.000000000000000 + 0.000000000000000 + + + + + + + + NeutralZone + + + + + + + 50 + + + + + + + NeutralZone + + + + + + + NeutralZone + + + + + + + 50 + + + + + + + 50 + + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + + 52 + 0 + + + + + 100 + 16777215 + + + + OK + + + + + + + + 0 + 0 + + + + + 52 + 0 + + + + + 100 + 16777215 + + + + Cancel + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + + + + + + QBezierConfigurator + QWidget +
qbezierconfigurator.h
+
+
+ + + + + + curveYaw + valueNeutralZoneChanged(int) + spinNZ_Yaw + setValue(int) + + + 268 + 114 + + + 593 + 125 + + + + + spinNZ_Yaw + valueChanged(int) + curveYaw + setNeutralZone(int) + + + 588 + 115 + + + 296 + 110 + + + + + curvePitch + valueNeutralZoneChanged(int) + spinNZ_Pitch + setValue(int) + + + 321 + 280 + + + 576 + 289 + + + + + spinNZ_Pitch + valueChanged(int) + curvePitch + setNeutralZone(int) + + + 629 + 287 + + + 334 + 285 + + + + + curveRoll + valueNeutralZoneChanged(int) + spinNZ_Roll + setValue(int) + + + 322 + 423 + + + 589 + 447 + + + + + spinNZ_Roll + valueChanged(int) + curveRoll + setNeutralZone(int) + + + 618 + 446 + + + 257 + 464 + + + + + curveX + valueNeutralZoneChanged(int) + spinNZ_X + setValue(int) + + + 312 + 107 + + + 568 + 126 + + + + + spinNZ_X + valueChanged(int) + curveX + setNeutralZone(int) + + + 548 + 125 + + + 322 + 142 + + + + + curveY + valueNeutralZoneChanged(int) + spinNZ_Y + setValue(int) + + + 282 + 261 + + + 569 + 286 + + + + + spinNZ_Y + valueChanged(int) + curveY + setNeutralZone(int) + + + 549 + 282 + + + 342 + 292 + + + + + curveZ + valueNeutralZoneChanged(int) + spinNZ_Z + setValue(int) + + + 363 + 417 + + + 571 + 445 + + + + + spinNZ_Z + valueChanged(int) + curveZ + setNeutralZone(int) + + + 546 + 444 + + + 316 + 447 + + + + + + startEngineClicked() + stopEngineClicked() + cameraSettingsClicked() + +
diff --git a/FaceTrackNoIR/FaceTrackNoIR.aps b/FaceTrackNoIR/FaceTrackNoIR.aps index f907ff92..0205c761 100644 Binary files a/FaceTrackNoIR/FaceTrackNoIR.aps and b/FaceTrackNoIR/FaceTrackNoIR.aps differ diff --git a/FaceTrackNoIR/FaceTrackNoIR.cpp b/FaceTrackNoIR/FaceTrackNoIR.cpp index ef579436..17e4284a 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.cpp +++ b/FaceTrackNoIR/FaceTrackNoIR.cpp @@ -698,6 +698,7 @@ void FaceTrackNoIR::createIconGroupBox() 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")); ui.iconcomboTrackerSource->addItem(QIcon(QCoreApplication::applicationDirPath() + "/images/SeeingMachines.ico"), tr("Face API")); ui.iconcomboTrackerSource->addItem(QIcon(QCoreApplication::applicationDirPath() + "/images/FaceTrackNoIR.ico"), tr("FTNoir server")); @@ -774,6 +775,9 @@ void FaceTrackNoIR::setIcon(int index) case TRACKIR: ui.btnShowServerControls->hide(); break; + case SIMCONNECT: + ui.btnShowServerControls->hide(); + break; default: break; } diff --git a/FaceTrackNoIR/FaceTrackNoIR.ui b/FaceTrackNoIR/FaceTrackNoIR.ui index fe4facb4..91c25ff5 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.ui +++ b/FaceTrackNoIR/FaceTrackNoIR.ui @@ -945,9 +945,6 @@ color:#000; - - - @@ -1096,9 +1093,166 @@ background:none; opacity:100; + + + + + + + 25 + 0 + + + + + 150 + 16777215 + + + + color:#ccc; +background:none; + + + Global settings + + + + + + + + 100 + 0 + + + + + 150 + 16777215 + + + + color:#ccc; +background:none; + + + Use EWMA filtering: + + + + + + + background:none; + + + + + + + + + + + 25 + 0 + + + + + 150 + 16777215 + + + + color:#ccc; +background:none; + + + Smoothing: + + + + + + + color:#ccc; +background:none; + + + (samples) + + + + + + + + 50 + 15 + + + + 1 + + + 120 + + + 10 + + + 10 + + + Qt::Horizontal + + + QSlider::NoTicks + + + + + + + + 50 + 22 + + + + background:none; + + + 120 + + + 10 + + + + + + + + + false + + + + + + QFrame::Sunken + + + Qt::Vertical + + + - + @@ -1112,6 +1266,9 @@ opacity:100; 16777215 + + Qt::RightToLeft + color:#ccc; background:none; @@ -1121,7 +1278,7 @@ background:none; - + @@ -1135,6 +1292,9 @@ background:none; 16777215 + + Qt::RightToLeft + color:#ccc; background:none; @@ -1144,7 +1304,7 @@ background:none; - + @@ -1158,6 +1318,9 @@ background:none; 16777215 + + Qt::RightToLeft + color:#ccc; background:none; @@ -1167,7 +1330,7 @@ background:none; - + @@ -1181,6 +1344,9 @@ background:none; 16777215 + + Qt::RightToLeft + color:#ccc; background:none; @@ -1190,7 +1356,7 @@ background:none; - + @@ -1204,6 +1370,9 @@ background:none; 16777215 + + Qt::RightToLeft + color:#ccc; background:none; @@ -1213,7 +1382,7 @@ background:none; - + @@ -1227,6 +1396,9 @@ background:none; 16777215 + + Qt::RightToLeft + color:#ccc; background:none; @@ -1236,7 +1408,7 @@ background:none; - + background:none; @@ -1246,7 +1418,7 @@ background:none; - + @@ -1269,7 +1441,7 @@ background:none; - + background:none; @@ -1279,7 +1451,7 @@ background:none; - + background:none; @@ -1289,7 +1461,7 @@ background:none; - + background:none; @@ -1299,7 +1471,7 @@ background:none; - + @@ -1322,7 +1494,7 @@ background:none; - + background:none; @@ -1332,7 +1504,7 @@ background:none; - + background:none; @@ -1342,11 +1514,11 @@ background:none; - + - 50 + 45 15 @@ -1367,11 +1539,11 @@ background:none; - + - 50 + 45 15 @@ -1392,11 +1564,11 @@ background:none; - + - 50 + 45 15 @@ -1417,7 +1589,7 @@ background:none; - + @@ -1439,7 +1611,7 @@ background:none; - + @@ -1461,7 +1633,7 @@ background:none; - + @@ -1483,7 +1655,7 @@ background:none; - + @@ -1506,11 +1678,11 @@ background:none; - + - 50 + 45 15 @@ -1531,11 +1703,11 @@ background:none; - + - 50 + 45 15 @@ -1556,11 +1728,11 @@ background:none; - + - 50 + 45 15 @@ -1581,7 +1753,7 @@ background:none; - + @@ -1603,7 +1775,7 @@ background:none; - + @@ -1625,7 +1797,7 @@ background:none; - + @@ -1647,7 +1819,7 @@ background:none; - + @@ -1670,140 +1842,31 @@ background:none; - - - - background:none; - - - - - - - - - - - 25 - 0 - - - - - 150 - 16777215 - - - - color:#ccc; -background:none; - - - Use EWMA filtering: - - - - - - - - 25 - 0 - - - - - 150 - 16777215 - - - - color:#ccc; -background:none; - - - Global settings - - - - - - - - 25 - 0 - - - - - 150 - 16777215 - + + + + Qt::RightToLeft color:#ccc; background:none; - Smoothing: + EWMA - - - - - 50 - 15 - - - - 1 - - - 120 - - - 10 - - - 10 - - - Qt::Horizontal - - - QSlider::NoTicks - - - - - - - - 50 - 22 - - - - background:none; - - - 120 - - - 10 + + + + Qt::RightToLeft - - - - color:#ccc; background:none; - (samples) + EWMA diff --git a/FaceTrackNoIR/FaceTrackNoIR.vcproj b/FaceTrackNoIR/FaceTrackNoIR.vcproj index cb75ed3b..e691835e 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.vcproj +++ b/FaceTrackNoIR/FaceTrackNoIR.vcproj @@ -25,6 +25,7 @@ > + + @@ -405,6 +411,32 @@ RelativePath=".\resource.h" > + + + + + + + + @@ -711,6 +743,18 @@ /> + + + + + @@ -801,6 +845,29 @@ /> + + + + + + + + diff --git a/FaceTrackNoIR/SCServer.cpp b/FaceTrackNoIR/SCServer.cpp new file mode 100644 index 00000000..70c36595 --- /dev/null +++ b/FaceTrackNoIR/SCServer.cpp @@ -0,0 +1,203 @@ +/******************************************************************************** +* SCServer SCServer is the Class, that communicates headpose-data * +* to games, using the SimConnect.dll. * +* * +* Copyright (C) 2010 Wim Vriend (Developing) * +* Ron Hendriks (Testing and Research) * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the * +* Free Software Foundation; either version 3 of the License, or (at your * +* option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but * +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * +* more details. * +* * +* You should have received a copy of the GNU General Public License along * +* with this program; if not, see . * +* * +********************************************************************************/ +/* + Modifications (last one on top): +*/ +#include "SCServer.h" + + +float SCServer::virtPosX = 0.0f; +float SCServer::virtPosY = 0.0f; +float SCServer::virtPosZ = 0.0f; + +float SCServer::virtRotX = 0.0f; +float SCServer::virtRotY = 0.0f; +float SCServer::virtRotZ = 0.0f; + +/** constructor **/ +SCServer::SCServer() { + + // Create events + m_StopThread = CreateEvent(0, TRUE, FALSE, 0); + m_WaitThread = CreateEvent(0, TRUE, FALSE, 0); + + ProgramName = ""; +} + +/** destructor **/ +SCServer::~SCServer() { + + // Trigger thread to stop + ::SetEvent(m_StopThread); + + // Wait until thread finished + if (isRunning()) { + ::WaitForSingleObject(m_WaitThread, INFINITE); + } + + // Close handles + ::CloseHandle(m_StopThread); + ::CloseHandle(m_WaitThread); + + // + // Free the DLL + // + SCClientLib.unload(); + + //terminates the QThread and waits for finishing the QThread + terminate(); + wait(); +} + +/** QThread run @override **/ +void SCServer::run() { +bool blnSimConnectActive = false; +HANDLE hSimConnect = NULL; // Handle to SimConnect +importSimConnect_Open simconnect_open; // SimConnect function(s) in DLL +importSimConnect_Close simconnect_close; +importSimConnect_CameraSetRelative6DOF simconnect_set6DOF; + + // + // Get the SimConnect_Open function from the DLL and use it! + // + simconnect_open = (importSimConnect_Open) SCClientLib.resolve("SimConnect_Open"); + if (simconnect_open == NULL) { + qDebug() << "SCServer::run() says: SimConnect_Open function not found in DLL!"; + return; + } + simconnect_set6DOF = (importSimConnect_CameraSetRelative6DOF) SCClientLib.resolve("SimConnect_CameraSetRelative6DOF"); + if (simconnect_set6DOF == NULL) { + qDebug() << "SCServer::run() says: SimConnect_CameraSetRelative6DOF function not found in DLL!"; + return; + } + simconnect_close = (importSimConnect_Close) SCClientLib.resolve("SimConnect_Close"); + if (simconnect_close == NULL) { + qDebug() << "SCServer::run() says: SimConnect_Close function not found in DLL!"; + return; + } + + qDebug() << "SCServer::run() says: SimConnect functions resolved in DLL!"; + + forever + { + // Check event for stop thread + if(::WaitForSingleObject(m_StopThread, 0) == WAIT_OBJECT_0) + { + // Set event + simconnect_close( hSimConnect ); + ::SetEvent(m_WaitThread); + return; + } + + if (!blnSimConnectActive) { + if (SUCCEEDED(simconnect_open(&hSimConnect, "FaceTrackNoIR", NULL, 0, 0, 0))) { + qDebug() << "SCServer::run() says: SimConnect active!"; + blnSimConnectActive = true; + } + else { + msleep(5000); + yieldCurrentThread(); + } + } + else { + // + // Write the 6DOF-data to FSX + // + if (S_OK == simconnect_set6DOF(hSimConnect, virtPosX, virtPosY, virtPosZ, virtRotX, virtRotZ, virtRotY)) { + qDebug() << "SCServer::run() says: SimConnect data written!"; + } + + // just for lower cpu load + msleep(15); + yieldCurrentThread(); + } + } +} + +// +// Check if the Client DLL exists and load it (to test it), if so. +// Returns 'true' if all seems OK. +// +bool SCServer::SCCheckClientDLL() +{ + QString aFileName; // File Path and Name + + // Code to activate the context for the SimConnect DLL + ACTCTX act = { 0 }; + HANDLE hctx; + ULONG_PTR ulCookie; + + + qDebug() << "FTCheckClientDLL says: Starting Function"; + + try { + + act.cbSize = sizeof(act); + act.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID; + + QString manifest(QCoreApplication::applicationDirPath()); + manifest += "\\FaceTrackNoIR.exe"; + const wchar_t * encodedName = reinterpret_cast(manifest.utf16()); + + act.lpSource = encodedName; + act.lpResourceName = MAKEINTRESOURCE(101); + + hctx = CreateActCtx (&act); + + if (hctx != INVALID_HANDLE_VALUE) { + if (!ActivateActCtx(hctx, &ulCookie)) { + ReleaseActCtx(hctx); + QMessageBox::information(0, "FaceTrackNoIR error", "SimConnect DLL not found!"); + } + } + else { + qDebug() << "FTCheckClientDLL says: Error INVALID_HANDLE: " << GetLastError(); + return false; + } + + // + // Just try to load the DLL. Let Windows handle the PATH's and such trivialities... + // + aFileName = SC_CLIENT_FILENAME; + + // + // Load the DLL. + // + SCClientLib.setFileName(aFileName); + if (SCClientLib.load() != true) { + QMessageBox::information(0, "FaceTrackNoIR error", SCClientLib.errorString()); + return false; + } + + // + // Deactivate the context again: the function-references should stay in-tact... + // + DeactivateActCtx(0, ulCookie); + ReleaseActCtx(hctx); + + } catch(...) { + return false; + } + return true; +} + +//END diff --git a/FaceTrackNoIR/SCServer.h b/FaceTrackNoIR/SCServer.h new file mode 100644 index 00000000..568cfe77 --- /dev/null +++ b/FaceTrackNoIR/SCServer.h @@ -0,0 +1,99 @@ +/******************************************************************************** +* SCServer SCServer is the Class, that communicates headpose-data * +* to games, using the SimConnect.dll. * +* * +* Copyright (C) 2010 Wim Vriend (Developing) * +* Ron Hendriks (Testing and Research) * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the * +* Free Software Foundation; either version 3 of the License, or (at your * +* option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but * +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * +* more details. * +* * +* You should have received a copy of the GNU General Public License along * +* with this program; if not, see . * +* * +********************************************************************************/ +#pragma once +#ifndef INCLUDED_SCSERVER_H +#define INCLUDED_SCSERVER_H + +// +// Prevent the SimConnect manifest from being merged in the application-manifest +// This is necessary to run FaceTrackNoIR on a PC without FSX +// +#define SIMCONNECT_H_NOMANIFEST +#include "Windows.h" +#include "SimConnect.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef HRESULT (WINAPI *importSimConnect_Open)(HANDLE * phSimConnect, LPCSTR szName, HWND hWnd, DWORD UserEventWin32, HANDLE hEventHandle, DWORD ConfigIndex); +typedef HRESULT (WINAPI *importSimConnect_Close)(HANDLE hSimConnect); +typedef HRESULT (WINAPI *importSimConnect_CameraSetRelative6DOF)(HANDLE hSimConnect, float fDeltaX, float fDeltaY, float fDeltaZ, float fPitchDeg, float fBankDeg, float fHeadingDeg); + +using namespace std; + +static const char* SC_CLIENT_FILENAME = "SimConnect.dll"; + +class SCServer : public QThread { + Q_OBJECT + +public: + + // public member methods + SCServer(); + ~SCServer(); + + bool SCCheckClientDLL(); + + // protected member methods +protected: + void run(); + +private: + // Handles to neatly terminate thread... + HANDLE m_StopThread; + HANDLE m_WaitThread; + + // Private properties + QString ProgramName; + QLibrary SCClientLib; + +public: + + // Settings for calculating the Virtual Pose + static float virtPosX; + static float virtPosY; + static float virtPosZ; + + static float virtRotX; + static float virtRotY; + static float virtRotZ; + + static void setVirtRotX(float rot) { virtRotX = rot; } // degrees + static void setVirtRotY(float rot) { virtRotY = rot; } + static void setVirtRotZ(float rot) { virtRotZ = rot; } + + static void setVirtPosX(float pos) { virtPosX = pos/100.f; } // cm to meters + static void setVirtPosY(float pos) { virtPosY = pos/100.f; } + static void setVirtPosZ(float pos) { virtPosZ = pos/100.f; } + +}; + + +#endif//INCLUDED_SCSERVER_H +//END diff --git a/FaceTrackNoIR/SCServer.manifest b/FaceTrackNoIR/SCServer.manifest new file mode 100644 index 00000000..19b123ba --- /dev/null +++ b/FaceTrackNoIR/SCServer.manifest @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/FaceTrackNoIR/postbuild.bat b/FaceTrackNoIR/postbuild.bat new file mode 100644 index 00000000..6653067e --- /dev/null +++ b/FaceTrackNoIR/postbuild.bat @@ -0,0 +1,27 @@ +@echo off +rem Copies required DLL files into output folder. + +setlocal +set COPY=xcopy /D /S /C /I /H /R /Y +set FILTER=find /v "File(s) copied" + +echo parameters %1 en %2 en %3 + +set API_BIN=%1 +set OUTDIR=%2 +set CONFIG=%3 + +if %CONFIG%==Debug (goto Debug) +if %CONFIG%==Release (goto Release) + +echo Unknown build configuration %CONFIG% +exit /b -1 + +:Debug +%COPY% %API_BIN% %OUTDIR%\ | %FILTER% +exit /b 0 + +:Release +%COPY% %API_BIN% %OUTDIR%\ | %FILTER% +exit /b 0 + diff --git a/FaceTrackNoIR/tracker.cpp b/FaceTrackNoIR/tracker.cpp index 82f26fc2..1eeb2c88 100644 --- a/FaceTrackNoIR/tracker.cpp +++ b/FaceTrackNoIR/tracker.cpp @@ -23,6 +23,9 @@ *********************************************************************************/ /* Modifications (last one on top): + 20101011 - WVR: Added SimConnect server. + 20101007 - WVR: Created 6DOF-curves and drastically changed the tracker for that. + Also eliminated a 'glitch' in the process. 20100607 - WVR: Re-installed Rotation Neutral Zone and improved reaction after 'start/stop'. MessageBeep when confidence is back... 20100604 - WVR: Created structure for DOF-data and changed timing of @@ -98,6 +101,7 @@ Tracker::Tracker( int clientID ) { server_FG = 0; server_PPJoy = 0; server_FTIR = 0; + server_SC = 0; switch (selectedClient) { case FREE_TRACK: server_FT = new FTServer; // Create Free-track protocol-server @@ -118,6 +122,10 @@ Tracker::Tracker( int clientID ) { server_FTIR = new FTIRServer; // Create Fake-TIR protocol-server break; + case SIMCONNECT: + server_SC = new SCServer; // Create SimConnect protocol-server + break; + default: // should never be reached break; @@ -142,6 +150,9 @@ Tracker::~Tracker() { if (server_FTIR) { server_FTIR->deleteLater(); } + if (server_SC) { + server_SC->deleteLater(); + } // Trigger thread to stop ::SetEvent(m_StopThread); @@ -217,6 +228,23 @@ void Tracker::setup(QWidget *head, FaceTrackNoIR *parent) { server_FTIR->start(); // Start the thread } + // + // Check if the SimConnect DLL is available, load it if so. + // + if (server_SC) { + DLL_Ok = server_SC->SCCheckClientDLL(); + + if (DLL_Ok) { + server_SC->start(); // Start the thread + } + else { + QMessageBox::information(0, "FaceTrackNoIR error", "This SimConnect version is not installed!"); + } + ////else { + //// server_SC->~SCServer(); + //// server_SC = 0; + ////} + } } @@ -458,11 +486,11 @@ void Tracker::run() { // X if (Tracker::useFilter) { - posX = lowPassFilter ( getSmoothFromList( &X.rawList ) - X.offset_headPos, + posX = lowPassFilter ( getSmoothFromList( &X.rawList ) - X.offset_headPos - X.initial_headPos, &X.prevPos, dT, Tracker::X.red ); } else { - posX = getSmoothFromList( &X.rawList ) - X.offset_headPos; + posX = getSmoothFromList( &X.rawList ) - X.offset_headPos - X.initial_headPos; } posX = X.invert * getOutputFromCurve(&X.curve, posX, X.NeutralZone, X.MaxInput); @@ -533,14 +561,6 @@ void Tracker::run() { // Fake-trackIR if (server_FTIR) { - - // For some reason (not yet understood) the values only came through after being copied to locals... - // Trying again?! - //float rotX = getDegreesFromRads ( Tracker::Pitch.invert * Tracker::Pitch.sens * rotX ); - //float rotY = getDegreesFromRads ( Tracker::Yaw.invert * Tracker::Yaw.sens * rotY ); - //float rotZ = getDegreesFromRads ( Tracker::Roll.invert * Tracker::Roll.sens * rotZ ); - qDebug() << "Tracker::run() says: virtRotX =" << rotX << " virtRotY =" << rotY; - server_FTIR->setVirtRotX ( rotX ); // degrees server_FTIR->setVirtRotY ( rotY ); server_FTIR->setVirtRotZ ( rotZ ); @@ -550,6 +570,17 @@ void Tracker::run() { server_FTIR->setVirtPosZ ( posZ ); } + // SimConnect + if (server_SC) { + server_SC->setVirtRotX ( rotX ); // degrees + server_SC->setVirtRotY ( rotY ); + server_SC->setVirtRotZ ( rotZ ); + + server_SC->setVirtPosX ( posX ); // centimeters + server_SC->setVirtPosY ( posY ); + server_SC->setVirtPosZ ( posZ ); + } + } else { // @@ -590,6 +621,15 @@ void Tracker::run() { server_FTIR->setVirtPosY ( 0.0f ); server_FTIR->setVirtPosZ ( 0.0f ); } + + if (server_SC) { + server_SC->setVirtRotX ( 0.0f ); + server_SC->setVirtRotY ( 0.0f ); + server_SC->setVirtRotZ ( 0.0f ); + server_SC->setVirtPosX ( 0.0f ); + server_SC->setVirtPosY ( 0.0f ); + server_SC->setVirtPosZ ( 0.0f ); + } } //for lower cpu load @@ -852,41 +892,70 @@ QPointF point1, point2, point3, point4; // Read the curve-settings from the file. Use the (deprecated) settings, if the curves are not there. // iniFile.beginGroup ( "Curves" ); + + // + // Create a new path and assign it to the curve. + // getCurvePoints( &iniFile, "Yaw_", &point1, &point2, &point3, &point4, NeutralZone, sensYaw, 50, 180 ); - Yaw.curve.moveTo( QPointF(0,0) ); + QPainterPath newYawCurve; + newYawCurve.moveTo( QPointF(0,0) ); + newYawCurve.cubicTo(point2, point3, point4); + Yaw.NeutralZone = point1.y(); // Get the Neutral Zone Yaw.MaxInput = point4.y(); // Get Maximum Input - Yaw.curve.cubicTo(point2, point3, point4); + Yaw.curve = newYawCurve; + qDebug() << "loadSettings says: curve-elementcount = " << Yaw.curve.elementCount(); + + // Pitch getCurvePoints( &iniFile, "Pitch_", &point1, &point2, &point3, &point4, NeutralZone, sensPitch, 50, 180 ); - Pitch.curve.moveTo( QPointF(0,0) ); + QPainterPath newPitchCurve; + newPitchCurve.moveTo( QPointF(0,0) ); + newPitchCurve.cubicTo(point2, point3, point4); + Pitch.NeutralZone = point1.y(); // Get the Neutral Zone Pitch.MaxInput = point4.y(); // Get Maximum Input - Pitch.curve.cubicTo(point2, point3, point4); + Pitch.curve = newPitchCurve; + // Roll getCurvePoints( &iniFile, "Roll_", &point1, &point2, &point3, &point4, NeutralZone, sensRoll, 50, 180 ); - Roll.curve.moveTo( QPointF(0,0) ); + QPainterPath newRollCurve; + newRollCurve.moveTo( QPointF(0,0) ); + newRollCurve.cubicTo(point2, point3, point4); + Roll.NeutralZone = point1.y(); // Get the Neutral Zone Roll.MaxInput = point4.y(); // Get Maximum Input - Roll.curve.cubicTo(point2, point3, point4); + Roll.curve = newRollCurve; + // X getCurvePoints( &iniFile, "X_", &point1, &point2, &point3, &point4, NeutralZone, sensX, 50, 180 ); - X.curve.moveTo( QPointF(0,0) ); + QPainterPath newXCurve; + newXCurve.moveTo( QPointF(0,0) ); + newXCurve.cubicTo(point2, point3, point4); + X.NeutralZone = point1.y(); // Get the Neutral Zone X.MaxInput = point4.y(); // Get Maximum Input - X.curve.cubicTo(point2, point3, point4); + X.curve = newXCurve; + // Y getCurvePoints( &iniFile, "Y_", &point1, &point2, &point3, &point4, NeutralZone, sensY, 50, 180 ); - Y.curve.moveTo( QPointF(0,0) ); + QPainterPath newYCurve; + newYCurve.moveTo( QPointF(0,0) ); + newYCurve.cubicTo(point2, point3, point4); + Y.NeutralZone = point1.y(); // Get the Neutral Zone Y.MaxInput = point4.y(); // Get Maximum Input - Y.curve.cubicTo(point2, point3, point4); + Y.curve = newYCurve; + // Z getCurvePoints( &iniFile, "Z_", &point1, &point2, &point3, &point4, NeutralZone, sensZ, 50, 180 ); - Z.curve.moveTo( QPointF(0,0) ); + QPainterPath newZCurve; + newZCurve.moveTo( QPointF(0,0) ); + newZCurve.cubicTo(point2, point3, point4); + Z.NeutralZone = point1.y(); // Get the Neutral Zone Z.MaxInput = point4.y(); // Get Maximum Input - Z.curve.cubicTo(point2, point3, point4); + Z.curve = newZCurve; iniFile.endGroup (); diff --git a/FaceTrackNoIR/tracker.h b/FaceTrackNoIR/tracker.h index e3d6063f..a04b8ef4 100644 --- a/FaceTrackNoIR/tracker.h +++ b/FaceTrackNoIR/tracker.h @@ -40,6 +40,7 @@ #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 the DirectX Library files #pragma comment (lib, "dinput8.lib") @@ -62,7 +63,8 @@ enum FTNoIR_Client { FLIGHTGEAR = 1, FTNOIR = 2, PPJOY = 3, - TRACKIR = 4 + TRACKIR = 4, + SIMCONNECT = 5 }; class FaceTrackNoIR; // pre-define parent-class to avoid circular includes @@ -154,6 +156,7 @@ private: FGServer *server_FG; // FlightGear Server PPJoyServer *server_PPJoy; // PPJoy Server FTIRServer *server_FTIR; // Fake TIR Server + SCServer *server_SC; // SimConnect Server protected: // qthread override run method @@ -172,22 +175,6 @@ public: QSharedPointer getEngine() { return _engine; }; - //static float getHeadPosX() {return X.headPos;} - //static float getHeadPosY() {return Y.headPos;} - //static float getHeadPosZ() {return Z.headPos;} - - //static void setHeadPosX(float x) { X.headPos = x; } - //static void setHeadPosY(float y) { Y.headPos = y; } - //static void setHeadPosZ(float z) { Z.headPos = z; } - - //static float getHeadRotX() {return Pitch.headPos;} - //static float getHeadRotY() {return Yaw.headPos;} - //static float getHeadRotZ() {return Roll.headPos;} - - //static void setHeadRotX(float x) { Pitch.headPos = x; } - //static void setHeadRotY(float y) { Yaw.headPos = y; } - //static void setHeadRotZ(float z) { Roll.headPos = z; } - static bool getConfid() { return confid; } static void setInvertPitch(bool invert) { Pitch.invert = invert?-1.0f:+1.0f; } diff --git a/bin/FaceTrackNoIR.exe b/bin/FaceTrackNoIR.exe index 775c7a68..12a74897 100644 Binary files a/bin/FaceTrackNoIR.exe and b/bin/FaceTrackNoIR.exe differ diff --git a/bin/Settings/ArmA.ini b/bin/Settings/ArmA.ini index db548ff1..b8913b5c 100644 --- a/bin/Settings/ArmA.ini +++ b/bin/Settings/ArmA.ini @@ -10,14 +10,14 @@ sensZ=70 invertYaw=false invertPitch=false invertRoll=true -invertX=false +invertX=true invertY=false invertZ=false useEWMA=true redYaw=60 redPitch=60 redRoll=60 -redX=70 +redX=71 redY=70 redZ=70 @@ -26,21 +26,21 @@ Selection=0 [Curves] Roll_point1=@Variant(\0\0\0\x1a\0\0\0\0\0\0\0\0@\b\0\0\0\0\0\0) -Roll_point2=@Variant(\0\0\0\x1a@\x14\0\0\0\0\0\0@F\0\0\0\0\0\0) -Roll_point3=@Variant(\0\0\0\x1a@\x14\0\0\0\0\0\0@C\x80\0\0\0\0\0) +Roll_point2=@Variant(\0\0\0\x1a@6\x80\0\0\0\0\0@B\xc0\0\0\0\0\0) +Roll_point3=@Variant(\0\0\0\x1a@9\x80\0\0\0\0\0@B\x80\0\0\0\0\0) Roll_point4=@Variant(\0\0\0\x1a@F\0\0\0\0\0\0@I\0\0\0\0\0\0) Yaw_point1=@Variant(\0\0\0\x1a\0\0\0\0\0\0\0\0@\0\0\0\0\0\0\0) -Yaw_point2="@Variant(\0\0\0\x1a@2\0\0\0\0\0\0@;\0\0\0\0\0\0)" -Yaw_point3=@Variant(\0\0\0\x1a@>\0\0\0\0\0\0@E\x80\0\0\0\0\0) -Yaw_point4=@Variant(\0\0\0\x1a@K\0\0\0\0\0\0@I\0\0\0\0\0\0) +Yaw_point2=@Variant(\0\0\0\x1a@2\0\0\0\0\0\0@8\0\0\0\0\0\0) +Yaw_point3=@Variant(\0\0\0\x1a@5\0\0\0\0\0\0@9\0\0\0\0\0\0) +Yaw_point4=@Variant(\0\0\0\x1a@G\0\0\0\0\0\0@I\0\0\0\0\0\0) Pitch_point1=@Variant(\0\0\0\x1a\0\0\0\0\0\0\0\0@\b\0\0\0\0\0\0) -Pitch_point2=@Variant(\0\0\0\x1a@3\0\0\0\0\0\0@D\0\0\0\0\0\0) -Pitch_point3=@Variant(\0\0\0\x1a@4\0\0\0\0\0\0@E\x80\0\0\0\0\0) +Pitch_point2=@Variant(\0\0\0\x1a@<\x80\0\0\0\0\0@@\0\0\0\0\0\0) +Pitch_point3=@Variant(\0\0\0\x1a@<\x80\0\0\0\0\0@@\x80\0\0\0\0\0) Pitch_point4=@Variant(\0\0\0\x1a@D\x80\0\0\0\0\0@I\0\0\0\0\0\0) X_point1=@Variant(\0\0\0\x1a\0\0\0\0\0\0\0\0@\0\0\0\0\0\0\0) -X_point2=@Variant(\0\0\0\x1a@P\xc0\0\0\0\0\0@1\x80\0\0\0\0\0) -X_point3=@Variant(\0\0\0\x1a@M\xc0\0\0\0\0\0@2\x80\0\0\0\0\0) -X_point4=@Variant(\0\0\0\x1a@U \0\0\0\0\0@I\0\0\0\0\0\0) +X_point2=@Variant(\0\0\0\x1a@Z@\0\0\0\0\0@1\0\0\0\0\0\0) +X_point3=@Variant(\0\0\0\x1a@a@\0\0\0\0\0@?\0\0\0\0\0\0) +X_point4=@Variant(\0\0\0\x1a@d\xa0\0\0\0\0\0@I\0\0\0\0\0\0) Y_point1=@Variant(\0\0\0\x1a\0\0\0\0\0\0\0\0@\0\0\0\0\0\0\0) Y_point2=@Variant(\0\0\0\x1a@F\x80\0\0\0\0\0@E\0\0\0\0\0\0) Y_point3=@Variant(\0\0\0\x1a@6\0\0\0\0\0\0@9\0\0\0\0\0\0) @@ -51,11 +51,11 @@ Z_point3=@Variant(\0\0\0\x1a@6\0\0\0\0\0\0@D\x80\0\0\0\0\0) Z_point4=@Variant(\0\0\0\x1a@K\x80\0\0\0\0\0@I\0\0\0\0\0\0) [KB_Shortcuts] -Keycode_Center=59 +Keycode_Center=199 Shift_Center=false Ctrl_Center=false -Alt_Center=true -Keycode_StartStop=60 +Alt_Center=false +Keycode_StartStop=211 Shift_StartStop=false Ctrl_StartStop=false -Alt_StartStop=true +Alt_StartStop=false diff --git a/bin/Settings/FF5.ini b/bin/Settings/FF5.ini new file mode 100644 index 00000000..db4901fd --- /dev/null +++ b/bin/Settings/FF5.ini @@ -0,0 +1,25 @@ +[Tracking] +Smooth=15 +NeutralZone=5 +sensYaw=200 +sensPitch=200 +sensRoll=100 +sensX=100 +sensY=100 +sensZ=100 +invertYaw=true +invertPitch=false +invertRoll=false +invertX=true +invertY=false +invertZ=false +useEWMA=true +redYaw=75 +redPitch=75 +redRoll=75 +redX=75 +redY=75 +redZ=75 + +[GameProtocol] +Selection=4 diff --git a/bin/Settings/GlovePIE.ini b/bin/Settings/GlovePIE.ini new file mode 100644 index 00000000..d6949d39 --- /dev/null +++ b/bin/Settings/GlovePIE.ini @@ -0,0 +1,25 @@ +[Tracking] +Smooth=15 +NeutralZone=5 +sensYaw=200 +sensPitch=200 +sensRoll=100 +sensX=100 +sensY=100 +sensZ=100 +invertYaw=true +invertPitch=false +invertRoll=false +invertX=true +invertY=false +invertZ=false +useEWMA=true +redYaw=75 +redPitch=75 +redRoll=75 +redX=75 +redY=75 +redZ=75 + +[GameProtocol] +Selection=3 diff --git a/bin/Settings/SimConnect.ini b/bin/Settings/SimConnect.ini new file mode 100644 index 00000000..3d69dde0 --- /dev/null +++ b/bin/Settings/SimConnect.ini @@ -0,0 +1,28 @@ +[Tracking] +Smooth=5 +invertYaw=true +invertPitch=true +invertRoll=false +invertX=false +invertY=false +invertZ=true +useEWMA=true +redYaw=60 +redPitch=60 +redRoll=60 +redX=71 +redY=70 +redZ=70 + +[GameProtocol] +Selection=5 + +[KB_Shortcuts] +Keycode_Center=59 +Shift_Center=false +Ctrl_Center=false +Alt_Center=true +Keycode_StartStop=60 +Shift_StartStop=false +Ctrl_StartStop=false +Alt_StartStop=true -- cgit v1.2.3