From 010d82e9392bd2fb5cafe6fbae03c9cdc301a2f8 Mon Sep 17 00:00:00 2001 From: Wim Vriend Date: Sat, 4 Jun 2011 12:37:46 +0000 Subject: Eagle Dynamics API implemented, added some 'nice to haves'. git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@87 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb --- FTNoIR_Protocol_MOUSE/FTNoIR_Protocol_MOUSE.cpp | 35 +++++++++++++++++++------ FTNoIR_Protocol_MOUSE/FTNoIR_Protocol_MOUSE.h | 5 +++- 2 files changed, 31 insertions(+), 9 deletions(-) (limited to 'FTNoIR_Protocol_MOUSE') diff --git a/FTNoIR_Protocol_MOUSE/FTNoIR_Protocol_MOUSE.cpp b/FTNoIR_Protocol_MOUSE/FTNoIR_Protocol_MOUSE.cpp index 31749b3d..2104c09f 100644 --- a/FTNoIR_Protocol_MOUSE/FTNoIR_Protocol_MOUSE.cpp +++ b/FTNoIR_Protocol_MOUSE/FTNoIR_Protocol_MOUSE.cpp @@ -40,6 +40,8 @@ FTNoIR_Protocol_MOUSE::FTNoIR_Protocol_MOUSE() prev_fMouse_X = 0.0f; prev_fMouse_Y = 0.0f; prev_fMouse_Wheel = 0.0f; + frame_delay = 0; + loadSettings(); } @@ -217,16 +219,22 @@ float fMouse_Wheel; MouseStruct.mi.dx = scale2AnalogLimits(-1.0f * fMouse_X * mouse_X_factor, -180, 180); MouseStruct.mi.dy = scale2AnalogLimits(fMouse_Y * mouse_Y_factor, -180, 180); MouseStruct.mi.mouseData = mouse_Wheel_factor * (fMouse_Wheel - prev_fMouse_Wheel); + + frame_delay = 9999; // Seems no problem with Absolute positioning break; case FTN_RELATIVE: MouseStruct.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_WHEEL; - MouseStruct.mi.dx = mouse_X_factor * (fMouse_X - prev_fMouse_X); + MouseStruct.mi.dx = -1.0f * mouse_X_factor * (fMouse_X - prev_fMouse_X); MouseStruct.mi.dy = mouse_Y_factor * (fMouse_Y - prev_fMouse_Y); - MouseStruct.mi.mouseData = mouse_Wheel_factor * (fMouse_Wheel - prev_fMouse_Wheel); + MouseStruct.mi.mouseData = - 1.0f * mouse_Wheel_factor * (fMouse_Wheel - prev_fMouse_Wheel); + + frame_delay += 1; // Add 1 to the counter + qDebug() << "sendHeadposeToGame(): FTN_RELATIVE x = " << MouseStruct.mi.dx << ", y = " << MouseStruct.mi.dy; break; default: + Mouse_Style = FTN_ABSOLUTE; // Force to a valid value... break; } @@ -234,13 +242,15 @@ float fMouse_Wheel; // Only send Input, when it has changed. // This releases the Mouse, when tracking is stopped (for a while). // - if ((prev_fMouse_X != fMouse_X) || (prev_fMouse_Y != fMouse_Y) || (prev_fMouse_Wheel != fMouse_Wheel)) { - SendInput(1, &MouseStruct, sizeof(MouseStruct)); - } + if (frame_delay > 10) { + if ((prev_fMouse_X != fMouse_X) || (prev_fMouse_Y != fMouse_Y) || (prev_fMouse_Wheel != fMouse_Wheel)) { + SendInput(1, &MouseStruct, sizeof(MouseStruct)); + } - prev_fMouse_X = fMouse_X; - prev_fMouse_Y = fMouse_Y; - prev_fMouse_Wheel = fMouse_Wheel; + prev_fMouse_X = fMouse_X; + prev_fMouse_Y = fMouse_Y; + prev_fMouse_Wheel = fMouse_Wheel; + } } // @@ -252,6 +262,15 @@ bool FTNoIR_Protocol_MOUSE::checkServerInstallationOK( HANDLE handle ) return true; } +// +// Return a name, if present the name from the Game, that is connected... +// +void FTNoIR_Protocol_MOUSE::getNameFromGame( char *dest ) +{ + sprintf_s(dest, 99, "Mouse"); + return; +} + //////////////////////////////////////////////////////////////////////////////// // Factory function that creates instances if the Protocol object. diff --git a/FTNoIR_Protocol_MOUSE/FTNoIR_Protocol_MOUSE.h b/FTNoIR_Protocol_MOUSE/FTNoIR_Protocol_MOUSE.h index b53fb3e4..ce267d87 100644 --- a/FTNoIR_Protocol_MOUSE/FTNoIR_Protocol_MOUSE.h +++ b/FTNoIR_Protocol_MOUSE/FTNoIR_Protocol_MOUSE.h @@ -54,7 +54,7 @@ enum FTN_AngleName { enum FTN_MouseStyle { FTN_ABSOLUTE = 0, - FTN_RELATIVE = 2 + FTN_RELATIVE = 1 }; @@ -69,6 +69,7 @@ public: bool checkServerInstallationOK( HANDLE handle ); void sendHeadposeToGame( T6DOF *headpose ); + void getNameFromGame( char *dest ); // Take care dest can handle up to 100 chars... private: HANDLE h; @@ -86,6 +87,8 @@ private: float prev_fMouse_Wheel; float mouse_Wheel_factor; // Sensitivity factor + int frame_delay; // Number of frames to delay SendInput (too fast, too furious?) + long scale2AnalogLimits( float x, float min_x, float max_x ); void loadSettings(); -- cgit v1.2.3