From b07a116670236fe13262f04d618b11460f4e4b73 Mon Sep 17 00:00:00 2001
From: Wim Vriend <facetracknoir@gmail.com>
Date: Thu, 7 Apr 2011 17:43:13 +0000
Subject: PPJoy in DLL

git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@64 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb
---
 FTNoIR_Protocol_FT/FTNoIR_FTcontrols.ui      | 194 ++++++++++++
 FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.cpp    | 443 +++++++++++++++++++++++++++
 FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.h      | 102 ++++++
 FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.vcproj | 332 ++++++++++++++++++++
 FTNoIR_Protocol_FT/FTTypes.h                 |  85 +++++
 5 files changed, 1156 insertions(+)
 create mode 100644 FTNoIR_Protocol_FT/FTNoIR_FTcontrols.ui
 create mode 100644 FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.cpp
 create mode 100644 FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.h
 create mode 100644 FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.vcproj
 create mode 100644 FTNoIR_Protocol_FT/FTTypes.h

diff --git a/FTNoIR_Protocol_FT/FTNoIR_FTcontrols.ui b/FTNoIR_Protocol_FT/FTNoIR_FTcontrols.ui
new file mode 100644
index 00000000..89b5d712
--- /dev/null
+++ b/FTNoIR_Protocol_FT/FTNoIR_FTcontrols.ui
@@ -0,0 +1,194 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>UICFTControls</class>
+ <widget class="QWidget" name="UICFTControls">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>411</width>
+    <height>157</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>FTIR settings FaceTrackNoIR</string>
+  </property>
+  <property name="windowIcon">
+   <iconset>
+    <normaloff>images/FaceTrackNoIR.ico</normaloff>images/FaceTrackNoIR.ico</iconset>
+  </property>
+  <property name="layoutDirection">
+   <enum>Qt::LeftToRight</enum>
+  </property>
+  <property name="autoFillBackground">
+   <bool>false</bool>
+  </property>
+  <layout class="QVBoxLayout" name="_vertical_layout">
+   <item>
+    <layout class="QHBoxLayout">
+     <item>
+      <spacer name="horizontalSpacer_3">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QCheckBox" name="chkTIRViews">
+       <property name="layoutDirection">
+        <enum>Qt::RightToLeft</enum>
+       </property>
+       <property name="text">
+        <string>Use TIRViews</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item>
+    <layout class="QVBoxLayout" name="verticalLayout">
+     <item>
+      <widget class="QLabel" name="label_2">
+       <property name="text">
+        <string>TIRViews is only required for some older games (like CFS3).</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLabel" name="label">
+       <property name="text">
+        <string>For it to work, TIRViews.dll must be placed in the FaceTrackNoIR program folder.</string>
+       </property>
+       <property name="wordWrap">
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLabel" name="label_3">
+       <property name="text">
+        <string>If the checkbox is disabled, the DLL was not found.</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <spacer name="horizontalSpacer_2">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout_2">
+       <property name="sizeConstraint">
+        <enum>QLayout::SetDefaultConstraint</enum>
+       </property>
+       <item>
+        <widget class="QPushButton" name="btnOK">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="minimumSize">
+          <size>
+           <width>100</width>
+           <height>0</height>
+          </size>
+         </property>
+         <property name="maximumSize">
+          <size>
+           <width>100</width>
+           <height>16777215</height>
+          </size>
+         </property>
+         <property name="text">
+          <string>OK</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QPushButton" name="btnCancel">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="minimumSize">
+          <size>
+           <width>100</width>
+           <height>0</height>
+          </size>
+         </property>
+         <property name="maximumSize">
+          <size>
+           <width>100</width>
+           <height>16777215</height>
+          </size>
+         </property>
+         <property name="text">
+          <string>Cancel</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeType">
+        <enum>QSizePolicy::Fixed</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>10</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+ <slots>
+  <slot>startEngineClicked()</slot>
+  <slot>stopEngineClicked()</slot>
+  <slot>cameraSettingsClicked()</slot>
+ </slots>
+</ui>
diff --git a/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.cpp b/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.cpp
new file mode 100644
index 00000000..4d0ef950
--- /dev/null
+++ b/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.cpp
@@ -0,0 +1,443 @@
+/********************************************************************************
+* 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 <http://www.gnu.org/licenses/>.				*
+*																				*
+* FTServer		FTServer is the Class, that communicates headpose-data			*
+*				to games, using the FreeTrackClient.dll.	         			*
+********************************************************************************/
+/*
+	Modifications (last one on top):
+	20110401 - WVR: Moved protocol to a DLL, convenient for installation etc.
+	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 "ftnoir_protocol_ft.h"
+
+/** constructor **/
+FTNoIR_Protocol_FT::FTNoIR_Protocol_FT()
+{
+	loadSettings();
+	ProgramName = "";
+}
+
+/** destructor **/
+FTNoIR_Protocol_FT::~FTNoIR_Protocol_FT()
+{
+	//
+	// Destroy the File-mapping
+	//
+	FTDestroyMapping();
+
+	//
+	// Free the DLL's
+	//
+	FTClientLib.unload();
+}
+
+/** helper to Auto-destruct **/
+void FTNoIR_Protocol_FT::Release()
+{
+    delete this;
+}
+
+void FTNoIR_Protocol_FT::Initialize()
+{
+	return;
+}
+
+//
+// Load the current Settings from the currently 'active' INI-file.
+//
+void FTNoIR_Protocol_FT::loadSettings() {
+}
+
+//
+// Update Headpose in Game.
+//
+void FTNoIR_Protocol_FT::sendHeadposeToGame( T6DOF *headpose ) {
+float virtPosX;
+float virtPosY;
+float virtPosZ;
+
+float virtRotX;
+float virtRotY;
+float virtRotZ;
+
+float headPosX;
+float headPosY;
+float headPosZ;
+
+float headRotX;
+float headRotY;
+float headRotZ;
+
+	//
+	// Scale the Raw measurements to the client measurements.
+	//
+	headRotX = getRadsFromDegrees(headpose->position.pitch);
+	headRotY = getRadsFromDegrees(headpose->position.yaw);
+	headRotZ = getRadsFromDegrees(headpose->position.roll);
+	headPosX = headpose->position.x * 10;
+	headPosY = headpose->position.y * 10;
+	headPosZ = headpose->position.z * 10;
+
+	virtRotX = getRadsFromDegrees(headpose->position.pitch);
+	virtRotY = getRadsFromDegrees(headpose->position.yaw);
+	virtRotZ = getRadsFromDegrees(headpose->position.roll);
+	virtPosX = headpose->position.x * 10;
+	virtPosY = headpose->position.y * 10;
+	virtPosZ = headpose->position.z * 10;
+
+	//
+	// 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;
+
+		//
+		//
+		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;
+}
+
+//
+// Check if the Client DLL exists and load it (to test it), if so.
+// Returns 'true' if all seems OK.
+//
+bool FTNoIR_Protocol_FT::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 );
+}
+
+//
+// Create a memory-mapping to the TrackIR data.
+// It contains the tracking data, a handle to the main-window and the program-name of the Game!
+//
+//
+bool FTNoIR_Protocol_FT::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 FTNoIR_Protocol_FT::FTDestroyMapping()
+{
+	if ( pMemData != NULL ) {
+		UnmapViewOfFile ( pMemData );
+	}
+	
+	CloseHandle( hFTMutex );
+	CloseHandle( hFTMemMap );
+	hFTMemMap = 0;
+
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+// Factory function that creates instances if the Protocol object.
+
+// Export both decorated and undecorated names.
+//   GetProtocol     - Undecorated name, which can be easily used with GetProcAddress
+//                Win32 API function.
+//   _GetProtocol@0  - Common name decoration for __stdcall functions in C language.
+#pragma comment(linker, "/export:GetProtocol=_GetProtocol@0")
+
+FTNOIR_PROTOCOL_BASE_EXPORT PROTOCOLHANDLE __stdcall GetProtocol()
+{
+	return new FTNoIR_Protocol_FT;
+}
+
+//*******************************************************************************************************
+// FaceTrackNoIR Client Settings-dialog.
+//*******************************************************************************************************
+
+//
+// Constructor for server-settings-dialog
+//
+FTControls::FTControls() :
+QWidget()
+{
+	QString aFileName;														// File Path and Name
+
+	ui.setupUi( this );
+
+	// 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()));
+
+	// Load the settings from the current .INI-file
+	loadSettings();
+}
+
+//
+// Destructor for server-dialog
+//
+FTControls::~FTControls() {
+	qDebug() << "~FTControls() says: started";
+}
+
+void FTControls::Release()
+{
+    delete this;
+}
+
+//
+// Initialize tracker-client-dialog
+//
+void FTControls::Initialize(QWidget *parent) {
+
+	QPoint offsetpos(100, 100);
+	if (parent) {
+		this->move(parent->pos() + offsetpos);
+	}
+	show();
+}
+
+//
+// OK clicked on server-dialog
+//
+void FTControls::doOK() {
+	save();
+	this->close();
+}
+
+// override show event
+void FTControls::showEvent ( QShowEvent * event ) {
+	loadSettings();
+}
+
+//
+// Cancel clicked on server-dialog
+//
+void FTControls::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 FTControls::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 ( "FT" );
+	ui.chkTIRViews->setChecked (iniFile.value ( "useTIRViews", 0 ).toBool());
+	iniFile.endGroup ();
+
+	settingsDirty = false;
+}
+
+//
+// Save the current Settings to the currently 'active' INI-file.
+//
+void FTControls::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 ( "FT" );
+	iniFile.setValue ( "useTIRViews", ui.chkTIRViews->isChecked() );
+	iniFile.endGroup ();
+
+	settingsDirty = false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Factory function that creates instances if the Protocol-settings dialog object.
+
+// Export both decorated and undecorated names.
+//   GetProtocolDialog     - Undecorated name, which can be easily used with GetProcAddress
+//                          Win32 API function.
+//   _GetProtocolDialog@0  - Common name decoration for __stdcall functions in C language.
+#pragma comment(linker, "/export:GetProtocolDialog=_GetProtocolDialog@0")
+
+FTNOIR_PROTOCOL_BASE_EXPORT PROTOCOLDIALOGHANDLE __stdcall GetProtocolDialog( )
+{
+	return new FTControls;
+}
diff --git a/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.h b/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.h
new file mode 100644
index 00000000..7b23fcba
--- /dev/null
+++ b/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.h
@@ -0,0 +1,102 @@
+/********************************************************************************
+* FaceTrackNoIR		This program is a private project of 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 <http://www.gnu.org/licenses/>.				*
+*																				*
+* FTServer		FTServer is the Class, that communicates headpose-data			*
+*				to games, using the FreeTrackClient.dll.		         		*
+********************************************************************************/
+#pragma once
+#ifndef INCLUDED_FTSERVER_H
+#define INCLUDED_FTSERVER_H
+
+#include "..\ftnoir_protocol_base\ftnoir_protocol_base.h"
+#include "ui_FTNoIR_FTcontrols.h"
+#include "FTTypes.h"
+#include <QMessageBox>
+#include <QSettings>
+#include <QLibrary>
+#include <QProcess>
+#include <QDebug>
+#include <QFile>
+#include "Windows.h"
+//#include "math.h"
+
+typedef char *(WINAPI *importProvider)(void);
+
+class FTNoIR_Protocol_FT : public IProtocol
+{
+public:
+	FTNoIR_Protocol_FT();
+	~FTNoIR_Protocol_FT();
+
+	void Release();
+    void Initialize();
+
+	bool checkServerInstallationOK( HANDLE handle );
+	void sendHeadposeToGame( T6DOF *headpose );
+
+private:
+	bool FTCreateMapping(HANDLE handle);
+	void FTDestroyMapping();
+
+	HANDLE hFTMemMap;
+	FTMemMap *pMemData;
+	HANDLE hFTMutex;
+
+	// Private properties
+	QString ProgramName;
+	QLibrary FTClientLib;
+
+	float getRadsFromDegrees ( float degrees ) { return (degrees * 0.017453f); }
+	void loadSettings();
+
+};
+
+// Widget that has controls for FTNoIR protocol client-settings.
+class FTControls: public QWidget, Ui::UICFTControls, public IProtocolDialog
+{
+    Q_OBJECT
+public:
+
+	explicit FTControls();
+    virtual ~FTControls();
+	void showEvent ( QShowEvent * event );
+
+	void Release();											// Member functions which are accessible from outside the DLL
+    void Initialize(QWidget *parent);
+
+private:
+	Ui::UICFTControls ui;
+	void loadSettings();
+	void save();
+
+	/** helper **/
+	bool settingsDirty;
+
+private slots:
+	void doOK();
+	void doCancel();
+	void settingChanged() { settingsDirty = true; };
+};
+
+#endif//INCLUDED_FTSERVER_H
+//END
diff --git a/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.vcproj b/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.vcproj
new file mode 100644
index 00000000..eb42b4c8
--- /dev/null
+++ b/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.vcproj
@@ -0,0 +1,332 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="8.00"
+	Name="FTNoIR_Protocol_FT"
+	ProjectGUID="{FE2FF09B-207D-468C-9763-23861956F388}"
+	RootNamespace="FTNoIR_Protocol_FT"
+	Keyword="Qt4VSv1.0"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="$(SolutionDir)/bin"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="2"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalIncludeDirectories=".\GeneratedFiles;&quot;$(QTDIR)\include&quot;;&quot;.\GeneratedFiles\$(ConfigurationName)&quot;;&quot;$(QTDIR)\include\qtmain&quot;;&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(QTDIR)\include\QtNetwork&quot;;&quot;$(QTDIR)\include\QtGui&quot;;.\"
+				PreprocessorDefinitions="UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_THREAD_SUPPORT;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;FTNOIR_PROTOCOL_BASE_LIB"
+				RuntimeLibrary="2"
+				TreatWChar_tAsBuiltInType="false"
+				DebugInformationFormat="0"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="qtmain.lib QtCore4.lib QtGui4.lib"
+				OutputFile="$(OutDir)\$(ProjectName).dll"
+				AdditionalLibraryDirectories="$(QTDIR)\lib"
+				GenerateDebugInformation="false"
+				SubSystem="2"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="2"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories=".\GeneratedFiles;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\qtmain;$(QTDIR)\include\QtCore;.\"
+				PreprocessorDefinitions="UNICODE,WIN32,QT_LARGEFILE_SUPPORT,QT_THREAD_SUPPORT,QT_CORE_LIB,FTNOIR_PROTOCOL_FT_LIB"
+				RuntimeLibrary="3"
+				TreatWChar_tAsBuiltInType="false"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="qtmaind.lib QtCored4.lib"
+				OutputFile="$(OutDir)\$(ProjectName).dll"
+				AdditionalLibraryDirectories="$(QTDIR)\lib"
+				GenerateDebugInformation="true"
+				SubSystem="2"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;cxx;c;def"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+			>
+			<File
+				RelativePath=".\ftnoir_Protocol_FT.cpp"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+			>
+			<File
+				RelativePath="..\FTNoIR_Protocol_Base\ftnoir_Protocol_base.h"
+				>
+			</File>
+			<File
+				RelativePath="..\FTNoIR_Protocol_Base\ftnoir_Protocol_base_global.h"
+				>
+			</File>
+			<File
+				RelativePath=".\FTNoIR_Protocol_FT.h"
+				>
+				<FileConfiguration
+					Name="Release|Win32"
+					>
+					<Tool
+						Name="VCCustomBuildTool"
+						Description="Moc&apos;ing $(InputFileName)..."
+						CommandLine="&quot;$(QTDIR)\bin\moc.exe&quot;   -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_THREAD_SUPPORT -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DFTNOIR_PROTOCOL_BASE_LIB -D_WINDLL  -I&quot;.\GeneratedFiles\.&quot; -I&quot;$(QTDIR)\include\.&quot; -I&quot;.\GeneratedFiles\$(ConfigurationName)\.&quot; -I&quot;$(QTDIR)\include\qtmain\.&quot; -I&quot;$(QTDIR)\include\QtCore\.&quot; -I&quot;$(QTDIR)\include\QtNetwork\.&quot; -I&quot;$(QTDIR)\include\QtGui\.&quot; -I&quot;.\.&quot; &quot;.\FTNoIR_Protocol_FT.h&quot; -o &quot;.\GeneratedFiles\$(ConfigurationName)\moc_$(InputName).cpp&quot;&#x0D;&#x0A;"
+						AdditionalDependencies="&quot;$(QTDIR)\bin\moc.exe&quot;;$(InputPath)"
+						Outputs="&quot;.\GeneratedFiles\$(ConfigurationName)\moc_$(InputName).cpp&quot;"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Debug|Win32"
+					>
+					<Tool
+						Name="VCCustomBuildTool"
+						Description="Moc&apos;ing $(InputFileName)..."
+						CommandLine="&quot;$(QTDIR)\bin\moc.exe&quot;   -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_THREAD_SUPPORT -DQT_CORE_LIB -DFTNOIR_PROTOCOL_FT_LIB -D_WINDLL  -I&quot;.\GeneratedFiles\.&quot; -I&quot;$(QTDIR)\include\.&quot; -I&quot;.\GeneratedFiles\$(ConfigurationName)\.&quot; -I&quot;$(QTDIR)\include\qtmain\.&quot; -I&quot;$(QTDIR)\include\QtCore\.&quot; -I&quot;.\.&quot; &quot;.\FTNoIR_Protocol_FT.h&quot; -o &quot;.\GeneratedFiles\$(ConfigurationName)\moc_$(InputName).cpp&quot;&#x0D;&#x0A;"
+						AdditionalDependencies="&quot;$(QTDIR)\bin\moc.exe&quot;;$(InputPath)"
+						Outputs="&quot;.\GeneratedFiles\$(ConfigurationName)\moc_$(InputName).cpp&quot;"
+					/>
+				</FileConfiguration>
+			</File>
+			<File
+				RelativePath=".\FTTypes.h"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Form Files"
+			Filter="ui"
+			UniqueIdentifier="{99349809-55BA-4b9d-BF79-8FDBB0286EB3}"
+			>
+			<File
+				RelativePath=".\FTNoIR_FTcontrols.ui"
+				>
+				<FileConfiguration
+					Name="Release|Win32"
+					>
+					<Tool
+						Name="VCCustomBuildTool"
+						Description="Uic&apos;ing $(InputFileName)..."
+						CommandLine="&quot;$(QTDIR)\bin\uic.exe&quot; -o &quot;.\GeneratedFiles\ui_$(InputName).h&quot; &quot;$(InputPath)&quot;&#x0D;&#x0A;"
+						AdditionalDependencies="$(QTDIR)\bin\uic.exe"
+						Outputs="&quot;.\GeneratedFiles\ui_$(InputName).h&quot;"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Debug|Win32"
+					>
+					<Tool
+						Name="VCCustomBuildTool"
+						Description="Uic&apos;ing $(InputFileName)..."
+						CommandLine="&quot;$(QTDIR)\bin\uic.exe&quot; -o &quot;.\GeneratedFiles\ui_$(InputName).h&quot; &quot;$(InputPath)&quot;&#x0D;&#x0A;"
+						AdditionalDependencies="$(QTDIR)\bin\uic.exe"
+						Outputs="&quot;.\GeneratedFiles\ui_$(InputName).h&quot;"
+					/>
+				</FileConfiguration>
+			</File>
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="qrc;*"
+			UniqueIdentifier="{D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E}"
+			ParseFiles="false"
+			>
+		</Filter>
+		<Filter
+			Name="Generated Files"
+			Filter="moc;h;cpp"
+			UniqueIdentifier="{71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11}"
+			SourceControlFiles="false"
+			>
+			<File
+				RelativePath=".\GeneratedFiles\ui_FTNoIR_FTcontrols.h"
+				>
+			</File>
+			<Filter
+				Name="Release"
+				Filter="cpp;moc"
+				SourceControlFiles="false"
+				>
+				<File
+					RelativePath=".\GeneratedFiles\Release\moc_FTNoIR_Protocol_FT.cpp"
+					>
+					<FileConfiguration
+						Name="Debug|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+				</File>
+			</Filter>
+			<Filter
+				Name="Debug"
+				Filter="cpp;moc"
+				SourceControlFiles="false"
+				>
+				<File
+					RelativePath=".\GeneratedFiles\Debug\moc_FTNoIR_Protocol_FT.cpp"
+					>
+					<FileConfiguration
+						Name="Release|Win32"
+						ExcludedFromBuild="true"
+						>
+						<Tool
+							Name="VCCLCompilerTool"
+						/>
+					</FileConfiguration>
+				</File>
+			</Filter>
+		</Filter>
+	</Files>
+	<Globals>
+		<Global
+			Name="lupdateOnBuild"
+			Value="0"
+		/>
+		<Global
+			Name="MocDir"
+			Value=".\GeneratedFiles\$(ConfigurationName)"
+		/>
+		<Global
+			Name="MocOptions"
+			Value=""
+		/>
+		<Global
+			Name="QtVersion Win32"
+			Value="QT462_VS2005"
+		/>
+		<Global
+			Name="RccDir"
+			Value=".\GeneratedFiles"
+		/>
+		<Global
+			Name="UicDir"
+			Value=".\GeneratedFiles"
+		/>
+	</Globals>
+</VisualStudioProject>
diff --git a/FTNoIR_Protocol_FT/FTTypes.h b/FTNoIR_Protocol_FT/FTTypes.h
new file mode 100644
index 00000000..a6dcb6c9
--- /dev/null
+++ b/FTNoIR_Protocol_FT/FTTypes.h
@@ -0,0 +1,85 @@
+/********************************************************************************
+* 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				<http://www.free-track.net>								*
+*																				*
+* 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 <http://www.gnu.org/licenses/>.				*
+*																				*
+* 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 <tchar.h>
+#include <stdio.h>
+
+//#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
-- 
cgit v1.2.3