From 394dca378432d8ba65dd84432ea1a85ddea636fd Mon Sep 17 00:00:00 2001 From: Wim Vriend Date: Thu, 7 Apr 2011 17:44:03 +0000 Subject: PPJoy in DLL git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@65 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb --- FaceTrackNoIR/FTNoIR_ppjoycontrols.ui | 172 -------------------- FaceTrackNoIR/FTServer.cpp | 257 ------------------------------ FaceTrackNoIR/FTServer.h | 105 ------------- FaceTrackNoIR/FTTypes.h | 85 ---------- FaceTrackNoIR/FaceApp.cpp | 2 +- FaceTrackNoIR/FaceTrackNoIR.cpp | 23 ++- FaceTrackNoIR/FaceTrackNoIR.vcproj | 146 ----------------- FaceTrackNoIR/PPJIoctl.h | 32 ---- FaceTrackNoIR/PPJoyServer.cpp | 285 ---------------------------------- FaceTrackNoIR/PPJoyServer.h | 136 ---------------- FaceTrackNoIR/tracker.cpp | 48 +++++- FaceTrackNoIR/tracker.h | 4 +- 12 files changed, 68 insertions(+), 1227 deletions(-) delete mode 100644 FaceTrackNoIR/FTNoIR_ppjoycontrols.ui delete mode 100644 FaceTrackNoIR/FTServer.cpp delete mode 100644 FaceTrackNoIR/FTServer.h delete mode 100644 FaceTrackNoIR/FTTypes.h delete mode 100644 FaceTrackNoIR/PPJIoctl.h delete mode 100644 FaceTrackNoIR/PPJoyServer.cpp delete mode 100644 FaceTrackNoIR/PPJoyServer.h diff --git a/FaceTrackNoIR/FTNoIR_ppjoycontrols.ui b/FaceTrackNoIR/FTNoIR_ppjoycontrols.ui deleted file mode 100644 index a160801a..00000000 --- a/FaceTrackNoIR/FTNoIR_ppjoycontrols.ui +++ /dev/null @@ -1,172 +0,0 @@ - - - UICPPJoyControls - - - - 0 - 0 - 346 - 180 - - - - PPJoy settings FaceTrackNoIR - - - - images/FaceTrackNoIR.icoimages/FaceTrackNoIR.ico - - - Qt::LeftToRight - - - false - - - - - - - - - 0 - 0 - - - - Virtual Joystick number: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - false - - - - - - - Select Number - - - QComboBox::InsertAlphabetically - - - - - - - - - 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/FTServer.cpp b/FaceTrackNoIR/FTServer.cpp deleted file mode 100644 index 7814c2d3..00000000 --- a/FaceTrackNoIR/FTServer.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/******************************************************************************** -* FTServer FTServer is the Class, that communicates headpose-data * -* to games, using the FreeTrackClient.dll. * -* It was (very) loosely translated from FTServer.pas. * -* which was created by the FreeTrack-team. * -* * -* Copyright (C) 2010 Wim Vriend (Developing) * -* Ron Hendriks (Testing and Research) * -* * -* Homepage * -* * -* 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 . * -* * -* We would like to extend our grattitude to the creators of SweetSpotter, * -* which has become the basis of this program: "Great work guys!" * -********************************************************************************/ -// -// There are some issues, that may need solving: -// -// 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? -// --> WVR 20100409: Update on this: Loading the DLL with QLibrary implemented. -// With UNICODE on, the DLL is loaded fine, but the memory-mapping -// does not. Explicitely using the 'A' extension for CreateFileMapping -// solves this (for now.) Maybe there is a Qt substitute for this? -// -/* - Modifications (last one on top): - 20101224 - WVR: Base class is no longer inheriting QThread. sendHeadposeToGame - is called from run() of Tracker.cpp - 20100601 - WVR: Added Mutex-bit in run(). Thought it wasn't so important (still do...). - 20100523 - WVR: Implemented the Freetrack-protocol just like Freetrack does. Earlier - FaceTrackNoIR only worked with an adapted DLL, with a putdata function. - Now it works direcly in shared memory! -*/ -#include "FTServer.h" - -/** constructor **/ -FTServer::FTServer() { - ProgramName = ""; -} - -/** destructor **/ -FTServer::~FTServer() { - - // - // Free the DLL - // - FTClientLib.unload(); -} - -// -// Update Headpose in Game. -// -void FTServer::sendHeadposeToGame() { - - // - // Check if the pointer is OK and wait for the Mutex. - // - if ( (pMemData != NULL) && (WaitForSingleObject(hFTMutex, 100) == WAIT_OBJECT_0) ) { - - // - // Copy the Raw measurements directly to the client. - // - pMemData->data.RawX = headPosX; - pMemData->data.RawY = headPosY; - pMemData->data.RawZ = headPosZ; - pMemData->data.RawPitch = headRotX; - pMemData->data.RawYaw = headRotY; - pMemData->data.RawRoll = headRotZ; - - // - // Multiply the FaceAPI value, with the sensitivity setting - // - pMemData->data.X = virtPosX; - pMemData->data.Y = virtPosY; - pMemData->data.Z = virtPosZ; - pMemData->data.Pitch = virtRotX; - pMemData->data.Yaw = virtRotY; - pMemData->data.Roll = virtRotZ; - - // - // Leave some values 0 yet... - // - pMemData->data.X1 = pMemData->data.DataID + 10; - pMemData->data.X2 = 0; - pMemData->data.X3 = 0; - pMemData->data.X4 = 0; - pMemData->data.Y1 = 0; - pMemData->data.Y2 = 0; - pMemData->data.Y3 = 0; - pMemData->data.Y4 = 0; - - //qDebug() << "FTServer says: pMemData.DataID =" << pMemData->data.DataID; - //qDebug() << "FTServer says: ProgramName =" << pMemData->ProgramName; - ReleaseMutex(hFTMutex); - } - - pMemData->data.DataID += 1; -} - -// -// Create a memory-mapping to the Freetrack data. -// It contains the tracking data, a handle to the main-window and the program-name of the Game! -// -// -bool FTServer::FTCreateMapping(HANDLE handle) -{ - qDebug() << "FTCreateMapping says: Starting Function"; - - // - // A FileMapping is used to create 'shared memory' between the FTServer and the FTClient. - // - // Try to create a FileMapping to the Shared Memory. - // If one already exists: close it. - // - hFTMemMap = CreateFileMappingA( INVALID_HANDLE_VALUE , 00 , PAGE_READWRITE , 0 , - sizeof( TFreeTrackData ) + sizeof( HANDLE ) + 100, - (LPCSTR) FT_MM_DATA ); - - if ( hFTMemMap != 0 ) { - qDebug() << "FTCreateMapping says: FileMapping Created!" << hFTMemMap; - } - - if ( ( hFTMemMap != 0 ) && ( (long) GetLastError == ERROR_ALREADY_EXISTS ) ) { - CloseHandle( hFTMemMap ); - hFTMemMap = 0; - } - - // - // Create a new FileMapping, Read/Write access - // - hFTMemMap = OpenFileMappingA( FILE_MAP_ALL_ACCESS , false , (LPCSTR) FT_MM_DATA ); - if ( ( hFTMemMap != 0 ) ) { - qDebug() << "FTCreateMapping says: FileMapping Created again:" << hFTMemMap; - pMemData = (FTMemMap *) MapViewOfFile(hFTMemMap, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(TFreeTrackData) + sizeof(hFTMemMap) + 100); - if (pMemData != NULL) { - pMemData->handle = handle; // The game uses the handle, to send a message that the Program-Name was set! - } - hFTMutex = CreateMutexA(NULL, false, FREETRACK_MUTEX); - } - else { - QMessageBox::information(0, "FaceTrackNoIR error", QString("FTServer Error! \n")); - return false; - } - - if (pMemData != NULL) { - pMemData->data.DataID = 1; - pMemData->data.CamWidth = 100; - pMemData->data.CamHeight = 250; - } - - return true; -} - -// -// Destory the FileMapping to the shared memory -// -void FTServer::FTDestroyMapping() -{ - if ( pMemData != NULL ) { - UnmapViewOfFile ( pMemData ); - } - - CloseHandle( hFTMutex ); - CloseHandle( hFTMemMap ); - hFTMemMap = 0; -} - -// -// Get the program-name from the client (Game!). -// -QString FTServer::GetProgramName() { -QString *str; - - str = new QString(pMemData->ProgramName); - return *str; -} - - -// -// Check if the Client DLL exists and load it (to test it), if so. -// Returns 'true' if all seems OK. -// -bool FTServer::checkServerInstallationOK( HANDLE handle ) -{ - QSettings settings("Freetrack", "FreetrackClient"); // Registry settings (in HK_USER) - QString aLocation; // Location of Client DLL - QString aFileName; // File Path and Name - - importProvider provider; - char *pProvider; - - qDebug() << "FTCheckClientDLL says: Starting Function"; - - try { - - // - // Load the FreeTrackClient.dll from the current path of FaceTrackNoIR, because there is no - // guarantee FreeTrack is also installed. - // - // Write this path in the registry (under FreeTrack/FreeTrackClient, for the game(s). - // - aLocation = QCoreApplication::applicationDirPath() + "/"; - qDebug() << "FTCheckClientDLL says: Location of DLL =" << aLocation; - - // - // Append a '/' to the Path and then the name of the dll. - // - aFileName = aLocation; - aFileName.append(FT_CLIENT_FILENAME); - qDebug() << "FTCheckClientDLL says: Full path of DLL =" << aFileName; - - if ( QFile::exists( aFileName ) ) { - qDebug() << "FTCheckClientDLL says: DLL exists!"; - // - // Write the path to the key in the Registry, so the game(s) can find it too... - // - settings.setValue( "Path" , aLocation ); - - // - // Load the DLL and map to the functions in it. - // - FTClientLib.setFileName(aFileName); - FTClientLib.load(); - provider = (importProvider) FTClientLib.resolve("FTProvider"); - if (provider) { - pProvider = provider(); - qDebug() << "FTCheckClientDLL says: Provider =" << pProvider; - } - } - else { - QMessageBox::information(0, "FaceTrackNoIR error", QString("Necessary file (FreeTrackClient.dll) was NOT found!\n")); - return false; - } - } catch(...) { - settings.~QSettings(); - } - return FTCreateMapping( handle ); -} - -//END diff --git a/FaceTrackNoIR/FTServer.h b/FaceTrackNoIR/FTServer.h deleted file mode 100644 index 68b0cabb..00000000 --- a/FaceTrackNoIR/FTServer.h +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************** -* FTServer FTServer is the Class, that communicates headpose-data * -* to games, using the FreeTrackClient.dll. * -* It was (very) loosely translated from FTServer.pas. * -* which was created by the FreeTrack-team. * -* * -* Copyright (C) 2010 Wim Vriend (Developing) * -* Ron Hendriks (Testing and Research) * -* * -* Homepage * -* * -* 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 . * -* * -* We would like to extend our grattitude to the creators of SweetSpotter, * -* which has become the basis of this program: "Great work guys!" * -********************************************************************************/ -#pragma once -#ifndef INCLUDED_FTSERVER_H -#define INCLUDED_FTSERVER_H - -#include "FTNoIR_cxx_protocolserver.h" -#include "FTTypes.h" -#include -#include -#include -#include -#include -#include -//#include -#include -#include -#include - -typedef char *(WINAPI *importProvider)(void); -typedef bool (WINAPI *importGetData)(TFreeTrackData * data); -typedef HANDLE (WINAPI *importGetMapHandle)(void); - -using namespace std; -using namespace v4friend::ftnoir; - -class FTServer : public ProtocolServerBase { - Q_OBJECT - -public: - - // public member methods - FTServer(); - ~FTServer(); - - QString GetProgramName(); - - // protected member methods -protected: -// void run(); - bool checkServerInstallationOK( HANDLE handle ); - void sendHeadposeToGame(); - -private: - bool FTCreateMapping(HANDLE handle); - void FTDestroyMapping(); - - HANDLE hFTMemMap; - FTMemMap *pMemData; - HANDLE hFTMutex; - - /** member varables for saving the head pose **/ - bool confid; - - // Private properties - QString ProgramName; - QLibrary FTClientLib; - -public: - void setHeadRotX(float x) { headRotX = getRadsFromDegrees(x); } - void setHeadRotY(float y) { headRotY = getRadsFromDegrees(y); } - void setHeadRotZ(float z) { headRotZ = getRadsFromDegrees(z); } - void setHeadPosX(float x) { headPosX = x * 10; } - void setHeadPosY(float y) { headPosY = y * 10; } - void setHeadPosZ(float z) { headPosZ = z * 10; } - - void setVirtRotX(float rot) { virtRotX = getRadsFromDegrees(rot); } - void setVirtRotY(float rot) { virtRotY = getRadsFromDegrees(rot); } - void setVirtRotZ(float rot) { virtRotZ = getRadsFromDegrees(rot); } - void setVirtPosX(float pos) { virtPosX = pos * 10; } - void setVirtPosY(float pos) { virtPosY = pos * 10; } - void setVirtPosZ(float pos) { virtPosZ = pos * 10; } - - float getRadsFromDegrees ( float degrees ) { return (degrees * 0.017453f); } - -}; - - -#endif//INCLUDED_FTSERVER_H -//END diff --git a/FaceTrackNoIR/FTTypes.h b/FaceTrackNoIR/FTTypes.h deleted file mode 100644 index a6dcb6c9..00000000 --- a/FaceTrackNoIR/FTTypes.h +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************** -* FTTypes FTTypes contains th specific type definitions for the * -* FreeTrack protocol. * -* It was loosely translated from FTTypes.pas * -* which was created by the FreeTrack-team. * -* * -* Copyright (C) 2010 Wim Vriend (Developing) * -* Ron Hendriks (Testing and Research) * -* * -* Homepage * -* * -* 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 . * -* * -* We would like to extend our grattitude to the creators of SweetSpotter, * -* which has become the basis of this program: "Great work guys!" * -********************************************************************************/ -#pragma once -#ifndef INCLUDED_FTTYPES_H -#define INCLUDED_FTTYPES_H - -#include "Windows.h" -#include -#include - -//#include "Registry.h" - -// static const char* FT_CLIENT_LOCATION = "Software\\Freetrack\\FreetrackClient"; - static const char* FT_CLIENT_FILENAME = "FreeTrackClient.Dll"; - static const char* FT_MM_DATA = "FT_SharedMem"; - static const char* FREETRACK = "Freetrack"; - static const char* FREETRACK_MUTEX = "FT_Mutext"; - static const char* FT_PROGRAMID = "FT_ProgramID"; - - -struct TFreeTrackData { - int DataID; - int CamWidth; - int CamHeight; - // virtual pose - float Yaw; // positive yaw to the left - float Pitch; // positive pitch up - float Roll; // positive roll to the left - float X; - float Y; - float Z; - // raw pose with no smoothing, sensitivity, response curve etc. - float RawYaw; - float RawPitch; - float RawRoll; - float RawX; - float RawY; - float RawZ; - // raw points, sorted by Y, origin top left corner - float X1; - float Y1; - float X2; - float Y2; - float X3; - float Y3; - float X4; - float Y4; -}; -typedef TFreeTrackData * PFreetrackData; - -struct FTMemMap { - TFreeTrackData data; - HANDLE handle; - char ProgramName[100]; -}; -typedef FTMemMap * PFTMemMap; - -extern bool (*FTGetData) (PFreetrackData data); - -#endif//INCLUDED_FTTYPES_H diff --git a/FaceTrackNoIR/FaceApp.cpp b/FaceTrackNoIR/FaceApp.cpp index 5998ebcf..2811974c 100644 --- a/FaceTrackNoIR/FaceApp.cpp +++ b/FaceTrackNoIR/FaceApp.cpp @@ -1,6 +1,6 @@ #include "FaceApp.h" #include "windows.h" -#include "FTTypes.h" +#include "..\FTNoIR_Protocol_FT\FTTypes.h" #include "..\FTNoIR_Protocol_FTIR\FTIRTypes.h" #include diff --git a/FaceTrackNoIR/FaceTrackNoIR.cpp b/FaceTrackNoIR/FaceTrackNoIR.cpp index 03f819de..49a6aab2 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.cpp +++ b/FaceTrackNoIR/FaceTrackNoIR.cpp @@ -31,7 +31,7 @@ */ #include "FaceTrackNoIR.h" #include "tracker.h" -#include "PPJoyServer.h" +//#include "PPJoyServer.h" #include "FSUIPCServer.h" //#include "FTIRServer.h" //#include "FGServer.h" @@ -835,9 +835,28 @@ QLibrary *protocolLib; case FREE_TRACK: case SIMCONNECT: break; + case PPJOY: - _server_controls = new PPJoyControls( this, Qt::Dialog ); + protocolLib = new QLibrary("FTNoIR_Protocol_PPJOY.dll"); + + 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 FSUIPC: _server_controls = new FSUIPCControls( this, Qt::Dialog ); break; diff --git a/FaceTrackNoIR/FaceTrackNoIR.vcproj b/FaceTrackNoIR/FaceTrackNoIR.vcproj index c16635b9..67546f1b 100644 --- a/FaceTrackNoIR/FaceTrackNoIR.vcproj +++ b/FaceTrackNoIR/FaceTrackNoIR.vcproj @@ -219,10 +219,6 @@ RelativePath=".\FTNServer.cpp" > - - @@ -231,10 +227,6 @@ RelativePath=".\main.cpp" > - - @@ -405,36 +397,6 @@ /> - - - - - - - - - - @@ -461,36 +423,6 @@ /> - - - - - - - - - - @@ -683,32 +615,6 @@ /> - - - - - - - - @@ -822,10 +728,6 @@ RelativePath=".\GeneratedFiles\ui_FTNoIR_KeyboardShortcuts.h" > - - @@ -907,18 +809,6 @@ /> - - - - - @@ -931,18 +821,6 @@ /> - - - - - @@ -1078,18 +956,6 @@ /> - - - - - @@ -1113,18 +979,6 @@ /> - - - - - diff --git a/FaceTrackNoIR/PPJIoctl.h b/FaceTrackNoIR/PPJIoctl.h deleted file mode 100644 index c406224f..00000000 --- a/FaceTrackNoIR/PPJIoctl.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef __PPJIOCTL_H__ -#define __PPJIOCTL_H__ - -#include "Windows.h" - -/* Define to use byte-size values for joystick axes, else dword size */ -#undef UCHAR_AXES - -#define PPJOY_AXIS_MIN 1 -#ifdef UCHAR_AXES -#define PPJOY_AXIS_MAX 127 -#else -#define PPJOY_AXIS_MAX 32767 -#endif - -#define FILE_DEVICE_PPORTJOY FILE_DEVICE_UNKNOWN - -#define PPORTJOY_IOCTL(_index_) \ - CTL_CODE (FILE_DEVICE_PPORTJOY, _index_, METHOD_BUFFERED, FILE_ANY_ACCESS) - -#define IOCTL_PPORTJOY_SET_STATE PPORTJOY_IOCTL (0x0) - -#define JOYSTICK_STATE_V1 0x53544143 - -typedef struct -{ - unsigned long Version; - unsigned char Data[1]; -} JOYSTICK_SET_STATE, *PJOYSTICK_SET_STATE; - - -#endif diff --git a/FaceTrackNoIR/PPJoyServer.cpp b/FaceTrackNoIR/PPJoyServer.cpp deleted file mode 100644 index 83b27f39..00000000 --- a/FaceTrackNoIR/PPJoyServer.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/******************************************************************************** -* FaceTrackNoIR This program is a private project of the some enthusiastic * -* gamers from Holland, who don't like to pay much for * -* head-tracking. * -* * -* Copyright (C) 2010 Wim Vriend (Developing) * -* Ron Hendriks (Researching and Testing) * -* * -* Homepage * -* * -* 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 . * -* * -* PPJoyServer PPJoyServer is the Class, that communicates headpose-data * -* to the Virtual Joystick, created by Deon van der Westhuysen.* -********************************************************************************/ -#include -#include -#include "PPJoyServer.h" -#include "Tracker.h" -#include - -//long PPJoyServer::PPJoyCorrection = 1470; -//long PPJoyServer::analogDefault = (PPJOY_AXIS_MIN+PPJOY_AXIS_MAX)/2 - PPJoyServer::PPJoyCorrection; -static const char* DevName = "\\\\.\\PPJoyIOCTL"; - -/** constructor **/ -PPJoyServer::PPJoyServer( Tracker *parent ) { -char strDevName[100]; - - // Save the parent - headTracker = parent; - - // Initialize arrays - for (int i = 0;i < 3;i++) { - centerPos[i] = 0; - centerRot[i] = 0; - } - selectedPPJoy = 1; - loadSettings(); - - /* Open a handle to the control device for the first virtual joystick. */ - /* Virtual joystick devices are named PPJoyIOCTL1 to PPJoyIOCTL16. */ - sprintf_s(strDevName, "%s%d", DevName, selectedPPJoy); - h = CreateFileA((LPCSTR) strDevName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); - - /* Make sure we could open the device! */ - if (h == INVALID_HANDLE_VALUE) - { - QMessageBox::critical(0, "Connection Failed", QString("FaceTrackNoIR failed to connect to Virtual Joystick %1.\nCheck if it was properly installed!").arg(selectedPPJoy)); - return; - } -} - -/** destructor **/ -PPJoyServer::~PPJoyServer() { - - - /* Make sure we could open the device! */ - if (h == INVALID_HANDLE_VALUE) { - return; - } - - // - // Free the Virtual Joystick - // - CloseHandle(h); -} - -/** QThread run @override **/ -void PPJoyServer::sendHeadposeToGame() { - - /* Initialise the IOCTL data structure */ - JoyState.Signature= JOYSTICK_STATE_V1; - JoyState.NumAnalog= NUM_ANALOG; // Number of analog values - Analog= JoyState.Analog; // Keep a pointer to the analog array for easy updating - Digital= JoyState.Digital; // Keep a pointer to the digital array for easy updating - JoyState.NumDigital= NUM_DIGITAL; // Number of digital values - - /* Make sure we could open the device! */ - /* MessageBox in run() does not work! (runtime error...)*/ - if (h == INVALID_HANDLE_VALUE) { - return; - } - - // The effective angle for faceTracking will be < 90 degrees, so we assume a smaller range here - Analog[0] = scale2AnalogLimits( virtRotX, -50.0f, 50.0f ); // Pitch - Analog[1] = scale2AnalogLimits( virtRotY, -50.0f, 50.0f ); // Yaw - Analog[2] = scale2AnalogLimits( virtRotZ, -50.0f, 50.0f ); // Roll - - // The effective movement for faceTracking will be < 50 cm, so we assume a smaller range here - Analog[3] = scale2AnalogLimits( virtPosX, -40.0f, 40.0f ); // X - - Analog[4] = scale2AnalogLimits( virtPosY, -40.0f, 40.0f ); // Y - Analog[5] = scale2AnalogLimits( virtPosZ, -40.0f, 40.0f ); // Z - - checkAnalogLimits(); - - /* Send request to PPJoy for processing. */ - /* Currently there is no Return Code from PPJoy, this may be added at a */ - /* later stage. So we pass a 0 byte output buffer. */ - if (!DeviceIoControl( h, IOCTL_PPORTJOY_SET_STATE, &JoyState, sizeof(JoyState), NULL, 0, &RetSize, NULL)) - { - return; - } -} - -// -// Limit the Joystick values -// -void PPJoyServer::checkAnalogLimits() { - for (int i = 0;i < NUM_ANALOG;i++) { - if (Analog[i]>PPJOY_AXIS_MAX) { - Analog[i]=PPJOY_AXIS_MAX; - } - else if (Analog[i]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.cbxSelectPPJoyNumber, SIGNAL(currentIndexChanged(int)), this, SLOT(virtualJoystickSelected( int ))); - - for (int i = 1 ; i < 17; i++) { - QString cbxText = QString("Virtual Joystick %1").arg(i); - ui.cbxSelectPPJoyNumber->addItem(QIcon("images/PPJoy.ico"), cbxText); - } - // Load the settings from the current .INI-file - loadSettings(); -} - -// -// Destructor for server-dialog -// -PPJoyControls::~PPJoyControls() { - qDebug() << "~PPJoyControls() says: started"; -} - -// -// OK clicked on server-dialog -// -void PPJoyControls::doOK() { - save(); - this->close(); -} - -// override show event -void PPJoyControls::showEvent ( QShowEvent * event ) { - loadSettings(); -} - -// -// Cancel clicked on server-dialog -// -void PPJoyControls::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 PPJoyControls::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 ( "PPJoy" ); - ui.cbxSelectPPJoyNumber->setCurrentIndex(iniFile.value ( "Selection", 1 ).toInt() - 1); - iniFile.endGroup (); - - settingsDirty = false; - -} - -// -// Save the current Settings to the currently 'active' INI-file. -// -void PPJoyControls::save() { - - qDebug() << "save() says: started"; - - 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 ( "PPJoy" ); - iniFile.setValue ( "Selection", ui.cbxSelectPPJoyNumber->currentIndex() + 1 ); - iniFile.endGroup (); - - settingsDirty = false; -} - -// -// Handle changes of the Virtual Joystick selection -// -void PPJoyControls::virtualJoystickSelected( int index ) -{ - settingsDirty = true; -} - -//END diff --git a/FaceTrackNoIR/PPJoyServer.h b/FaceTrackNoIR/PPJoyServer.h deleted file mode 100644 index a12ce34a..00000000 --- a/FaceTrackNoIR/PPJoyServer.h +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************** -* FaceTrackNoIR This program is a private project of the some enthusiastic * -* gamers from Holland, who don't like to pay much for * -* head-tracking. * -* * -* Copyright (C) 2010 Wim Vriend (Developing) * -* Ron Hendriks (Researching and Testing) * -* * -* Homepage * -* * -* 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 . * -* * -* PPJoyServer PPJoyServer is the Class, that communicates headpose-data * -* to the Virtual Joystick, created by Deon van der Westhuysen.* -********************************************************************************/ -#pragma once -#ifndef INCLUDED_PPJOYSERVER_H -#define INCLUDED_PPJOYSERVER_H - -#include "FTNoIR_cxx_protocolserver.h" -#include "PPJIoctl.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ui_FTNoIR_ppjoycontrols.h" - -using namespace std; -using namespace v4friend::ftnoir; - -class Tracker; // pre-define parent-class to avoid circular includes - -#define NUM_ANALOG 7 /* Number of analog values which we will provide */ -#define NUM_DIGITAL 1 /* Number of digital values which we will provide */ - -#pragma pack(push,1) /* All fields in structure must be byte aligned. */ -typedef struct -{ - unsigned long Signature; /* Signature to identify packet to PPJoy IOCTL */ - char NumAnalog; /* Num of analog values we pass */ - long Analog[NUM_ANALOG]; /* Analog values */ - char NumDigital; /* Num of digital values we pass */ - char Digital[NUM_DIGITAL]; /* Digital values */ -} JOYSTICK_STATE; -#pragma pack(pop) - -class PPJoyServer : public ProtocolServerBase { - Q_OBJECT - -public: - - // public member methods - PPJoyServer( Tracker *parent ); - ~PPJoyServer(); - - // protected member methods -protected: -// void run(); - void sendHeadposeToGame(); - -private slots: -// void readPendingDatagrams(); - -private: - Tracker *headTracker; // For upstream messages... - - HANDLE h; - JOYSTICK_STATE JoyState; - DWORD RetSize; - DWORD rc; - long *Analog; - char *Digital; - int selectedPPJoy; // Number of virtual joystick (1..16) - -// static long analogDefault,PPJoyCorrection; - long centerPos[3],centerRot[3]; - - void checkAnalogLimits(); - long scale2AnalogLimits( float x, float min_x, float max_x ); - void loadSettings(); - -public: - void setVirtRotX(float rot) { virtRotX = rot; } - void setVirtRotY(float rot) { virtRotY = rot; } - void setVirtRotZ(float rot) { virtRotZ = rot; } - void setVirtPosX(float pos) { virtPosX = pos; } - void setVirtPosY(float pos) { virtPosY = pos; } - void setVirtPosZ(float pos) { virtPosZ = pos; } - -}; - -// Widget that has controls for PPJoy server-settings. -class PPJoyControls: public QWidget, public Ui::UICPPJoyControls -{ - Q_OBJECT -public: - - explicit PPJoyControls( QWidget *parent=0, Qt::WindowFlags f=0 ); - virtual ~PPJoyControls(); - void showEvent ( QShowEvent * event ); - -private: - Ui::UICPPJoyControls ui; - void loadSettings(); - void save(); - - /** helper **/ - bool settingsDirty; - -private slots: - void doOK(); - void doCancel(); - void virtualJoystickSelected( int index ); - -}; - - -#endif//INCLUDED_PPJOYSERVER_H -//END diff --git a/FaceTrackNoIR/tracker.cpp b/FaceTrackNoIR/tracker.cpp index 46b26237..0dd7311e 100644 --- a/FaceTrackNoIR/tracker.cpp +++ b/FaceTrackNoIR/tracker.cpp @@ -183,11 +183,31 @@ QFrame *video_frame; // switch (selectedClient) { case FREE_TRACK: - server_Game = QSharedPointer(new FTServer ( )); // Create Free-track protocol-server + 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; + } break; case FLIGHTGEAR: - server_Game = QSharedPointer(new FTServer ( )); // Create Free-track protocol-server + 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. @@ -215,11 +235,31 @@ QFrame *video_frame; break; case PPJOY: - server_Game = QSharedPointer(new PPJoyServer ( this )); // Create PPJoy protocol-server + 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; + } break; case TRACKIR: - server_Game = QSharedPointer(new FTServer ( )); // Create Free-track protocol-server + 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. diff --git a/FaceTrackNoIR/tracker.h b/FaceTrackNoIR/tracker.h index c5921e85..3440495f 100644 --- a/FaceTrackNoIR/tracker.h +++ b/FaceTrackNoIR/tracker.h @@ -35,9 +35,9 @@ #define DIRECTINPUT_VERSION 0x0800 #include -#include "FTServer.h" // Freetrack-server +//#include "FTServer.h" // Freetrack-server //#include "FGServer.h" // FlightGear-server -#include "PPJoyServer.h" // Virtual Joystick +//#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) -- cgit v1.2.3