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. --- logic/main-settings.cpp | 13 +++++------ logic/main-settings.hpp | 12 ++++++++-- logic/pipeline.cpp | 62 ++++++++++++++++++++++++++++--------------------- logic/pipeline.hpp | 10 ++++---- 4 files changed, 57 insertions(+), 40 deletions(-) (limited to 'logic') 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; -- cgit v1.2.3