From e7d57ba055627e6b6c8f6de61a497894e0caa658 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 29 Nov 2014 12:25:27 +0100 Subject: implement zero shortcut --- facetracknoir/ui.cpp | 7 ++++ facetracknoir/ui.h | 1 + opentrack/keyboard.ui | 87 ++++++++++++++++++++++++++++++++++++++++++++----- opentrack/shortcuts.cpp | 26 ++++++++++++--- opentrack/shortcuts.h | 12 ++++--- opentrack/tracker.cpp | 24 ++++++++++---- opentrack/tracker.h | 2 ++ opentrack/work.hpp | 2 ++ 8 files changed, 138 insertions(+), 23 deletions(-) diff --git a/facetracknoir/ui.cpp b/facetracknoir/ui.cpp index b8f12490..06ff2d3c 100644 --- a/facetracknoir/ui.cpp +++ b/facetracknoir/ui.cpp @@ -411,6 +411,13 @@ void MainWindow::shortcutToggled() work->tracker->toggle_enabled(); } +void MainWindow::shortcutZeroed() +{ + qDebug() << "Zero"; + if (work) + work->tracker->zero(); +} + void MainWindow::ensure_tray() { if (tray) diff --git a/facetracknoir/ui.h b/facetracknoir/ui.h index 3f607726..70700cbb 100644 --- a/facetracknoir/ui.h +++ b/facetracknoir/ui.h @@ -96,6 +96,7 @@ class MainWindow : public QMainWindow, private State public slots: void shortcutRecentered(); void shortcutToggled(); + void shortcutZeroed(); void bindKeyboardShortcuts(); private slots: void open(); diff --git a/opentrack/keyboard.ui b/opentrack/keyboard.ui index c3c6019e..903bb20f 100644 --- a/opentrack/keyboard.ui +++ b/opentrack/keyboard.ui @@ -6,7 +6,7 @@ 0 0 - 422 + 461 174 @@ -39,7 +39,49 @@ QFrame::Plain - + + + + + 0 + 0 + + + + Zero + + + false + + + + + + + + 50 + 16777215 + + + + Alt + + + + + + + + 50 + 16777215 + + + + Ctrl + + + + @@ -100,6 +142,35 @@ + + + + + 50 + 16777215 + + + + Alt + + + + + + + + 90 + 0 + + + + Select Number + + + QComboBox::InsertAlphabetically + + + @@ -113,7 +184,7 @@ - + @@ -171,8 +242,8 @@ - - + + 50 @@ -180,12 +251,12 @@ - Alt + Shift - - + + 90 diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp index 88c6c69d..c9e9ce41 100644 --- a/opentrack/shortcuts.cpp +++ b/opentrack/shortcuts.cpp @@ -11,6 +11,7 @@ KeyboardShortcutDialog::KeyboardShortcutDialog() for ( int i = 0; i < global_key_sequences.size(); i++) { ui.cbxCenterKey->addItem(global_key_sequences.at(i)); ui.cbxToggleKey->addItem(global_key_sequences.at(i)); + ui.cbxZeroKey->addItem(global_key_sequences.at(i)); } tie_setting(s.center.key_index, ui.cbxCenterKey); @@ -23,6 +24,11 @@ KeyboardShortcutDialog::KeyboardShortcutDialog() tie_setting(s.toggle.shift, ui.chkToggleShift); tie_setting(s.toggle.ctrl, ui.chkToggleCtrl); + tie_setting(s.zero.key_index, ui.cbxZeroKey); + tie_setting(s.zero.alt, ui.chkZeroAlt); + tie_setting(s.zero.shift, ui.chkZeroShift); + tie_setting(s.zero.ctrl, ui.chkZeroCtrl); + tie_setting(s.s_main.tray_enabled, ui.trayp); } @@ -40,12 +46,13 @@ void KeyboardShortcutDialog::doCancel() { #if defined(_WIN32) #include -void KeybindingWorker::set_keys(Key kCenter_, Key kToggle_) +void KeybindingWorker::set_keys(Key kCenter_, Key kToggle_, Key kZero_) { QMutexLocker l(&mtx); kCenter = kCenter_; kToggle = kToggle_; + kZero = kZero_; } KeybindingWorker::~KeybindingWorker() { @@ -59,8 +66,8 @@ KeybindingWorker::~KeybindingWorker() { din->Release(); } -KeybindingWorker::KeybindingWorker(Key keyCenter, Key keyToggle, WId handle, Shortcuts& sc) : - sc(sc), din(0), dinkeyboard(0), kCenter(keyCenter), kToggle(keyToggle), should_quit(true) +KeybindingWorker::KeybindingWorker(Key keyCenter, Key keyToggle, Key keyZero, WId handle, Shortcuts& sc) : + sc(sc), din(0), dinkeyboard(0), kCenter(keyCenter), kToggle(keyToggle), kZero(keyZero), should_quit(true) { if (DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&din, NULL) != DI_OK) { qDebug() << "setup DirectInput8 Creation failed!" << GetLastError(); @@ -139,6 +146,9 @@ void KeybindingWorker::run() { if (isKeyPressed(&kToggle, keystate) && kToggle.should_process()) emit sc.toggle(); + if (isKeyPressed(&kZero, keystate) && kZero.should_process()) + emit sc.zero(); + // keypresses get dropped with high values Sleep(15); } @@ -195,17 +205,23 @@ void Shortcuts::reload() { keyToggle->setShortcut(QKeySequence::UnknownKey); keyToggle->setEnabled(false); } + if (keyZero) + { + keyZero->setShortcut(QKeySequence::UnknownKey); + keyZero->setEnabled(false); + } #endif bind_keyboard_shortcut(keyCenter, s.center); bind_keyboard_shortcut(keyToggle, s.toggle); + bind_keyboard_shortcut(keyZero, s.zero); #ifdef _WIN32 bool is_new = keybindingWorker == nullptr; if (is_new) { - keybindingWorker = std::make_shared(keyCenter, keyToggle, handle, *this); + keybindingWorker = std::make_shared(keyCenter, keyToggle, keyZero, handle, *this); keybindingWorker->start(); } else - keybindingWorker->set_keys(keyCenter, keyToggle); + keybindingWorker->set_keys(keyCenter, keyToggle, keyZero); #endif } diff --git a/opentrack/shortcuts.h b/opentrack/shortcuts.h index 541d7699..7f5f9f1f 100644 --- a/opentrack/shortcuts.h +++ b/opentrack/shortcuts.h @@ -69,16 +69,17 @@ private: LPDIRECTINPUTDEVICE8 dinkeyboard; Key kCenter; Key kToggle; + Key kZero; QMutex mtx; public: volatile bool should_quit; ~KeybindingWorker(); - KeybindingWorker(Key keyCenter, Key keyToggle, WId handle, Shortcuts& sc); + KeybindingWorker(Key keyCenter, Key keyToggle, Key keyZero, WId handle, Shortcuts& sc); void run(); - void set_keys(Key kCenter, Key kToggle); + void set_keys(Key kCenter, Key kToggle, Key kZero); #else public: - KeybindingWorker(Key, Key, WId) {} + KeybindingWorker(Key, Key, Key, WId) {} void run() {} #endif }; @@ -97,6 +98,7 @@ public: K keyCenter; K keyToggle; + K keyZero; WId handle; #ifdef _WIN32 @@ -105,12 +107,13 @@ public: struct settings { pbundle b; - key_opts center, toggle; + key_opts center, toggle, zero; main_settings s_main; settings() : b(bundle("keyboard-shortcuts")), center(b, "center"), toggle(b, "toggle"), + zero(b, "zero"), s_main(bundle("opentrack-ui")) {} } s; @@ -123,6 +126,7 @@ private: signals: void center(); void toggle(); + void zero(); }; class KeyboardShortcutDialog: public QWidget diff --git a/opentrack/tracker.cpp b/opentrack/tracker.cpp index be0ecd84..a6433da5 100644 --- a/opentrack/tracker.cpp +++ b/opentrack/tracker.cpp @@ -26,6 +26,7 @@ Tracker::Tracker(main_settings& s, Mappings &m, SelectedLibraries &libs) : m(m), centerp(false), enabledp(true), + zero_(false), should_quit(false), libs(libs), r_b(dmat<3,3>::eye()), @@ -127,12 +128,26 @@ void Tracker::logic() m(5).opts.invert, }; + static constexpr double pi = 3.141592653; + static constexpr double r2d = 180. / pi; + Pose value, raw; - for (int i = 0; i < 6; i++) + if (!zero_) + for (int i = 0; i < 6; i++) + { + value(i) = newpose[i]; + raw(i) = newpose[i]; + } + else { - value(i) = newpose[i]; - raw(i) = newpose[i]; + auto mat = rmat_to_euler(r_b); + + for (int i = 0; i < 3; i++) + { + raw(i+3) = value(i+3) = mat(i, 0) * r2d; + raw(i) = value(i) = t_b[i]; + } } if (centerp) @@ -149,9 +164,6 @@ void Tracker::logic() const dmat<3, 1> euler = rmat_to_euler(m_); for (int i = 0; i < 3; i++) { - static constexpr double pi = 3.141592653; - static constexpr double r2d = 180. / pi; - value(i) -= t_b[i]; value(i+3) = euler(i, 0) * r2d; } diff --git a/opentrack/tracker.h b/opentrack/tracker.h index 84202635..bf0047b4 100644 --- a/opentrack/tracker.h +++ b/opentrack/tracker.h @@ -29,6 +29,7 @@ private: double newpose[6]; std::atomic centerp; std::atomic enabledp; + std::atomic zero_; std::atomic should_quit; SelectedLibraries const& libs; @@ -48,4 +49,5 @@ public: void start() { QThread::start(); } void toggle_enabled() { enabledp.store(!enabledp.load()); } void center() { centerp.store(!centerp.load()); } + void zero() { zero_.store(!zero_.load()); } }; diff --git a/opentrack/work.hpp b/opentrack/work.hpp index 9a9889a7..b93c71b6 100644 --- a/opentrack/work.hpp +++ b/opentrack/work.hpp @@ -26,9 +26,11 @@ struct Work #ifndef _WIN32 QObject::connect(sc->keyCenter.get(), SIGNAL(activated()), recv, SLOT(shortcutRecentered())); QObject::connect(sc->keyToggle.get(), SIGNAL(activated()), recv, SLOT(shortcutToggled())); + QObject::connect(sc->keyZero.get(), SIGNAL(activated()), recv, SLOT(shortcutZeroed())); #else QObject::connect(sc.get(), SIGNAL(center()), recv, SLOT(shortcutRecentered())); QObject::connect(sc.get(), SIGNAL(toggle()), recv, SLOT(shortcutToggled())); + QObject::connect(sc.get(), SIGNAL(zero()), recv, SLOT(shortcutZeroed())); #endif tracker->start(); } -- cgit v1.2.3