From 101b7c956a764cec69b84bb86635822bac3fc01c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 24 Jun 2013 23:49:57 +0200 Subject: Fix mouse protocol, remove most of the options for simplicity's sake --- ftnoir_protocol_mouse/ftnoir_mousecontrols.ui | 336 +-------------------- ftnoir_protocol_mouse/ftnoir_protocol_mouse.cpp | 85 ++---- ftnoir_protocol_mouse/ftnoir_protocol_mouse.h | 22 +- .../ftnoir_protocol_mouse_dialog.cpp | 64 +--- 4 files changed, 43 insertions(+), 464 deletions(-) (limited to 'ftnoir_protocol_mouse') diff --git a/ftnoir_protocol_mouse/ftnoir_mousecontrols.ui b/ftnoir_protocol_mouse/ftnoir_mousecontrols.ui index 1a7712f2..8794e9cd 100644 --- a/ftnoir_protocol_mouse/ftnoir_mousecontrols.ui +++ b/ftnoir_protocol_mouse/ftnoir_mousecontrols.ui @@ -6,15 +6,15 @@ 0 0 - 462 - 299 + 250 + 99 MouseLook settings FaceTrackNoIR - + :/images/Mouse.png:/images/Mouse.png @@ -26,62 +26,8 @@ - - - - - 0 - 0 - - - - Mouse style: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - false - - - - - - - - 80 - 16777215 - - - - Select Number - - - QComboBox::InsertAlphabetically - - - - - - - - 0 - 0 - - - - Map mouse X to: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - false - - - - + 80 @@ -96,7 +42,7 @@ - + @@ -115,8 +61,8 @@ - - + + 0 @@ -124,7 +70,7 @@ - Map mouse Wheel to: + Map mouse X to: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -134,24 +80,8 @@ - - - - - 80 - 16777215 - - - - Select Number - - - QComboBox::InsertAlphabetically - - - - - + + 80 @@ -166,149 +96,6 @@ - - - - - 150 - 16777215 - - - - 50 - - - Qt::Horizontal - - - - - - - - 150 - 16777215 - - - - 50 - - - Qt::Horizontal - - - - - - - - 150 - 16777215 - - - - 50 - - - Qt::Horizontal - - - - - - - Sensitivity (10=1x): - - - - - - - 50 - - - - - - - 50 - - - - - - - 50 - - - - - - - - 0 - 0 - - - - Use Virtual Desk: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - false - - - - - - - - 0 - 20 - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - Most games (like First Person Shooters) support 'relative' mouse look. - - - - - - - - - - - Mouse sensitivity can also be influenced via the Windows Mouse settings. - - - @@ -403,107 +190,8 @@ - - - - - - slideSensX - valueChanged(int) - spinSensX - setValue(int) - - - 334 - 44 - - - 445 - 46 - - - - - slideSensY - valueChanged(int) - spinSensY - setValue(int) - - - 338 - 73 - - - 450 - 70 - - - - - slideSensWheel - valueChanged(int) - spinSensWheel - setValue(int) - - - 334 - 98 - - - 445 - 96 - - - - - spinSensX - valueChanged(int) - slideSensX - setValue(int) - - - 440 - 37 - - - 364 - 41 - - - - - spinSensY - valueChanged(int) - slideSensY - setValue(int) - - - 441 - 69 - - - 347 - 73 - - - - - spinSensWheel - valueChanged(int) - slideSensWheel - setValue(int) - - - 459 - 99 - - - 350 - 99 - - - - + + startEngineClicked() stopEngineClicked() diff --git a/ftnoir_protocol_mouse/ftnoir_protocol_mouse.cpp b/ftnoir_protocol_mouse/ftnoir_protocol_mouse.cpp index 40558254..187da752 100644 --- a/ftnoir_protocol_mouse/ftnoir_protocol_mouse.cpp +++ b/ftnoir_protocol_mouse/ftnoir_protocol_mouse.cpp @@ -38,10 +38,6 @@ /** constructor **/ FTNoIR_Protocol::FTNoIR_Protocol() { - prev_fMouse_X = 0.0f; - prev_fMouse_Y = 0.0f; - prev_fMouse_Wheel = 0.0f; - frame_delay = 0; loadSettings(); } @@ -50,16 +46,6 @@ FTNoIR_Protocol::~FTNoIR_Protocol() { } -// -// Scale the measured value to the Joystick values -// -long FTNoIR_Protocol::scale2AnalogLimits( float x, float min_x, float max_x ) { -double y; - - y = ((MOUSE_AXIS_MAX - MOUSE_AXIS_MIN)/(max_x - min_x)) * x + ((MOUSE_AXIS_MAX - MOUSE_AXIS_MIN)/2) + MOUSE_AXIS_MIN; - return (long) y; -} - // // Load the current Settings from the currently 'active' INI-file. // @@ -70,17 +56,8 @@ void FTNoIR_Protocol::loadSettings() { QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) iniFile.beginGroup ( "Mouse" ); - Mouse_Style = (FTN_MouseStyle) (iniFile.value ( "Style", 1 ).toInt() - 1); - Mouse_X = (FTN_AngleName) (iniFile.value ( "Mouse_X", 1 ).toInt() - 1); - Mouse_Y = (FTN_AngleName) (iniFile.value ( "Mouse_Y", 1 ).toInt() - 1); - Mouse_Wheel = (FTN_AngleName) (iniFile.value ( "Mouse_Wheel", 1 ).toInt() - 1); - - mouse_X_factor = iniFile.value("SensX", 10).toFloat() / 10.0f; - mouse_Y_factor = iniFile.value("SensY", 10).toFloat() / 10.0f; - mouse_Wheel_factor = iniFile.value("SensWheel", 10).toFloat() / 10.0f; - - useVirtualDesk = iniFile.value ( "useVirtualDesk", 0 ).toBool(); - + Mouse_X = (FTN_AngleName) (iniFile.value ( "Mouse_X", 0 ).toInt()); + Mouse_Y = (FTN_AngleName) (iniFile.value ( "Mouse_Y", 0 ).toInt()); iniFile.endGroup (); } @@ -88,48 +65,22 @@ void FTNoIR_Protocol::loadSettings() { // Update Headpose in Game. // void FTNoIR_Protocol::sendHeadposeToGame(double *headpose, double *rawheadpose ) { -float fMouse_X = 0; // The actual value -float fMouse_Y = 0; -float fMouse_Wheel = 0; - - - // - // Determine which of the 6DOF's is used. - // The rotations are from -180 to +180 and the translations from -50cm to +50cm. - // Let's scale the translations to the degrees for simplicity sake... - // - - if (Mouse_X > 0 && Mouse_X < 6+1) - fMouse_X = headpose[Mouse_X-1]; - - if (Mouse_X < 3+1 && Mouse_X > 0) - fMouse_X *= 3; - - if (Mouse_Y > 0 && Mouse_Y < 6+1) - fMouse_Y = headpose[Mouse_Y-1]; - - if (Mouse_Y < 3+1 && Mouse_Y > 0) - fMouse_Y *= 3; - - if (Mouse_Wheel > 0 && Mouse_Wheel < 6+1) - fMouse_Wheel = headpose[Mouse_Wheel-1]; - - if (Mouse_Wheel < 3+1 && Mouse_Wheel > 0) - fMouse_Wheel *= 3; - - // - // Only send Input, when it has changed. - // This releases the Mouse, when tracking is stopped (for a while). - // - 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; - } + float fMouse_X = 0; + float fMouse_Y = 0; + + if (Mouse_X > 0 && Mouse_X < 6) + fMouse_X = headpose[Mouse_X-1] / (Mouse_X < 3 ? 100 : 180); + + if (Mouse_Y > 0 && Mouse_Y < 6) + fMouse_Y = headpose[Mouse_Y-1] / (Mouse_Y < 3 ? 100 : 180); + + RECT desktop; + const HWND hDesktop = GetDesktopWindow(); + if (hDesktop != NULL && GetWindowRect(hDesktop, &desktop)) { + fMouse_X *= desktop.right; + fMouse_Y *= desktop.bottom; + SetCursorPos(fMouse_X + desktop.right/2, fMouse_Y + desktop.bottom/2); + } } // diff --git a/ftnoir_protocol_mouse/ftnoir_protocol_mouse.h b/ftnoir_protocol_mouse/ftnoir_protocol_mouse.h index d5c614fa..14719540 100644 --- a/ftnoir_protocol_mouse/ftnoir_protocol_mouse.h +++ b/ftnoir_protocol_mouse/ftnoir_protocol_mouse.h @@ -46,20 +46,14 @@ #define MOUSE_AXIS_MAX 65535 enum FTN_AngleName { - FTN_PITCH = RX, - FTN_YAW = TY, + FTN_YAW = RX, + FTN_PITCH = RY, FTN_ROLL = RZ, FTN_X = TX, FTN_Y = TY, FTN_Z = TZ }; -enum FTN_MouseStyle { - FTN_ABSOLUTE = 0, - FTN_RELATIVE = 1 -}; - - class FTNoIR_Protocol : public IProtocol { public: @@ -75,18 +69,6 @@ private: FTN_AngleName Mouse_X; // Map one of the 6DOF's to this Mouse direction FTN_AngleName Mouse_Y; FTN_AngleName Mouse_Wheel; - FTN_MouseStyle Mouse_Style; // AutoPan, Absolute or Relative? - bool useVirtualDesk; // Extend the mouse-range beyond the standard - float prev_fMouse_X; // The previous value(s) - float mouse_X_factor; // Sensitivity factor - float prev_fMouse_Y; - float mouse_Y_factor; // Sensitivity factor - 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(); QString getGameName() { return "Mouse tracker"; diff --git a/ftnoir_protocol_mouse/ftnoir_protocol_mouse_dialog.cpp b/ftnoir_protocol_mouse/ftnoir_protocol_mouse_dialog.cpp index 6882ab6a..2b737030 100644 --- a/ftnoir_protocol_mouse/ftnoir_protocol_mouse_dialog.cpp +++ b/ftnoir_protocol_mouse/ftnoir_protocol_mouse_dialog.cpp @@ -45,52 +45,27 @@ MOUSEControls::MOUSEControls() : QWidget() { ui.setupUi( this ); - - // - // Setup the choices - // - ui.cbxSelectMouseStyle->addItem("Absolute"); - ui.cbxSelectMouseStyle->addItem("Relative"); - ui.cbxSelectMouse_X->addItem("None"); - ui.cbxSelectMouse_X->addItem("Pitch"); - ui.cbxSelectMouse_X->addItem("Yaw"); - ui.cbxSelectMouse_X->addItem("Roll"); - ui.cbxSelectMouse_X->addItem("X"); + ui.cbxSelectMouse_X->addItem("X"); ui.cbxSelectMouse_X->addItem("Y"); ui.cbxSelectMouse_X->addItem("Z"); + ui.cbxSelectMouse_X->addItem("Yaw"); + ui.cbxSelectMouse_X->addItem("Pitch"); + ui.cbxSelectMouse_X->addItem("Roll"); ui.cbxSelectMouse_Y->addItem("None"); - ui.cbxSelectMouse_Y->addItem("Pitch"); - ui.cbxSelectMouse_Y->addItem("Yaw"); - ui.cbxSelectMouse_Y->addItem("Roll"); ui.cbxSelectMouse_Y->addItem("X"); ui.cbxSelectMouse_Y->addItem("Y"); ui.cbxSelectMouse_Y->addItem("Z"); - - ui.cbxSelectMouse_Wheel->addItem("None"); - ui.cbxSelectMouse_Wheel->addItem("Pitch"); - ui.cbxSelectMouse_Wheel->addItem("Yaw"); - ui.cbxSelectMouse_Wheel->addItem("Roll"); - ui.cbxSelectMouse_Wheel->addItem("X"); - ui.cbxSelectMouse_Wheel->addItem("Y"); - ui.cbxSelectMouse_Wheel->addItem("Z"); - + ui.cbxSelectMouse_Y->addItem("Yaw"); + ui.cbxSelectMouse_Y->addItem("Pitch"); + ui.cbxSelectMouse_Y->addItem("Roll"); // Connect Qt signals to member-functions connect(ui.btnOK, SIGNAL(clicked()), this, SLOT(doOK())); connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(doCancel())); connect(ui.cbxSelectMouse_X, SIGNAL(currentIndexChanged(int)), this, SLOT(settingChanged( int ))); connect(ui.cbxSelectMouse_Y, SIGNAL(currentIndexChanged(int)), this, SLOT(settingChanged( int ))); - connect(ui.cbxSelectMouse_Wheel, SIGNAL(currentIndexChanged(int)), this, SLOT(settingChanged( int ))); - - connect(ui.spinSensX, SIGNAL(valueChanged(int)), this, SLOT(settingChanged(int))); - connect(ui.spinSensY, SIGNAL(valueChanged(int)), this, SLOT(settingChanged(int))); - connect(ui.spinSensWheel, SIGNAL(valueChanged(int)), this, SLOT(settingChanged(int))); - - connect(ui.chkUseVirtualDesk, SIGNAL(stateChanged(int)), this, SLOT(settingChanged(int))); - theProtocol = NULL; - // Load the settings from the current .INI-file loadSettings(); } @@ -173,17 +148,8 @@ void MOUSEControls::loadSettings() { qDebug() << "loadSettings says: iniFile = " << currentFile; iniFile.beginGroup ( "Mouse" ); - ui.cbxSelectMouseStyle->setCurrentIndex(iniFile.value ( "Style", 1 ).toInt() - 1); - ui.cbxSelectMouse_X->setCurrentIndex(iniFile.value ( "Mouse_X", 1 ).toInt() - 1); - ui.cbxSelectMouse_Y->setCurrentIndex(iniFile.value ( "Mouse_Y", 1 ).toInt() - 1); - ui.cbxSelectMouse_Wheel->setCurrentIndex(iniFile.value ( "Mouse_Wheel", 1 ).toInt() - 1); - - ui.slideSensX->setValue(iniFile.value("SensX", 10).toInt()); - ui.slideSensY->setValue(iniFile.value("SensY", 10).toInt()); - ui.slideSensWheel->setValue(iniFile.value("SensWheel", 10).toInt()); - - ui.chkUseVirtualDesk->setChecked( iniFile.value ( "useVirtualDesk", 0 ).toBool() ); - + ui.cbxSelectMouse_X->setCurrentIndex(iniFile.value ( "Mouse_X", 0 ).toInt() ); + ui.cbxSelectMouse_Y->setCurrentIndex(iniFile.value ( "Mouse_Y", 0 ).toInt() ); iniFile.endGroup (); settingsDirty = false; @@ -201,16 +167,8 @@ void MOUSEControls::save() { QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) iniFile.beginGroup ( "Mouse" ); - iniFile.setValue ( "Style", ui.cbxSelectMouseStyle->currentIndex() + 1 ); - iniFile.setValue ( "Mouse_X", ui.cbxSelectMouse_X->currentIndex() + 1 ); - iniFile.setValue ( "Mouse_Y", ui.cbxSelectMouse_Y->currentIndex() + 1 ); - iniFile.setValue ( "Mouse_Wheel", ui.cbxSelectMouse_Wheel->currentIndex() + 1 ); - - iniFile.setValue ( "SensX", ui.slideSensX->value() ); - iniFile.setValue ( "SensY", ui.slideSensY->value() ); - iniFile.setValue ( "SensWheel", ui.slideSensWheel->value() ); - - iniFile.setValue( "useVirtualDesk", ui.chkUseVirtualDesk->isChecked() ); + iniFile.setValue ( "Mouse_X", ui.cbxSelectMouse_X->currentIndex() ); + iniFile.setValue ( "Mouse_Y", ui.cbxSelectMouse_Y->currentIndex() ); iniFile.endGroup (); settingsDirty = false; -- cgit v1.2.3