From d971b9d699f7862b4c9414abfdb64445f4be9018 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 31 Oct 2017 21:04:44 +0100 Subject: tracker/tobii: set up settings for prototype vesion The initial version won't have a generalized spline with multiple parameters to configure the gain. But it's doable in one go unlike a fully-fledged version from the start. --- tracker-tobii-eyex/CMakeLists.txt | 36 +- tracker-tobii-eyex/images/tobii-eyex-logo.png | Bin 1319 -> 402 bytes tracker-tobii-eyex/tobii-eyex-dialog.cpp | 28 +- tracker-tobii-eyex/tobii-eyex-dialog.hpp | 5 +- tracker-tobii-eyex/tobii-eyex-dialog.ui | 771 ++++++++++++-------------- tracker-tobii-eyex/tobii-eyex.cpp | 8 +- tracker-tobii-eyex/tobii-eyex.hpp | 9 +- tracker-tobii-eyex/tobii-settings.cpp | 118 ---- tracker-tobii-eyex/tobii-settings.hpp | 55 +- 9 files changed, 397 insertions(+), 633 deletions(-) delete mode 100644 tracker-tobii-eyex/tobii-settings.cpp diff --git a/tracker-tobii-eyex/CMakeLists.txt b/tracker-tobii-eyex/CMakeLists.txt index 6d133f1d..eead67bf 100644 --- a/tracker-tobii-eyex/CMakeLists.txt +++ b/tracker-tobii-eyex/CMakeLists.txt @@ -1,34 +1,24 @@ if(WIN32) set(SDK_TOBII_EYEX "" CACHE PATH "") if(SDK_TOBII_EYEX) - if(CMAKE_COMPILER_IS_GNUCXX) - add_definitions(-Wno-error) - endif() - set(porked NO-INSTALL) - otr_module(tracker-tobii-eyex ${porked}) - target_link_libraries(opentrack-tracker-tobii-eyex opentrack-spline) + otr_module(tracker-tobii) set(tobii-libdir ${SDK_TOBII_EYEX}/lib/x86/) - set(tobii-dll ${tobii-libdir}/Tobii.EyeX.Client.dll) + set(tobii-dll "${tobii-libdir}/Tobii.EyeX.Client.dll") # we only care about the .lib for MSVC++ build anyway - set(tobii-link ${tobii-libdir}/Tobii.EyeX.Client.lib) - target_include_directories(opentrack-tracker-tobii-eyex PRIVATE ${CMAKE_SOURCE_DIR}/spline) - target_link_libraries(opentrack-tracker-tobii-eyex ${tobii-link} opentrack-spline) + target_link_libraries(opentrack-tracker-tobii "${tobii-libdir}/Tobii.EyeX.Client.lib") # we only ever use the C headers due to Microsoft CRT ABI incompatibility with GNU - set(tobii-incdir ${SDK_TOBII_EYEX}/include/eyex) - target_include_directories(opentrack-tracker-tobii-eyex SYSTEM PUBLIC ${tobii-incdir}) + target_include_directories(opentrack-tracker-tobii SYSTEM PUBLIC "${SDK_TOBII_EYEX}/include/eyex") - if(NOT "!${porked}" STREQUAL "!NO-INSTALL") - install(FILES ${tobii-dll} DESTINATION ${opentrack-hier-pfx} ${opentrack-perms-exec}) - if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - file(TO_CMAKE_PATH "$ENV{SystemRoot}" sysroot) - if (IS_DIRECTORY "${sysroot}/SysWOW64") - set(src "${sysroot}/SysWOW64") - else() - set(src "${sysroot}/System32") - endif() - install(FILES "${src}/msvcp110.dll" DESTINATION ${opentrack-hier-pfx} PERMISSIONS ${opentrack-perms-exec}) - install(FILES "${src}/msvcr110.dll" DESTINATION ${opentrack-hier-pfx} PERMISSIONS ${opentrack-perms-exec}) + install(FILES "${tobii-dll}" DESTINATION "${opentrack-hier-pfx}" PERMISSIONS ${opentrack-perms-exec}) + if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + file(TO_CMAKE_PATH "$ENV{SystemRoot}" sysroot) + if (IS_DIRECTORY "${sysroot}/SysWOW64") + set(src "${sysroot}/SysWOW64") + else() + set(src "${sysroot}/System32") endif() + install(FILES "${src}/msvcp110.dll" DESTINATION ${opentrack-hier-pfx} PERMISSIONS ${opentrack-perms-exec}) + install(FILES "${src}/msvcr110.dll" DESTINATION ${opentrack-hier-pfx} PERMISSIONS ${opentrack-perms-exec}) endif() endif() endif() diff --git a/tracker-tobii-eyex/images/tobii-eyex-logo.png b/tracker-tobii-eyex/images/tobii-eyex-logo.png index b952891b..e01bc1ae 100644 Binary files a/tracker-tobii-eyex/images/tobii-eyex-logo.png and b/tracker-tobii-eyex/images/tobii-eyex-logo.png differ diff --git a/tracker-tobii-eyex/tobii-eyex-dialog.cpp b/tracker-tobii-eyex/tobii-eyex-dialog.cpp index 8997c6c2..807542e1 100644 --- a/tracker-tobii-eyex/tobii-eyex-dialog.cpp +++ b/tracker-tobii-eyex/tobii-eyex-dialog.cpp @@ -7,39 +7,15 @@ tobii_eyex_dialog::tobii_eyex_dialog() connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &tobii_eyex_dialog::do_ok); connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &tobii_eyex_dialog::do_cancel); - ui.tracking_mode->addItem("Relative", tobii_relative); - ui.tracking_mode->addItem("Absolute", tobii_absolute); + ui.tracking_mode->addItem("Snap", tobii_snap); + ui.tracking_mode->addItem("Accumulative", tobii_acc); tie_setting(s.mode, ui.tracking_mode); - - ui.relative_mode_gain->setConfig(&rs.acc_mode_spline); - ui.relative_mode_gain->set_preview_only(true); - - tie_setting(rs.dz_len, ui.deadzone); - tie_setting(rs.expt_slope, ui.exponent); - tie_setting(rs.expt_len, ui.exponent_len); - tie_setting(rs.expt_norm, ui.exponent_norm); - - tie_setting(rs.log_len, ui.log_len); - - connect(rs.b.get(), &bundle_::changed, this, [this]() { rs.make_spline(); }, Qt::QueuedConnection); - - // todo add specialization for label with traits -#if 0 - tie_setting(rs.dz_len, ui.deadzone_label); - tie_setting(rs.expt_slope, ui.exponent_label); - tie_setting(rs.expt_len, ui.exponent_len_label); - tie_setting(rs.expt_norm, ui.exponent_norm_label); - tie_setting(rs.log_slope, ui.log_base_label); - tie_setting(rs.log_len, ui.log_len_label); - tie_setting(rs.log_norm, ui.log_norm_label); -#endif } void tobii_eyex_dialog::do_ok() { s.b->save(); - rs.b->save(); close(); } diff --git a/tracker-tobii-eyex/tobii-eyex-dialog.hpp b/tracker-tobii-eyex/tobii-eyex-dialog.hpp index 51957bf2..8ff0e46f 100644 --- a/tracker-tobii-eyex/tobii-eyex-dialog.hpp +++ b/tracker-tobii-eyex/tobii-eyex-dialog.hpp @@ -6,17 +6,14 @@ #include "ui_tobii-eyex-dialog.h" #include -class tobii_eyex_dialog final : public ITrackerDialog +struct tobii_eyex_dialog final : public ITrackerDialog { - Q_OBJECT -public: tobii_eyex_dialog(); void register_tracker(ITracker*) override {} void unregister_tracker() override {} private: Ui::tobii_eyex_dialog_widgets ui; settings s; - rel_settings rs; private slots: void do_ok(); void do_cancel(); diff --git a/tracker-tobii-eyex/tobii-eyex-dialog.ui b/tracker-tobii-eyex/tobii-eyex-dialog.ui index f32c91f4..a6aecafb 100644 --- a/tracker-tobii-eyex/tobii-eyex-dialog.ui +++ b/tracker-tobii-eyex/tobii-eyex-dialog.ui @@ -6,8 +6,8 @@ 0 0 - 702 - 440 + 659 + 471 @@ -17,20 +17,42 @@ :/images/tobii-eyex-logo.png:/images/tobii-eyex-logo.png - + 4 - + + + + 0 + 0 + + Tracking settings + + + 0 + 0 + + + + + 617 + 0 + + - Relative mode shifts the view toward a target that may be offscreen then fixes upon it.The absolute mode is not gradual. + Accumulative mode shifts the view toward a target that may be offscreen then fixes upon it. +On the other hand, the snap mode allows for a quick glance outside the field of vision. + + + Qt::PlainText true @@ -39,6 +61,12 @@ + + + 0 + 0 + + QFrame::NoFrame @@ -74,7 +102,7 @@ - + 0 0 @@ -100,432 +128,348 @@ - + + + + 0 + 0 + + - Relative tracking mode gain + Accumulative mode settings - - - 0 - - - 0 - - - 0 - - - 0 - - + + + + + 0 + 0 + + - Adjust the gain mapping and speed to suit your preference, game type, display size, and distance from the screen. + Screen edge length - - true + + + + + + + 9 + 0 + + + + 1 + + + 20 + + + 1 + + + Qt::Horizontal - - + + - + + 10 + 0 + + + + + + + + + + + 0 0 - - QFrame::NoFrame + + Speed - - QFrame::Raised + + + + + + + 0 + 0 + + + + Max yaw + + + + + + + + 9 + 0 + + + + 100 + + + 1 + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + Max pitch + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + Position output + + + + + + + + 0 + 0 + + + + Enabled + + + + + + + + + + + 0 + 0 + + + + Snap mode settings + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + Max pitch + + + + + + + + 0 + 0 + + + + Max yaw + + + + + + + + 0 + 0 + + + + Speed + + + + + + + + 8 + 0 + + + + 1 + + + 20 + + + 1 + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + + + + + + 10 + 0 + + + + + + + + + + + + 8 + 0 + + + + 100 + + + 1 + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + Screen edge length + + + + + + + + 0 + 0 + + + + Enabled + + + + + + + + 0 + 0 + + + + Position output - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - QFrame::NoFrame - - - QFrame::Raised - - - - 4 - - - 4 - - - 4 - - - 3 - - - - - - 0 - 0 - - - - Deadzone - - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - QSlider::TicksAbove - - - 25 - - - - - - - - 24 - 0 - - - - 0 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - QSlider::TicksAbove - - - 25 - - - - - - - - 24 - 0 - - - - 0 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - Speed - - - - - - - - 24 - 0 - - - - 0 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - Log segment length - - - - - - - - 0 - 0 - - - - Exponent - - - - - - - - 24 - 0 - - - - 0 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - QSlider::TicksAbove - - - 25 - - - - - - - - 0 - 0 - - - - Exponent segment length - - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - QSlider::TicksAbove - - - 25 - - - - - - - - 24 - 0 - - - - 0 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - QSlider::TicksAbove - - - 25 - - - - - - - - 0 - 0 - - - - Exponent norm - - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - QSlider::TicksAbove - - - 25 - - - - - - - - 24 - 0 - - - - 0 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Qt::Vertical - - - - 20 - 0 - - - - - - - - - - - - 0 - 0 - - - - - 300 - 150 - - - - - 192 - 32 - 8 - - - - - 240 - 240 - 240 - - - - true - - - - - relative_mode_gain - frame_3 - + + + + 0 + 0 + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok @@ -533,13 +477,6 @@ - - - spline_widget - QWidget -
spline/spline-widget.hpp
-
-
diff --git a/tracker-tobii-eyex/tobii-eyex.cpp b/tracker-tobii-eyex/tobii-eyex.cpp index eb5aae42..e35c849e 100644 --- a/tracker-tobii-eyex/tobii-eyex.cpp +++ b/tracker-tobii-eyex/tobii-eyex.cpp @@ -1,13 +1,13 @@ #include "tobii-eyex.hpp" +#include "compat/math-imports.hpp" + #include #include -#include + #include #include #include -// XXX TODO whole opentrack needs different debug levels -sh 20160801 - //#define TOBII_EYEX_DEBUG_PRINTF #define TOBII_EYEX_VERBOSE_PRINTF @@ -236,7 +236,7 @@ void tobii_eyex_tracker::start_tracker(QFrame*) dbg_verbose("api initialized"); } -tobii_eyex_tracker::num tobii_eyex_tracker::gain(num /*x_*/) +tobii_eyex_tracker::num tobii_eyex_tracker::gain(num x) { return 1; } diff --git a/tracker-tobii-eyex/tobii-eyex.hpp b/tracker-tobii-eyex/tobii-eyex.hpp index 62b0d733..a86a4a76 100644 --- a/tracker-tobii-eyex/tobii-eyex.hpp +++ b/tracker-tobii-eyex/tobii-eyex.hpp @@ -10,13 +10,13 @@ #include "tobii-settings.hpp" -#include - #include "api/plugin-api.hpp" #include "options/options.hpp" using namespace options; #include "compat/timer.hpp" +#include + #include #include @@ -53,9 +53,6 @@ private: num gain(num x); - settings s; - rel_settings rel_s; - TX_CONTEXTHANDLE dev_ctx; TX_TICKET conn_state_changed_ticket; TX_TICKET event_handler_ticket; @@ -63,7 +60,7 @@ private: TX_HANDLE display_state; QMutex global_state_mtx; - + settings s; Timer t; struct state diff --git a/tracker-tobii-eyex/tobii-settings.cpp b/tracker-tobii-eyex/tobii-settings.cpp deleted file mode 100644 index bc201be4..00000000 --- a/tracker-tobii-eyex/tobii-settings.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include "tobii-settings.hpp" -#include -#include -#include -#include - -/* - def plot(f, max=None, min=None): - if max is None and min is None: - min, max = -1.5, 1.5 - elif max is None: - max=-min - elif min is None: - min=-max - - assert max > min - c = 1e-4*(max-min) - if c < 1e-12: - c = 1e-6 - rng = arange(min, max, c) - plt.plot(rng, map(f, rng)) -*/ - -/* - def richards(b, q, v, c=1): - return lambda x: 1./((c + q * exp(-b * x) ** (1./v))) -*/ - -void rel_settings::make_spline() -{ - const double dz_len_ = dz_len(), - expt_len_ = expt_len(), - expt_norm_ = expt_norm(), - expt_slope_ = expt_slope(), - log_len_ = log_len(); - - const double expt_deriv_at_end = expt_norm_ * expt_slope_ * std::pow(expt_len_, expt_slope_ - 1); // cnx^(n-1) - const double expt_at_end = expt_norm_ * std::pow(expt_len_, expt_slope_); // cx^n - - const double lin_len = 1 - dz_len_ - expt_len_ - log_len_; - - // this isn't correct but works. - // we use exponentiation of the linear part to get logarithmic approximation of the linear - // part rather than linear approximation of the linear part - - const double lin_at_end = std::pow(M_E, lin_len * expt_deriv_at_end - expt_at_end); // e^(cx + a) - const double lin_deriv_at_end = expt_deriv_at_end * std::exp(-expt_at_end + expt_deriv_at_end * lin_len); // ce^(a + cx) - - // this was all derived by the awesome linear approximation - // calculator - - auto expt_part = [=](double x) { return expt_norm_ * std::pow(x, expt_slope_); }; - const double expt_inv_norm = expt_norm_/expt_part(expt_len_); - - auto lin_part = [=](double x) { return expt_inv_norm * (expt_at_end + expt_deriv_at_end * (x - expt_len_)); }; - const double lin_inv_norm = (1 - expt_norm_ - .25)/lin_part(lin_len); - - // TODO needs norm for log/lin parts - auto log_part = [=](double x) { return expt_inv_norm * lin_inv_norm * std::log(lin_at_end + lin_deriv_at_end * (x - lin_len)); }; - const double log_inv_norm = .25/log_part(expt_len_); - - qDebug() << "lin" << expt_deriv_at_end << lin_inv_norm; - - part functors[] - { - { dz_len_, [](double) { return 0; } }, - { expt_len_, [=](double x) { return expt_inv_norm * expt_part(x); } }, // cx^n - { lin_len, [=](double x) { return lin_inv_norm * lin_part(x); } }, // cx + a - { log_len_, [=](double x) { return log_inv_norm * log_part(x); } }, // ln(cx + a) - }; - - make_spline_(functors, std::distance(std::begin(functors), std::end(functors))); -} - -rel_settings::rel_settings() : - opts("tobii-eyex-relative-mode"), - speed(b, "speed", s(3, .1, 10)), - dz_len(b, "deadzone-length", s(.04, 0, .2)), - expt_slope(b, "exponent-slope", s(1.75, 1.5, 3)), - expt_len(b, "exponent-length", s(.2, 0, .5)), - expt_norm(b, "exponent-norm", s(.4, .1, .5)), - log_len(b, "log-len", s(.1, 0, .2)) -{ - make_spline(); -} - -// there's an underflow in spline code, can't use 1e0 -constexpr double spline_max = 1e2; - -double rel_settings::gain(double value) -{ - return acc_mode_spline.get_value_no_save(value * spline_max) / spline_max; -} - -void rel_settings::make_spline_(part* functors, unsigned len) -{ - acc_mode_spline.clear(); - - double lastx = 0; - - for (unsigned k = 0; k < len; k++) - { - part& fun = functors[k]; - - constexpr unsigned nparts = 7; - - for (unsigned i = 1; i <= nparts; i++) - { - const double x = i*fun.len/nparts; - const double y = clamp(fun.f(x), 0, 1); - if (i == nparts/2) - qDebug() << k << i << x << y; - acc_mode_spline.add_point((lastx + x) * spline_max, y * spline_max); - } - - lastx += fun.len; - } -} diff --git a/tracker-tobii-eyex/tobii-settings.hpp b/tracker-tobii-eyex/tobii-settings.hpp index 08e05ecf..cfdfa65c 100644 --- a/tracker-tobii-eyex/tobii-settings.hpp +++ b/tracker-tobii-eyex/tobii-settings.hpp @@ -1,51 +1,36 @@ #pragma once -#include "api/plugin-api.hpp" #include "options/options.hpp" using namespace options; -#include "spline/spline.hpp" -#include "spline/spline-widget.hpp" - -#include - -#include enum tobii_mode { - tobii_relative, - tobii_absolute, + tobii_snap = 0xf00d, + tobii_acc = 0xacc, }; -class rel_settings final : public QObject, public opts +enum max_yaw { - Q_OBJECT - - using functor = std::function; - - struct part - { - double len; - functor f; - }; - - void make_spline_(part* functors, unsigned len); - -public: - using s = slider_value; - value speed, dz_len, expt_slope, expt_len, expt_norm, log_len; - spline acc_mode_spline; - rel_settings(); - double gain(double value); + y10, y15, y20, y30, y45, +}; -public slots: - void make_spline(); +enum max_pitch +{ + p10, p15, p25, p35, }; struct settings final : public opts { - value mode; - settings() : - opts("tobii-eyex"), - mode(b, "mode", tobii_relative) - {} + value mode { b, "mode", tobii_snap }; + + value snap_speed { b, "snap-speed", slider_value(.1, .05, 1) }, + snap_inv_dz { b, "snap-screen-edge-length", slider_value(.35, .1, .5) }; + value acc_speed { b, "acc-speed", slider_value(.1, .05, 1) }, + acc_dz_len { b, "acc-screen-edge-length", slider_value(.1, .1, 1) }; + value snap_yaw { b, "snap-max-yaw", y20 }, + acc_yaw { b, "acc-max-yaw", y20 }; + value snap_pitch { b, "snap-max-pitch", p15 }, + acc_pitch { b, "acc-max-pitch", p15 }; + + settings() : opts("tobii-eyex") {} }; -- cgit v1.2.3