From 7a14410a282f76b392eaff1ba2651b820aeb24a4 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 11 Nov 2014 13:22:27 +0100 Subject: sane gimbal lock bounds Tested-by: @KyokushinPL Issue: #63 --- opentrack/tracker.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'opentrack') diff --git a/opentrack/tracker.cpp b/opentrack/tracker.cpp index 5b36971e..07ea22b5 100644 --- a/opentrack/tracker.cpp +++ b/opentrack/tracker.cpp @@ -53,12 +53,13 @@ static dmat<3, 1> rmat_to_euler(const dmat<3, 3>& R) { static constexpr double pi = 3.141592653; const double up = 90 * pi / 180.; - if (R(0, 2) > 0.998) + static constexpr double bound = 1. - 2e-4; + if (R(0, 2) > bound) { double roll = atan(R(1, 0) / R(2, 0)); return dmat<3, 1>({0., up, roll}); } - if (R(0, 2) < -0.998) + if (R(0, 2) < -bound) { double roll = atan(R(1, 0) / R(2, 0)); return dmat<3, 1>({0., -up, roll}); -- cgit v1.2.3