44
55#define MAX_PROCEDURES 100
66
7- #define MENU_ITEM_FLIP 10000
8- #define MENU_ITEM_SHOW_LABELS 10001
9- #define MENU_ITEM_PROCEDURES_SEL_START 20000
10- #define MENU_ITEM_PROCEDURES_NEW_START 30000
7+ #define MENU_ITEM_FLIP 10000
8+ #define MENU_ITEM_SHOW_LABELS 10001
9+ #define MENU_ITEM_CORRECT_FOR_TEMPERATURE 10002
10+ #define MENU_ITEM_PROCEDURES_SEL_START 20000
11+ #define MENU_ITEM_PROCEDURES_NEW_START 30000
1112
1213BEGIN_MESSAGE_MAP (IWWindow, CWnd)
1314 ON_WM_PAINT()
@@ -28,6 +29,7 @@ BEGIN_MESSAGE_MAP(IWWindow, CWnd)
2829 ON_MESSAGE(WM_EXITSIZEMOVE, &IWWindow::OnExitSizeMove)
2930 ON_COMMAND_EX(MENU_ITEM_FLIP, &IWWindow::OnMenuOptionSelected)
3031 ON_COMMAND_EX(MENU_ITEM_SHOW_LABELS, &IWWindow::OnMenuOptionSelected)
32+ ON_COMMAND_EX(MENU_ITEM_CORRECT_FOR_TEMPERATURE, &IWWindow::OnMenuOptionSelected)
3133 ON_COMMAND_RANGE(MENU_ITEM_PROCEDURES_SEL_START, MENU_ITEM_PROCEDURES_SEL_START + MAX_PROCEDURES, &IWWindow::OnProcedureSelected)
3234 ON_COMMAND_RANGE(MENU_ITEM_PROCEDURES_NEW_START, MENU_ITEM_PROCEDURES_NEW_START + MAX_PROCEDURES, &IWWindow::OnProcedureSelected)
3335END_MESSAGE_MAP()
@@ -476,10 +478,18 @@ void IWWindow::OnLButtonDown(UINT nFlags, CPoint point)
476478bool IWWindow::CalculateTargetCoordinates (const IWTargetPosition& position, CPoint& ptTopView, CPoint& ptSideView)
477479{
478480 // Calculate position relative to the runway
479- double heightAboveThreshold = position.trueAltitude - selectedApproach.thresholdAltitude ;
480481 double distanceToThreshold = CalculateDistance (position.latitude , position.longitude , selectedApproach.thresholdLatitude , selectedApproach.thresholdLongitude );
481482 double directionToThreshold = CalculateBearing (position.latitude , position.longitude , selectedApproach.thresholdLatitude , selectedApproach.thresholdLongitude );
482483 double angleDiff = (selectedApproach.localizerCourse - directionToThreshold) / 180.0 * PI; // anglediff in radians
484+ double heightAboveThreshold = position.pressureCorrectedAltitude - selectedApproach.thresholdAltitude ;
485+
486+ if (applyTemperatureCorrection) {
487+ // In newer flight simulators true altitude is affected by the temperature.
488+ // In cold weather aircraft will be shown higher than they actually are, unless we correct for it.
489+ // See: https://forums.flightsimulator.com/t/vatsim-ivao-pilotedge-users-be-aware-of-an-important-bug/426142/468
490+ int temperatureCorrection = CalculateTemperatureCorrection (position.pressureCorrectedAltitude , selectedApproach.thresholdAltitude , m_latestLiveData.airportTemperatures [selectedApproach.airport ]);
491+ heightAboveThreshold -= temperatureCorrection;
492+ }
483493
484494 double projectedDistanceFromThreshold = distanceToThreshold * cos (angleDiff);
485495 double projectedDistanceFromExtendedCenterline = distanceToThreshold * tan (angleDiff);
@@ -559,6 +569,13 @@ double IWWindow::CalculateBearing(double lat1, double lon1, double lat2, double
559569 return bearing * 180.0 / PI;
560570}
561571
572+ double IWWindow::CalculateTemperatureCorrection (int planePressAlt, int airportPressureAlt, double surfTemp) {
573+ double isaDeviation = surfTemp - 15 ;
574+
575+ // Formula is from here: https://www.pprune.org/tech-log/573002-accurate-temperature-correction-formula.html
576+ return ((-isaDeviation / -0.0019812 ) * std::log (1 + (-0.0019812 * planePressAlt) / (288.15 + -0.0019812 * airportPressureAlt)));
577+ }
578+
562579std::string IWWindow::GetActiveApproachName () const
563580{
564581 std::lock_guard<std::mutex> lock (approachDataMutex);
@@ -611,6 +628,11 @@ void IWWindow::CreatePopupMenu(CPoint point)
611628 MENU_ITEM_SHOW_LABELS,
612629 _T (" Show labels by default" )
613630 );
631+ menu.AppendMenu (
632+ MF_STRING | (this ->applyTemperatureCorrection ? MF_CHECKED : MF_UNCHECKED),
633+ MENU_ITEM_CORRECT_FOR_TEMPERATURE,
634+ _T (" Apply temperature correction" )
635+ );
614636 menu.AppendMenu (
615637 MF_STRING,
616638 MENU_ITEM_FLIP,
@@ -619,6 +641,7 @@ void IWWindow::CreatePopupMenu(CPoint point)
619641
620642 // Display the menu
621643 menu.TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x , point.y , this );
644+
622645}
623646
624647BOOL IWWindow::OnMenuOptionSelected (UINT nID)
@@ -634,6 +657,11 @@ BOOL IWWindow::OnMenuOptionSelected(UINT nID)
634657 this ->showTagsByDefault = !this ->showTagsByDefault ;
635658 Invalidate ();
636659 }
660+ else if (nID == MENU_ITEM_CORRECT_FOR_TEMPERATURE)
661+ {
662+ this ->applyTemperatureCorrection = !this ->applyTemperatureCorrection ;
663+ Invalidate ();
664+ }
637665 return TRUE ;
638666}
639667
0 commit comments