From e0866f30d25abd62fadb4b29fff90143c288e9ff Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 18 Jan 2018 23:08:30 +0100 Subject: logic: change relative translation triggering Relative translation mode now has three states: - disabled - always enabled - enabled when not aiming In the third mode, looking very close to center disables reltrans. The exact values aren't final. --- gui/settings-dialog.ui | 89 ++++++++++++++++++++++++++------------ gui/settings.cpp | 23 +++++++--- logic/main-settings.cpp | 13 +++--- logic/main-settings.hpp | 12 ++++- logic/pipeline.cpp | 62 +++++++++++++++----------- logic/pipeline.hpp | 10 ++--- migration/20180118_00-reltrans.cpp | 44 +++++++++++++++++++ 7 files changed, 178 insertions(+), 75 deletions(-) create mode 100644 migration/20180118_00-reltrans.cpp diff --git a/gui/settings-dialog.ui b/gui/settings-dialog.ui index 363edb3a..20a1b524 100644 --- a/gui/settings-dialog.ui +++ b/gui/settings-dialog.ui @@ -1785,13 +1785,47 @@ - - - - - - Enable - + + + + + + + 10 + 0 + + + + Mode + + + + + + + + 4 + 0 + + + + + Disabled + + + + + Enabled + + + + + Enabled when not aiming + + + + + @@ -1825,7 +1859,7 @@ 0 - + 3 @@ -1836,12 +1870,12 @@ - Disable for X + Disable for Y - - + + 3 @@ -1852,40 +1886,40 @@ - Disable for Y + Disable for X - - + + - 3 + 2 0 - - - - Disable for Z (for zoom on Z axis) + Disable effect by roll - - + + - 2 + 3 0 + + + - Disable effect by yaw + Disable for Z (for zoom on Z axis) - + @@ -1898,8 +1932,8 @@ - - + + 2 @@ -1907,7 +1941,7 @@ - Disable effect by roll + Disable effect by yaw @@ -2147,7 +2181,6 @@ src_z invert_z tracklogging_enabled - tcomp_enable tcomp_tx_disable tcomp_ty_disable tcomp_tz_disable diff --git a/gui/settings.cpp b/gui/settings.cpp index fe0b3261..fc7cde19 100644 --- a/gui/settings.cpp +++ b/gui/settings.cpp @@ -54,15 +54,24 @@ options_dialog::options_dialog(std::function pause_keybindings) : tie_setting(main.center_at_startup, ui.center_at_startup); - tie_setting(main.tcomp_p, ui.tcomp_enable); + const reltrans_state reltrans_modes[] = { + reltrans_disabled, + reltrans_enabled, + reltrans_non_center, + }; + + for (unsigned k = 0; k < 3; k++) + ui.reltrans_mode->setItemData(k, int(reltrans_modes[k])); + + tie_setting(main.reltrans_mode, ui.reltrans_mode); - tie_setting(main.tcomp_disable_tx, ui.tcomp_tx_disable); - tie_setting(main.tcomp_disable_ty, ui.tcomp_ty_disable); - tie_setting(main.tcomp_disable_tz, ui.tcomp_tz_disable); + tie_setting(main.reltrans_disable_tx, ui.tcomp_tx_disable); + tie_setting(main.reltrans_disable_ty, ui.tcomp_ty_disable); + tie_setting(main.reltrans_disable_tz, ui.tcomp_tz_disable); - tie_setting(main.tcomp_disable_src_yaw, ui.tcomp_src_yaw_disable); - tie_setting(main.tcomp_disable_src_pitch, ui.tcomp_src_pitch_disable); - tie_setting(main.tcomp_disable_src_roll, ui.tcomp_src_roll_disable); + tie_setting(main.reltrans_disable_src_yaw, ui.tcomp_src_yaw_disable); + tie_setting(main.reltrans_disable_src_pitch, ui.tcomp_src_pitch_disable); + tie_setting(main.reltrans_disable_src_roll, ui.tcomp_src_roll_disable); tie_setting(main.neck_z, ui.neck_z); diff --git a/logic/main-settings.cpp b/logic/main-settings.cpp index 2c5d45db..c735ac6e 100644 --- a/logic/main-settings.cpp +++ b/logic/main-settings.cpp @@ -12,13 +12,12 @@ main_settings::main_settings() : a_pitch("pitch", Pitch), a_roll("roll", Roll), all_axis_opts { &a_x, &a_y, &a_z, &a_yaw, &a_pitch, &a_roll }, - tcomp_p(b, "compensate-translation", false), - tcomp_disable_tx(b, "compensate-translation-disable-x-axis", false), - tcomp_disable_ty(b, "compensate-translation-disable-y-axis", false), - tcomp_disable_tz(b, "compensate-translation-disable-z-axis", false), - tcomp_disable_src_yaw(b, "compensate-translation-disable-source-yaw", false), - tcomp_disable_src_pitch(b, "compensate-translation-disable-source-pitch", false), - tcomp_disable_src_roll(b, "compensate-translation-disable-source-roll", false), + reltrans_disable_tx(b, "compensate-translation-disable-x-axis", false), + reltrans_disable_ty(b, "compensate-translation-disable-y-axis", false), + reltrans_disable_tz(b, "compensate-translation-disable-z-axis", false), + reltrans_disable_src_yaw(b, "compensate-translation-disable-source-yaw", false), + reltrans_disable_src_pitch(b, "compensate-translation-disable-source-pitch", false), + reltrans_disable_src_roll(b, "compensate-translation-disable-source-roll", false), tray_enabled(b, "use-system-tray", false), tray_start(b, "start-in-tray", false), center_at_startup(b, "center-at-startup", true), diff --git a/logic/main-settings.hpp b/logic/main-settings.hpp index 00fbe9cc..df86f856 100644 --- a/logic/main-settings.hpp +++ b/logic/main-settings.hpp @@ -15,6 +15,13 @@ #include "export.hpp" +enum reltrans_state +{ + reltrans_disabled = 0, + reltrans_enabled = 1, + reltrans_non_center = 2, +}; + namespace main_settings_impl { using namespace options; @@ -40,8 +47,9 @@ struct OTR_LOGIC_EXPORT main_settings final axis_opts a_x, a_y, a_z; axis_opts a_yaw, a_pitch, a_roll; axis_opts* all_axis_opts[6]; - value tcomp_p, tcomp_disable_tx, tcomp_disable_ty, tcomp_disable_tz; - value tcomp_disable_src_yaw, tcomp_disable_src_pitch, tcomp_disable_src_roll; + value reltrans_mode { b, "relative-translation-mode", reltrans_disabled }; + value reltrans_disable_tx, reltrans_disable_ty, reltrans_disable_tz; + value reltrans_disable_src_yaw, reltrans_disable_src_pitch, reltrans_disable_src_roll; value tray_enabled, tray_start; value center_at_startup; //value center_method; diff --git a/logic/pipeline.cpp b/logic/pipeline.cpp index de7d94e6..e6ca3b70 100644 --- a/logic/pipeline.cpp +++ b/logic/pipeline.cpp @@ -15,6 +15,7 @@ #include "compat/nan.hpp" #include "compat/sleep.hpp" #include "compat/math.hpp" +#include "compat/meta.hpp" #include "pipeline.hpp" @@ -64,29 +65,38 @@ euler_t reltrans::rotate(const rmat& rmat, const euler_t& xyz, return output; } -Pose reltrans::apply_pipeline(bool enable, const Pose& value, const Mat& disable) +Pose reltrans::apply_pipeline(reltrans_state state, const Pose& value, const Mat& disable) { - if (enable) + if (state != reltrans_disabled) { euler_t rel { value(TX), value(TY), value(TZ) }; { - const bool yaw_in_zone = std::fabs(value(Yaw)) > 135; - const bool pitch_in_zone = value(Pitch) < -30; - const bool tcomp_in_zone_ = yaw_in_zone || pitch_in_zone; + bool tcomp_in_zone_ = progn( + if (state == reltrans_non_center) + { + const bool yaw_in_zone = std::fabs(value(Yaw)) < 12; + const bool pitch_in_zone = std::fabs(value(Pitch)) < 15; + const bool roll_in_zone = std::fabs(value(Roll)) < 7; + + return !(yaw_in_zone && pitch_in_zone && roll_in_zone); + } + else + return true; + ); - if (!tcomp_state && tcomp_in_zone != tcomp_in_zone_) + if (!cur && in_zone != tcomp_in_zone_) { - //qDebug() << "tcomp-interp: START"; - tcomp_state = true; - tcomp_interp_timer.start(); + //qDebug() << "reltrans-interp: START" << tcomp_in_zone_; + cur = true; + interp_timer.start(); } - tcomp_in_zone = tcomp_in_zone_; + in_zone = tcomp_in_zone_; } // only when looking behind or downward - if (tcomp_in_zone) + if (in_zone) { const double tcomp_c[] = { double(!disable(Yaw)), @@ -105,41 +115,41 @@ Pose reltrans::apply_pipeline(bool enable, const Pose& value, const Mat& disable); + Pose apply_pipeline(reltrans_state cur, const Pose& value, const Mat& disable); }; using namespace time_units; diff --git a/migration/20180118_00-reltrans.cpp b/migration/20180118_00-reltrans.cpp new file mode 100644 index 00000000..ba35e7f0 --- /dev/null +++ b/migration/20180118_00-reltrans.cpp @@ -0,0 +1,44 @@ +#include "migration.hpp" +#include "options/options.hpp" + +using namespace options; +using namespace migrations; + +enum reltrans_state +{ + reltrans_disabled = 0, + reltrans_enabled = 1, + reltrans_non_center = 2, +}; + +static const char* old_name = "compensate-translation"; +static const char* new_name = "relative-translation-mode"; + +struct reltrans_enum : migration +{ + QString unique_date() const override + { + return "20180118_00"; + } + + QString name() const override + { + return "reltrans modes"; + } + + bool should_run() const override + { + auto b = make_bundle("opentrack-ui"); + return b->contains(old_name) && !b->contains(new_name); + } + + void run() override + { + auto b = make_bundle("opentrack-ui"); + bool value = b->get(old_name); + b->store_kv(new_name, int(value ? reltrans_enabled : reltrans_disabled)); + b->save(); + } +}; + +OPENTRACK_MIGRATION(reltrans_enum); -- cgit v1.2.3