From 6c1934fcdf7dc91897e9d4dc8b8b6810b1de6a51 Mon Sep 17 00:00:00 2001 From: Edward d'Auvergne Date: Sun, 3 May 2015 20:04:33 +0200 Subject: [PATCH] Singularity avoidance fix for the flightgear Viewer. This was reported at https://sourceforge.net/p/flightgear/codetickets/1740/ and discussed at http://thread.gmane.org/gmane.games.flightgear.devel/77562 . The flightgear Viewer no longer causes aircraft to disappear due to the singularity at the poles resulting in an undefined azimuthal angle. --- src/Viewer/viewer.cxx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Viewer/viewer.cxx b/src/Viewer/viewer.cxx index a18c51b23..7061f76cb 100644 --- a/src/Viewer/viewer.cxx +++ b/src/Viewer/viewer.cxx @@ -310,11 +310,15 @@ FGViewer::setGoalPitchOffset_deg (double goal_pitch_offset_deg) { _dirty = true; _goal_pitch_offset_deg = goal_pitch_offset_deg; - if ( _goal_pitch_offset_deg < -90 ) { - _goal_pitch_offset_deg = -90.0; + /* The angle is set to 1/1000th of a degree from the poles to avoid the + * singularity where the azimuthal angle becomes undefined, inducing optical + * artefacts. The arbitrary angle offset is visually unnoticeable while + * avoiding any possible floating point truncation artefacts. */ + if ( _goal_pitch_offset_deg < -89.999 ) { + _goal_pitch_offset_deg = -89.999; } - if ( _goal_pitch_offset_deg > 90.0 ) { - _goal_pitch_offset_deg = 90.0; + if ( _goal_pitch_offset_deg > 89.999 ) { + _goal_pitch_offset_deg = 89.999; } } -- 2.39.5