summaryrefslogtreecommitdiffhomepage
path: root/FaceTrackNoIR/FTServer.cpp
diff options
context:
space:
mode:
authorWim Vriend <facetracknoir@gmail.com>2010-12-24 18:58:17 +0000
committerWim Vriend <facetracknoir@gmail.com>2010-12-24 18:58:17 +0000
commite007864f430012ac03455142b3910760df03987d (patch)
treeed1d358f61ffbd19788670da593e17a20b2a276e /FaceTrackNoIR/FTServer.cpp
parent53231950ec75f67a931d47b78987a6bcac9d2eb0 (diff)
Removed QThread reference of protocol server-code.
Have still to adapt some of them though... git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@32 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb
Diffstat (limited to 'FaceTrackNoIR/FTServer.cpp')
-rw-r--r--FaceTrackNoIR/FTServer.cpp137
1 files changed, 55 insertions, 82 deletions
diff --git a/FaceTrackNoIR/FTServer.cpp b/FaceTrackNoIR/FTServer.cpp
index 27808343..7814c2d3 100644
--- a/FaceTrackNoIR/FTServer.cpp
+++ b/FaceTrackNoIR/FTServer.cpp
@@ -41,110 +41,77 @@
//
/*
Modifications (last one on top):
- 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!
+ 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() {
-
- // Create events
- m_StopThread = CreateEvent(0, TRUE, FALSE, 0);
- m_WaitThread = CreateEvent(0, TRUE, FALSE, 0);
-
ProgramName = "";
}
/** destructor **/
FTServer::~FTServer() {
- // Trigger thread to stop
- ::SetEvent(m_StopThread);
-
- // Wait until thread finished
- ::WaitForSingleObject(m_WaitThread, INFINITE);
-
- // Close handles
- ::CloseHandle(m_StopThread);
- ::CloseHandle(m_WaitThread);
-
//
// Free the DLL
//
FTClientLib.unload();
- //if( aDLLHandle != INVALID_HANDLE_VALUE )
- // FreeLibrary( (HMODULE) aDLLHandle );
- //terminates the QThread and waits for finishing the QThread
- terminate();
- wait();
}
-/** QThread run @override **/
-void FTServer::run() {
-
- if (pMemData != NULL) {
- pMemData->data.DataID = 1;
- pMemData->data.CamWidth = 100;
- pMemData->data.CamHeight = 250;
- }
-
- forever
- {
- // Check event for stop thread
- if(::WaitForSingleObject(m_StopThread, 0) == WAIT_OBJECT_0)
- {
- // Set event
- ::SetEvent(m_WaitThread);
- return;
- }
-
- 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;
+//
+// Update Headpose in Game.
+//
+void FTServer::sendHeadposeToGame() {
- //
- // 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;
+ //
+ // Check if the pointer is OK and wait for the Mutex.
+ //
+ if ( (pMemData != NULL) && (WaitForSingleObject(hFTMutex, 100) == WAIT_OBJECT_0) ) {
- //
- // 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;
+ //
+ // 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;
- //qDebug() << "FTServer says: pMemData.DataID =" << pMemData->data.DataID;
- //qDebug() << "FTServer says: ProgramName =" << pMemData->ProgramName;
- ReleaseMutex(hFTMutex);
- }
+ //
+ // 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;
- // just for lower cpu load
- msleep(15);
- yieldCurrentThread();
- pMemData->data.DataID += 1;
+ //
+ // 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;
}
//
@@ -192,6 +159,12 @@ bool FTServer::FTCreateMapping(HANDLE handle)
return false;
}
+ if (pMemData != NULL) {
+ pMemData->data.DataID = 1;
+ pMemData->data.CamWidth = 100;
+ pMemData->data.CamHeight = 250;
+ }
+
return true;
}