Skip to content

Commit 6fa90e9

Browse files
committed
ptl tool fixed, now works correctly regardless of rotation settings
1 parent d8a6bfb commit 6fa90e9

File tree

2 files changed

+42
-28
lines changed

2 files changed

+42
-28
lines changed

CSiTRadar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void CSiTRadar::OnRefresh(HDC hdc, int phase)
145145

146146
// Draw PTL
147147
if (hasPTL.find(radarTarget.GetCallsign()) != hasPTL.end()) {
148-
HaloTool::drawPTL(&dc, radarTarget, p, 3, pixnm);
148+
HaloTool::drawPTL(&dc, radarTarget, this, p, 3);
149149
}
150150

151151
// Get information about the Aircraft/Flightplan

HaloTool.h

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,60 +11,74 @@ class HaloTool :
1111
{
1212
public:
1313

14-
static void drawHalo(CDC* dc, POINT p, double r, double pixpernm)
14+
static inline double degtorad(double deg) {
15+
double ans = deg * PI / 180;
16+
return ans;
17+
}
18+
19+
static CPosition calcPTL(CPosition origin, double ptlLen, double gs, double bearing) {
20+
double lat2;
21+
double long2;
22+
double earthRad = 3440; // in nautical miles
23+
24+
lat2 = asin(sin(origin.m_Latitude * PI / 180) * cos((ptlLen * gs / 60) / earthRad) + cos(origin.m_Latitude * PI / 180) * sin((ptlLen * gs / 60) / earthRad) * cos(bearing * PI / 180));
25+
long2 = degtorad(origin.m_Longitude) + atan2((sin(bearing * PI / 180)) * sin((ptlLen * gs / 60) / earthRad) * cos(origin.m_Latitude * PI / 180), (cos(sin(bearing * PI / 180) / earthRad) - sin(origin.m_Latitude * PI / 180) * sin(lat2)));
26+
CPosition ptlEnd;
27+
28+
ptlEnd.m_Latitude = lat2 * 180 / PI;
29+
ptlEnd.m_Longitude = long2 * 180 / PI;
30+
31+
return ptlEnd;
32+
};
33+
34+
static double calcBearing(CPosition origin, CPosition end) {
35+
double y = sin(degtorad(end.m_Longitude) - degtorad(origin.m_Longitude)) * cos(degtorad(end.m_Latitude));
36+
double x = cos(degtorad(origin.m_Latitude)) * sin(degtorad(end.m_Latitude)) - sin(degtorad(origin.m_Latitude)) * cos(degtorad(end.m_Latitude)) * cos(degtorad(end.m_Longitude) - degtorad(origin.m_Longitude));
37+
double phi = atan2(y, x);
38+
double bearing = fmod((phi * 180 / PI + 360), 360);
39+
40+
return bearing;
41+
}
42+
43+
static void drawHalo(CDC* dc, POINT p, double r, double pixpernm)
1544
{
1645
int sDC = dc->SaveDC();
1746

1847
//calculate pixels per nautical mile
1948

2049
int pixoffset = (int)round(pixpernm * r);
2150

22-
// draw the halo around point p with radius r in NM
51+
// draw the halo around point p with radius r in NM
2352
COLORREF targetPenColor = RGB(202, 205, 169);
2453
HPEN targetPen = CreatePen(PS_SOLID, 1, targetPenColor);
2554
dc->SelectObject(targetPen);
2655
dc->SelectStockObject(HOLLOW_BRUSH);
27-
dc->Ellipse(p.x - pixoffset, p.y - pixoffset, p.x + pixoffset, p.y + pixoffset);
56+
dc->Ellipse(p.x - pixoffset, p.y - pixoffset, p.x + pixoffset, p.y + pixoffset);
2857

2958
DeleteObject(targetPen);
30-
59+
3160
dc->RestoreDC(sDC);
3261
};
3362

34-
static void drawPTL(CDC* dc, CRadarTarget radtar, POINT p, double ptlTime, double pixpernm)
63+
static void drawPTL(CDC* dc, CRadarTarget radtar, CRadarScreen* radscr, POINT p, double ptlTime)
3564
{
3665
int sDC = dc->SaveDC();
37-
38-
double theta = (radtar.GetTrackHeading() + CSiTRadar::magvar) * PI / 180;
39-
double ptlDistance = radtar.GetGS() / 60 * ptlTime * pixpernm;
40-
double ptlYdelta = -cos(theta) * ptlDistance;
41-
double ptlXdelta = sin(theta) * ptlDistance;
66+
67+
CPosition pos1 = radtar.GetPreviousPosition(radtar.GetPosition()).GetPosition();
68+
CPosition pos2 = radtar.GetPosition().GetPosition();
69+
double theta = calcBearing(pos1, pos2);
70+
CPosition ptl = calcPTL(radtar.GetPosition().GetPosition(), ptlTime, radtar.GetPosition().GetReportedGS(), theta);
71+
POINT p2 = radscr->ConvertCoordFromPositionToPixel(ptl);
4272

4373
COLORREF targetPenColor = C_PTL_GREEN;
4474
HPEN targetPen = CreatePen(PS_SOLID, 1, targetPenColor);
4575
dc->SelectObject(targetPen);
4676

4777
dc->MoveTo(p);
48-
dc->LineTo(p.x + (int)round(ptlXdelta), p.y + (int)round(ptlYdelta));
78+
dc->LineTo(p2);
4979

5080
DeleteObject(targetPen);
5181

5282
dc->RestoreDC(sDC);
5383
};
54-
55-
static CPosition calcPTL(CPosition origin, double ptlLen, double gs, double bearing) {
56-
double lat2;
57-
double long2;
58-
double earthRad = 3440; // in nautical miles
59-
60-
lat2 = asin(sin(origin.m_Latitude * PI / 180) * cos((ptlLen * gs / 60) / earthRad) + cos(origin.m_Latitude * PI / 180) * sin((ptlLen*gs/60) / earthRad) * cos(bearing * PI/180));
61-
long2 = origin.m_Longitude + atan2((sin(bearing * PI / 180)) * sin((ptlLen * gs / 60) / earthRad) * cos(origin.m_Latitude * PI / 180), (cos(sin(bearing * PI / 180) / earthRad) - sin(origin.m_Latitude * PI / 180) * sin(lat2)));
62-
CPosition ptlEnd;
63-
64-
ptlEnd.m_Latitude = lat2 * 180 / PI;
65-
ptlEnd.m_Longitude = long2 * 180 / PI;
66-
67-
return ptlEnd;
68-
};
6984
};
70-

0 commit comments

Comments
 (0)