From 86c76402b6cd20d277bf4fd6d9309234b49b73cf Mon Sep 17 00:00:00 2001 From: jmbaud Date: Sun, 6 Nov 2022 15:36:05 +0100 Subject: [PATCH] Fix AGL altitude calculation for fixed landing gears and reorganize this code a little bit. --- src/sardraw.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/sardraw.c b/src/sardraw.c index 956dc12..e03fbbf 100644 --- a/src/sardraw.c +++ b/src/sardraw.c @@ -3791,31 +3791,23 @@ static void SARDrawOutsideAttitude( y += 18; /* Altitude AGL */ + if(aircraft->landed) + v1 = 0.0f; + else + v1 = (float)MAX( + -(((((gear_state == 1) || (gear_state == 2)) ? aircraft->gear_height : 0.0f) + + aircraft->belly_height) + + aircraft->center_to_ground_height), 0.0f + ); switch(opt->units) { case SAR_UNITS_METRIC: - if(aircraft->landed) - v1 = 0.0f; - else - v1 = (float)MAX( - -((((gear_state == 1) ? aircraft->gear_height : 0.0f) + - aircraft->belly_height) + - aircraft->center_to_ground_height), 0.0f - ); units_str1 = "M"; break; + case SAR_UNITS_METRIC_ALT_FEET: default: - if(aircraft->landed) - v1 = 0.0f; - else - v1 = (float)SFMMetersToFeet( - MAX( - -((((gear_state == 1) ? aircraft->gear_height : 0.0f) + - aircraft->belly_height) + - aircraft->center_to_ground_height), 0.0f - ) - ); + v1 = (float)SFMMetersToFeet(v1); units_str1 = "FT"; break; }