diff options
-rw-r--r-- | compat/euler.cpp | 118 | ||||
-rw-r--r-- | compat/euler.hpp | 10 | ||||
-rw-r--r-- | compat/macros.hpp | 5 | ||||
-rw-r--r-- | filter-kalman/kalman.cpp | 4 | ||||
-rw-r--r-- | installer/opentrack-installer.iss | 6 | ||||
-rw-r--r-- | logic/pipeline.cpp | 65 | ||||
-rw-r--r-- | logic/pipeline.hpp | 16 | ||||
-rw-r--r-- | logic/runtime-libraries.cpp | 6 | ||||
-rw-r--r-- | tracker-wii/wii_module.cpp | 3 | ||||
-rw-r--r-- | variant/default/main-window.cpp | 16 | ||||
-rw-r--r-- | variant/default/main-window.hpp | 2 |
11 files changed, 88 insertions, 163 deletions
diff --git a/compat/euler.cpp b/compat/euler.cpp index 7c753214..39d2b116 100644 --- a/compat/euler.cpp +++ b/compat/euler.cpp @@ -2,113 +2,39 @@ #include "math-imports.hpp" #include <cmath> +// rotation order is XYZ + namespace euler { euler_t OTR_COMPAT_EXPORT rmat_to_euler(const rmat& R) { - const double cy = sqrt(R(2,2)*R(2, 2) + R(2, 1)*R(2, 1)); - const bool large_enough = cy > 1e-10; - if (large_enough) - return { - atan2(-R(1, 0), R(0, 0)), - atan2(R(2, 0), cy), - atan2(-R(2, 1), R(2, 2)) - }; - else - return { - atan2(R(0, 1), R(1, 1)), - atan2(R(2, 0), cy), - 0 - }; -} - -// tait-bryan angles, not euler -rmat OTR_COMPAT_EXPORT euler_to_rmat(const euler_t& input) -{ - const double H = -input(0); - const double P = -input(1); - const double B = -input(2); + double alpha, beta, gamma; - const auto c1 = cos(H); - const auto s1 = sin(H); - const auto c2 = cos(P); - const auto s2 = sin(P); - const auto c3 = cos(B); - const auto s3 = sin(B); + beta = atan2( -R(2,0), sqrt(R(2,1)*R(2,1) + R(2,2)*R(2,2)) ); + alpha = atan2( R(1,0), R(0,0)); + gamma = atan2( R(2,1), R(2,2)); - return { - // z - c1*c2, - c1*s2*s3 - c3*s1, - s1*s3 + c1*c3*s2, - // y - c2*s1, - c1*c3 + s1*s2*s3, - c3*s1*s2 - c1*s3, - // x - -s2, - c2*s3, - c2*c3 - }; + return { alpha, -beta, gamma }; } -// https://en.wikipedia.org/wiki/Davenport_chained_rotations#Tait.E2.80.93Bryan_chained_rotations -void OTR_COMPAT_EXPORT tait_bryan_to_matrices(const euler_t& input, - rmat& r_roll, - rmat& r_pitch, - rmat& r_yaw) +rmat OTR_COMPAT_EXPORT euler_to_rmat(const euler_t& e) { - { - const double phi = -input(2); - const double sin_phi = sin(phi); - const double cos_phi = cos(phi); - - r_roll = { - 1, 0, 0, - 0, cos_phi, -sin_phi, - 0, sin_phi, cos_phi - }; - } - - { - const double theta = input(1); - const double sin_theta = sin(theta); - const double cos_theta = cos(theta); + const double X = e(2); + const double Y = -e(1); + const double Z = e(0); - r_pitch = { - cos_theta, 0, -sin_theta, - 0, 1, 0, - sin_theta, 0, cos_theta - }; - } + const double cx = cos(X); + const double sx = sin(X); + const double cy = cos(Y); + const double sy = sin(Y); + const double cz = cos(Z); + const double sz = sin(Z); - { - const double psi = -input(0); - const double sin_psi = sin(psi); - const double cos_psi = cos(psi); - - r_yaw = { - cos_psi, -sin_psi, 0, - sin_psi, cos_psi, 0, - 0, 0, 1 - }; - } -} - -template<int H, int W, typename f = double> -rmat quaternion_to_mat_(const Mat<f, H, W>& q) -{ - const double w = q.w(), x = q.x(), y = q.y(), z = q.z(); - const double ww = w*w, xx = x*x, yy = y*y, zz = z*z; - - return rmat( - ww + xx - yy - zz, 2 * (x*y - w*z), 2 * (x*z + w*y), - 2 * (x*z - w*y), 2 * (y*z + w*x), ww - xx - yy + zz, - 2 * (x*y + w*z), ww - xx + yy - zz, 2 * (y*z - w*x) - ); + return { + cy*cz, -cy*sz, sy, + cz*sx*sy + cx*sz, cx*cz - sx*sy*sz, -cy*sx, + -cx*cz*sy + sx*sz, cz*sx + cx*sy*sz, cx*cy, + }; } -rmat OTR_COMPAT_EXPORT quaternion_to_mat(const dmat<1, 4>& q) { return quaternion_to_mat_(q); } -//rmat OTR_COMPAT_EXPORT quaternion_to_mat(const dmat<4, 1>& q) { return quaternion_to_mat_(q); } - } // end ns euler diff --git a/compat/euler.hpp b/compat/euler.hpp index a4c58ffb..d4217a70 100644 --- a/compat/euler.hpp +++ b/compat/euler.hpp @@ -14,22 +14,12 @@ namespace euler { template<int h_, int w_> using dmat = Mat<double, h_, w_>; -using dvec2 = Mat<double, 2, 1>; using dvec3 = Mat<double, 3, 1>; using rmat = dmat<3, 3>; using euler_t = dmat<3, 1>; rmat OTR_COMPAT_EXPORT euler_to_rmat(const euler_t& input); - euler_t OTR_COMPAT_EXPORT rmat_to_euler(const rmat& R); -void OTR_COMPAT_EXPORT tait_bryan_to_matrices(const euler_t& input, - rmat& r_roll, - rmat& r_pitch, - rmat& r_yaw); - -rmat OTR_COMPAT_EXPORT quaternion_to_mat(const dmat<1, 4>& q); -//rmat OTR_COMPAT_EXPORT quaternion_to_mat(const dmat<4, 1>& q); - } // end ns euler diff --git a/compat/macros.hpp b/compat/macros.hpp index df71b1f3..c8fbca20 100644 --- a/compat/macros.hpp +++ b/compat/macros.hpp @@ -47,3 +47,8 @@ # define unlikely(x) (x) #endif +#if defined _MSC_VER +# define OTR_FUNNAME (__FUNCSIG__) +#else +# define OTR_FUNNAME (__PRETTY_FUNCTION__) +#endif diff --git a/filter-kalman/kalman.cpp b/filter-kalman/kalman.cpp index 82b1b0f1..3a0da608 100644 --- a/filter-kalman/kalman.cpp +++ b/filter-kalman/kalman.cpp @@ -270,9 +270,9 @@ dialog_kalman::dialog_kalman() void dialog_kalman::updateLabels(const slider_value&) { - // M$ hates unicode! (M$ autoconverts source code of one kind of utf-8 format, + // M$ hates unicode! (M$ autoconverts source code of one kind of utf-8 format, // the one without BOM, to another kind that QT does not like) - // Previous attempt to use c++11 utf8 strings like u8" °" now failed for unkown + // Previous attempt to use c++11 utf8 strings like u8" °" now failed for unknown // reasons where it worked before. Hence fallback to QChar(0x00b0). this->ui.noiseRotLabel->setText( QString::number(settings::map_slider_value(s.noise_rot_slider_value), 'f', 3) + " " + QChar(0x00b0)); diff --git a/installer/opentrack-installer.iss b/installer/opentrack-installer.iss index 8e2a5c85..e6551863 100644 --- a/installer/opentrack-installer.iss +++ b/installer/opentrack-installer.iss @@ -1,7 +1,7 @@ ; Script generated by the Inno Setup Script Wizard. ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! -#include "../build-msvc17/opentrack-version.h" +#include "../build/opentrack-version.h" #define MyAppName "opentrack" #define MyAppVersion OPENTRACK_VERSION #define MyAppPublisher "opentrack" @@ -26,7 +26,7 @@ DefaultDirName={pf}\{#MyAppName} DefaultGroupName={#MyAppName} AllowNoIcons=yes OutputBaseFilename={#MyAppVersion}-win32-setup -SetupIconFile=..\gui\opentrack.ico +SetupIconFile=..\variant\default\opentrack.ico Compression=lzma2/ultra64 SolidCompression=yes DisableWelcomePage=True @@ -45,7 +45,7 @@ Name: "english"; MessagesFile: "compiler:Default.isl" Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked [Files] -Source: "..\build-msvc17\install\*"; DestDir: "{app}"; Flags: ignoreversion createallsubdirs recursesubdirs +Source: "..\build\install\*"; DestDir: "{app}"; Flags: ignoreversion createallsubdirs recursesubdirs [Icons] Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" diff --git a/logic/pipeline.cpp b/logic/pipeline.cpp index 654a9f09..0d9c2021 100644 --- a/logic/pipeline.cpp +++ b/logic/pipeline.cpp @@ -15,8 +15,10 @@ #include "compat/sleep.hpp" #include "compat/math.hpp" #include "compat/meta.hpp" +#include "compat/macros.hpp" #include "pipeline.hpp" +#include "logic/shortcuts.h" #include <cmath> #include <algorithm> @@ -234,22 +236,18 @@ bool maybe_nan(const char* text, const char* fun, int line, const xs&... vals) return false; } -#if defined _MSC_VER -# define OTR_FUNNAME2 (__FUNCSIG__) -#else -# define OTR_FUNNAME2 (__PRETTY_FUNCTION__) -#endif -// don't expand -# define OTR_FUNNAME (OTR_FUNNAME2) - -#define nan_check(...) \ - do \ - { \ - if (maybe_nan(#__VA_ARGS__, OTR_FUNNAME, __LINE__, __VA_ARGS__)) \ - goto nan; \ +// for MSVC `else' is like `unlikely' for GNU + +#define nan_check(...) \ + do \ + { \ + if (likely(!maybe_nan(#__VA_ARGS__, OTR_FUNNAME, __LINE__, __VA_ARGS__))) \ + (void)0; \ + else \ + goto error; \ } while (false) -void pipeline::maybe_enable_center_on_tracking_started() +bool pipeline::maybe_enable_center_on_tracking_started() { if (!tracking_started) { @@ -261,15 +259,20 @@ void pipeline::maybe_enable_center_on_tracking_started() } if (tracking_started && s.center_at_startup) + { set(f_center, true); + return true; + } } + + return false; } void pipeline::maybe_set_center_pose(const Pose& value, bool own_center_logic) { euler_t tmp = d2r * euler_t(&value[Yaw]); - scaled_rotation.rotation = euler_to_rmat(c_div * tmp); - real_rotation.rotation = euler_to_rmat(tmp); + //scaled_rotation.rotation = euler_to_rmat(c_div * tmp); + rotation.rotation = euler_to_rmat(tmp); if (get(f_center)) { @@ -278,15 +281,15 @@ void pipeline::maybe_set_center_pose(const Pose& value, bool own_center_logic) if (own_center_logic) { - scaled_rotation.rot_center = rmat::eye(); - real_rotation.rot_center = rmat::eye(); + //scaled_rotation.rot_center = rmat::eye(); + rotation.inv_rot_center = rmat::eye(); t_center = euler_t(); } else { - real_rotation.rot_center = real_rotation.rotation.t(); - scaled_rotation.rot_center = scaled_rotation.rotation.t(); + rotation.inv_rot_center = rotation.rotation.t(); + //scaled_rotation.rot_center = scaled_rotation.rotation.t(); t_center = euler_t(static_cast<const double*>(value)); } @@ -316,27 +319,26 @@ Pose pipeline::clamp_value(Pose value) const Pose pipeline::apply_center(Pose value) const { - rmat rotation = scaled_rotation.rotation * scaled_rotation.rot_center; - euler_t pos = euler_t(value) - t_center; - euler_t rot = r2d * c_mult * rmat_to_euler(rotation); + euler_t T = euler_t(value) - t_center; + euler_t R = r2d * rmat_to_euler(rotation.rotation * rotation.inv_rot_center); - pos = rel.rotate(real_rotation.rot_center, pos, vec3_bool()); + T = rel.rotate(rotation.inv_rot_center, T, vec3_bool()); for (int i = 0; i < 3; i++) { - // don't invert after t_compensate + // don't invert after reltrans // inverting here doesn't break centering if (m(i+3).opts.invert) - rot(i) = -rot(i); + R(i) = -R(i); if (m(i).opts.invert) - pos(i) = -pos(i); + T(i) = -T(i); } for (int i = 0; i < 3; i++) { - value(i) = pos(i); - value(i+3) = rot(i); + value(i) = T(i); + value(i+3) = R(i); } return value; @@ -442,7 +444,8 @@ void pipeline::logic() maybe_enable_center_on_tracking_started(); maybe_set_center_pose(value, own_center_logic); value = apply_center(value); - logger.write_pose(value); // "corrected" - after various transformations to account for camera position + // "corrected" - after various transformations to account for camera position + logger.write_pose(value); } { @@ -470,7 +473,7 @@ void pipeline::logic() goto ok; -nan: +error: { QMutexLocker foo(&mtx); diff --git a/logic/pipeline.hpp b/logic/pipeline.hpp index 5c3c3a26..d51655b3 100644 --- a/logic/pipeline.hpp +++ b/logic/pipeline.hpp @@ -92,22 +92,22 @@ private: Pose newpose; runtime_libraries const& libs; // The owner of the reference is the main window. - // This design might be usefull if we decide later on to swap out + // This design might be useful if we decide later on to swap out // the logger while the tracker is running. TrackLogger& logger; struct state { - rmat rot_center; + rmat inv_rot_center; rmat rotation; - state() : rot_center(rmat::eye()) + state() : inv_rot_center(rmat::eye()) {} }; reltrans rel; - state real_rotation, scaled_rotation; + state rotation; euler_t t_center; ns backlog_time = ns(0); @@ -117,7 +117,7 @@ private: double map(double pos, Map& axis); void logic(); void run() override; - void maybe_enable_center_on_tracking_started(); + bool maybe_enable_center_on_tracking_started(); void maybe_set_center_pose(const Pose& value, bool own_center_logic); Pose clamp_value(Pose value) const; Pose apply_center(Pose value) const; @@ -126,9 +126,9 @@ private: Pose apply_reltrans(Pose value, vec6_bool disabled); Pose apply_zero_pos(Pose value) const; - // note: float exponent base is 2 - static constexpr inline double c_mult = 16; - static constexpr inline double c_div = 1./c_mult; + // reminder: float exponent base is 2 + //static constexpr inline double c_mult = 16; + //static constexpr inline double c_div = 1./c_mult; public: pipeline(Mappings& m, runtime_libraries& libs, event_handler& ev, TrackLogger& logger); ~pipeline(); diff --git a/logic/runtime-libraries.cpp b/logic/runtime-libraries.cpp index 1dcff4a5..d05e90c2 100644 --- a/logic/runtime-libraries.cpp +++ b/logic/runtime-libraries.cpp @@ -19,7 +19,7 @@ runtime_libraries::runtime_libraries(QFrame* frame, dylibptr t, dylibptr p, dyli if(status = pProtocol->initialize(), !status.is_ok()) { - status = _("Error occured while loading protocol %1\n\n%2\n") + status = _("Error occurred while loading protocol %1\n\n%2\n") .arg(p->name).arg(status.error); goto end; } @@ -36,14 +36,14 @@ runtime_libraries::runtime_libraries(QFrame* frame, dylibptr t, dylibptr p, dyli if (pFilter) if(status = pFilter->initialize(), !status.is_ok()) { - status = _("Error occured while loading filter %1\n\n%2\n") + status = _("Error occurred while loading filter %1\n\n%2\n") .arg(f->name).arg(status.error); goto end; } if (status = pTracker->start_tracker(frame), !status.is_ok()) { - status = _("Error occured while loading tracker %1\n\n%2\n") + status = _("Error occurred while loading tracker %1\n\n%2\n") .arg(t->name).arg(status.error); goto end; } diff --git a/tracker-wii/wii_module.cpp b/tracker-wii/wii_module.cpp index 40131f69..5ef75f57 100644 --- a/tracker-wii/wii_module.cpp +++ b/tracker-wii/wii_module.cpp @@ -76,8 +76,7 @@ using namespace pt_module; wii_dialog_pt::wii_dialog_pt() : TrackerDialog_PT(module_name) { - ui.camera_settings_groupbox->hide(); - ui.groupBox_2->hide(); + ui.tabWidget->removeTab(0); } OPENTRACK_DECLARE_TRACKER(wii_tracker_pt, wii_dialog_pt, wii_metadata_pt) diff --git a/variant/default/main-window.cpp b/variant/default/main-window.cpp index 9df36a7d..62b969e1 100644 --- a/variant/default/main-window.cpp +++ b/variant/default/main-window.cpp @@ -339,21 +339,16 @@ bool main_window::get_new_config_name_from_dialog(QString& ret) main_window::~main_window() { - if (tray) - tray->hide(); - tray = nullptr; - - const bool just_stopping = bool(work); - // stupid ps3 eye has LED issues - if (just_stopping) + if (work) { stop_tracker_(); - close(); QEventLoop ev; ev.processEvents(); portable::sleep(2000); } + + exit(); } void main_window::set_working_directory() @@ -842,6 +837,11 @@ bool main_window::maybe_hide_to_tray(QEvent* e) return false; } +void main_window::closeEvent(QCloseEvent*) +{ + exit(); +} + void main_window::maybe_start_profile_from_executable() { if (!work) diff --git a/variant/default/main-window.hpp b/variant/default/main-window.hpp index b4b7dbb7..c28aadc4 100644 --- a/variant/default/main-window.hpp +++ b/variant/default/main-window.hpp @@ -115,6 +115,8 @@ class main_window : public QMainWindow, private State template<typename t, typename F> bool mk_window_common(std::unique_ptr<t>& d, F&& ctor); + void closeEvent(QCloseEvent *event) override; + private slots: void save_modules(); void exit(int status = EXIT_SUCCESS); |