Rise
The Vieneo Province
Loading...
Searching...
No Matches
TCASOverlay.cpp
Go to the documentation of this file.
1#include "../Instrument.h"
2
3#include "../../TcasAudio.h"
4
5TCASOverlay::TCASOverlay(int prmX, int prmY, float prmXScale, float prmYScale, Bus* prmBus, Logger* prmLogger, DeviceObject* prmDevice, std::vector<Font*> prmFonts) :
6 Instrument(prmX, prmY, prmXScale, prmYScale, prmBus, prmLogger, prmDevice, prmFonts)
7{
8 logger->AddToCallStack("TCAS::ctor");
9 defaultFont = 1;
10
11 noThreat = new Sprite(logger, pDevice, "Textures/Instruments/TCAS.png", x, y, 0.3f, 0, 0, 28, 28, 0xFFFFFFFF, xScale, yScale);
12 proximate = new Sprite(logger, pDevice, "Textures/Instruments/TCAS.png", x, y, 0.3f, 28, 0, 28, 28, 0xFFFFFFFF, xScale, yScale);
13 potentialThreat = new Sprite(logger, pDevice, "Textures/Instruments/TCAS.png", x, y, 0.3f, 56, 0, 28, 28, 0xFFFFFFFF, xScale, yScale);
14 collisionThreat = new Sprite(logger, pDevice, "Textures/Instruments/TCAS.png", x, y, 0.3f, 84, 0, 28, 28, 0xFFFFFFFF, xScale, yScale);
15
16 // offset from middle to top left of 28x28 sprite
17 iconOffsetX = 14 * xScale;
18 iconOffsetY = 14 * yScale;
19
20 relativeCenter = RiseMath::Vector2(530.0f * 0.5f * xScale, 530.0f * 0.5f * yScale);
21}
22
24{
25 const auto drawTarget = [&](Sprite* symbol, int left, int top, float altitude, const wchar_t* label, DWORD color) {
26 symbol->SetLocation(left, top);
27 symbol->Update();
28 symbol->Draw(color);
29 DrawTextW(label, left - x, top - y + (altitude > 0 ? -10 : 10), 0.4f, DT_NOCLIP, color);
30 };
32 {
33 // Synthetic contacts stay in this renderer, never in the scanner or live RA state.
34 // Render from the bus even when this page was opened midway through the test.
35 // Finish the map batch so its high-layer assay/terrain labels cannot cover this check.
36 HRESULT hr;
38 const int cx = static_cast<int>(relativeCenter.x), top = static_cast<int>(relativeCenter.y) - 84;
39 DrawTextW(L"TCAS TEST", cx, top + 7, 0.4f, DT_CENTER | DT_NOCLIP, 0xFFFFFFFF);
40 const int callout = bus->TCASTestCallout;
41 if (callout >= 0 && callout < TcasAudio::Count)
42 {
43 const DWORD color = callout == 0 ? 0xFFFFAA00 : callout < 13 ? 0xFFFF0000 : 0xFFFFFFFF;
44 DrawTextW(TcasAudio::Callouts[callout].testInstruction, cx, top + 21, 0.4f, DT_CENTER | DT_NOCLIP, color);
45 DrawTextW(TcasAudio::Callouts[callout].testDetail, cx, top + 34, 0.4f, DT_CENTER | DT_NOCLIP, color);
46 }
47 else
48 DrawTextW(L"DISPLAY CHECK", cx, top + 21, 0.4f, DT_CENTER | DT_NOCLIP, 0xFFFFFFFF);
49 const int row = y + top + 64;
50 drawTarget(noThreat, x + cx - 51, row, .5f, L"05", 0xFF0088FF);
51 drawTarget(proximate, x + cx - 21, row, -.1f, L"01", 0xFF0088FF);
52 drawTarget(potentialThreat, x + cx + 9, row, .2f, L"02\u2191", 0xFFFFAA00);
53 drawTarget(collisionThreat, x + cx + 39, row, -.2f, L"02\u2193", 0xFFFF0000);
54 return;
55 }
56 if (bus->TCAS >= Bus::RA_Climb)
57 {
58 const wchar_t* instruction = L"MONITOR VERTICAL SPEED";
59 switch (bus->TCAS)
60 {
61 case Bus::RA_Climb: instruction = L"CLIMB"; break;
62 case Bus::RA_Descend: instruction = L"DESCEND"; break;
63 case Bus::RA_Increase_Climb: instruction = L"INCREASE CLIMB"; break;
64 case Bus::RA_Increase_Descent: instruction = L"INCREASE DESCENT"; break;
65 case Bus::RA_Reduce_Climb: instruction = L"REDUCE CLIMB / LEVEL OFF"; break;
66 case Bus::RA_Reduce_Descent: instruction = L"REDUCE DESCENT / LEVEL OFF"; break;
67 case Bus::RA_Maintain_Climb: case Bus::RA_Maintain_Descent: instruction = L"MAINTAIN VERTICAL SPEED"; break;
68 case Bus::RA_Climb_Now: instruction = L"CLIMB NOW"; break;
69 case Bus::RA_Descend_Now: instruction = L"DESCEND NOW"; break;
70 case Bus::RA_Adjust: instruction = L"ADJUST / LEVEL OFF"; break;
71 case Bus::RA_Monitor_Climb: instruction = L"DO NOT DESCEND"; break;
72 case Bus::RA_Monitor_Descent: instruction = L"DO NOT CLIMB"; break;
73 }
74 wchar_t text[128];
75 swprintf_s(text, L"%ls%ls %+.0f FPM", instruction, bus->TCASCrossing ? L" - CROSSING" : L"",
76 bus->TCASTargetVerticalSpeedKms * 196850.394f);
77 DrawTextW(text, 10, 10, 0.4f, DT_NOCLIP, 0xFFFF0000);
78 }
79 for (UINT i = 0; i < targets.size(); i++)
80 {
81 const s_network_objects target = targets.at(i);
82
83 DWORD color = 0xFF0088FF;
84 if (target.ordinal == bus->TCASTargetOrdinal)
85 {
87 color = 0xFFFFAA00;
88 else if (bus->TCAS >= Bus::TcasEnum::RA_Climb)
89 color = 0xFFFF0000;
90 }
91
92 Sprite* symbol = color == 0xFFFFAA00 ? potentialThreat : color == 0xFFFF0000 ? collisionThreat :
93 (fabsf(target.acc.z) <= 0.36576f ? proximate : noThreat); // Proximate within 1,200 feet.
94 drawTarget(symbol, static_cast<int>(target.acc.x), static_cast<int>(target.acc.y), target.acc.z, target.tcasOnly, color);
95 }
96}
97
98void TCASOverlay::FrameMove(float fElapsed)
99{
100 targets.clear();
101
102 if (!playerships[0].transponder)
103 return;
104
106
107 // so 6.28 - 0 is a 6.28 or -6.28 difference!
108 float diff = headingTrueRad - rotate;
109 if (diff > RiseMath::Pi)
110 diff -= RiseMath::Tau;
111 else if (diff < -RiseMath::Pi)
112 diff += RiseMath::Tau;
113
114 rotate += diff * fElapsed;
115
116 /*diff = rotate - bus->AFCS.DesiredHeadingRadians;
117 if (diff > RiseMath::Pi)
118 diff -= RiseMath::Tau;
119 else if (diff < -RiseMath::Pi)
120 diff += RiseMath::Tau;*/
121
122 pixelPerKmX = 530.0f * 0.25f / bus->MapScaleInnerRingKm * xScale;
123 pixelPerKmY = 530.0f * 0.25f / bus->MapScaleInnerRingKm * yScale;
124
125 RiseMath::Vector3 posnorml;
126 RiseMath::Vec3Normalize(&posnorml, &playerships[0].position);
127 RiseMath::Matrix lookAtLH;
128 RiseMath::MatrixLookAtLH(&lookAtLH, &playerships[0].position, &northpoleK, &posnorml);
129 RiseMath::Matrix matrixRot;
131 lookAtLH = lookAtLH * matrixRot;
132
133 for (UINT ii = 1; ii < MAX_SCAN; ii++)
134 {
135 s_network_objects target = playerships[ii];
136
137 if (!target.active || !target.visible || !target.isOnScanner)
138 continue;
139
140 if (!target.logolight ||
141 //target.docked || // we want to show them but not alert on them
142 target.groundvehicle ||
143 !target.transponder ||
144 //target.reference == REF_ONGROUND || // we want to show them but not alert on them
145 target.reference == REF_INANOTHER ||
146 target.distance >= 74.08f || // TCAS limited to 40 NM
147 target.altitudeDiffAbs >= 3.01752f || // 9900 feet
148 target.type == VehicleType::FloatingMan ||
149 target.type == VehicleType::BeishtKione)
150 //target.closurerate <= 0.0f) // we want to show them but not alert on them
151 continue;
152
153 RiseMath::Vector3 result1;
154 RiseMath::Vec3TransformCoord(&result1, &target.position, &lookAtLH);
155
156 // if they are more than 10,000 feet difference then we skip
157 // Bill wanted this turned off 11/12/2022
158 //if (fabsf(result1.z) >= 3.0f)
159 //continue;
160
161 // if distance is beyond 2x scale then skip
162 RiseMath::Vector2 result2 = RiseMath::Vector2(result1.x, result1.y);
163 const float dist = RiseMath::Vec2Length(&result2);
164 if (dist > bus->MapScaleInnerRingKm * 2.0f)
165 continue;
166
167 const RiseMath::Vector2 diff2d = RiseMath::Vector2(-result2.x * pixelPerKmX, result2.y * pixelPerKmY);
168 RiseMath::Vector2 nextWaypoint = relativeCenter + diff2d;
169 nextWaypoint.x = static_cast<int>(nextWaypoint.x) - iconOffsetX;
170 nextWaypoint.y = static_cast<int>(nextWaypoint.y) - iconOffsetY;
171 target.acc.x = nextWaypoint.x + x;
172 target.acc.y = nextWaypoint.y + y;
173 target.acc.z = -result1.z; // relative altitude!
174 if (fabsf(target.acc.z) < 0.05f)
175 target.acc.z = 0.0f;
176 swprintf_s(target.tcasOnly, 16, L"%02.0f", fabsf(target.acc.z) * 10.0f); // .5 km becomes 05, 3.0 becomes 30
177 if (target.vsi > 0.001f)
178 wcscat_s(target.tcasOnly, 16, L"\u2191"); // up arrow
179 else if (target.vsi < -0.001f)
180 wcscat_s(target.tcasOnly, 16, L"\u2193"); // down arrow
181
182 target.ordinal = ii;
183
184 targets.emplace_back(target);
185 }
186}
#define V(expression)
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
@ BeishtKione
Definition ServerTypes.h:83
@ FloatingMan
Definition ServerTypes.h:88
#define MAX_SCAN
const RiseMath::Vector3 northpoleK
@ REF_INANOTHER
Definition ServerTypes.h:45
Definition Bus.h:20
float MapScaleInnerRingKm
Definition Bus.h:490
short TCASTargetOrdinal
Definition Bus.h:339
int TCASTestCallout
Definition Bus.h:342
@ RA_Maintain_Descent
Definition Bus.h:334
@ RA_Increase_Descent
Definition Bus.h:330
@ RA_Maintain_Climb
Definition Bus.h:333
@ RA_Monitor_Climb
Definition Bus.h:327
@ Traffic_Advisory
Definition Bus.h:324
@ RA_Reduce_Descent
Definition Bus.h:332
@ RA_Climb_Now
Definition Bus.h:335
@ RA_Monitor_Descent
Definition Bus.h:328
@ RA_Increase_Climb
Definition Bus.h:329
@ RA_Descend
Definition Bus.h:326
@ RA_Climb
Definition Bus.h:325
@ RA_Adjust
Definition Bus.h:337
@ RA_Reduce_Climb
Definition Bus.h:331
@ RA_Descend_Now
Definition Bus.h:336
bool TCASTestActive
Definition Bus.h:341
float HeadingTrueDegrees
Definition Bus.h:41
float TCASTargetVerticalSpeedKms
Definition Bus.h:344
bool TCASCrossing
Definition Bus.h:343
enum Bus::TcasEnum TCAS
Rendering::RenderSprite * pSprite
Bus * bus
Definition Instrument.h:22
float xScale
Definition Instrument.h:19
float yScale
Definition Instrument.h:20
Instrument(int prmX, int prmY, float prmXScale, float prmYScale, Bus *prmBus, Logger *prmLogger, DeviceObject *prmDevice, std::vector< Font * > prmFonts)
Definition Instrument.h:36
Logger * logger
Definition Instrument.h:23
DeviceObject * pDevice
Definition Instrument.h:21
UINT defaultFont
Definition Instrument.h:24
void AddToCallStack(const char *msg)
Definition Logger.cpp:355
void SetLocation(int absoluteX, int absoluteY)
Definition Sprite.cpp:99
Sprite(Logger *prmLogger, DeviceObject *prmpDevice, std::string prmPathAndFilename, int prmX, int prmY, float prmZ, int prmTop, int prmLeft, int prmWidth, int prmHeight, DWORD prmColor, float scaleX=1.0f, float scaleY=1.0f)
Definition Sprite.cpp:5
void Draw(RiseMath::Color prmColor)
Definition Sprite.cpp:75
void Update()
Definition Sprite.cpp:50
Sprite * collisionThreat
Definition Instrument.h:691
TCASOverlay(int prmX, int prmY, float prmXScale, float prmYScale, Bus *prmBus, Logger *prmLogger, DeviceObject *prmDevice, std::vector< Font * > prmFonts)
float pixelPerKmY
Definition Instrument.h:693
Sprite * proximate
Definition Instrument.h:689
float iconOffsetX
Definition Instrument.h:695
std::vector< s_network_objects > targets
Definition Instrument.h:694
void FrameMove(float fElapsed) override
float pixelPerKmX
Definition Instrument.h:692
Sprite * potentialThreat
Definition Instrument.h:690
float headingTrueRad
Definition Instrument.h:697
float iconOffsetY
Definition Instrument.h:696
void Render() override
Sprite * noThreat
Definition Instrument.h:688
RiseMath::Vector2 relativeCenter
Definition Instrument.h:698
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
auto ToRadian(T value)
Definition ClientMath.h:13
constexpr float Pi
Definition ClientMath.h:12
Vector3 * Vec3TransformCoord(Vector3 *out, const Vector3 *a, const Matrix *m)
Definition ClientMath.h:109
float Vec2Length(const Vector2 *a)
Definition ClientMath.h:92
Matrix * MatrixLookAtLH(Matrix *out, const Vector3 *eye, const Vector3 *at, const Vector3 *up)
Definition ClientMath.h:139
constexpr float Tau
Definition ClientMath.h:12
Vector3 * Vec3Normalize(Vector3 *out, const Vector3 *a)
Definition ClientMath.h:103
Matrix * MatrixRotationZ(Matrix *out, float value)
Definition ClientMath.h:128
constexpr int Count
Definition TcasAudio.h:36
constexpr Callout Callouts[]
Definition TcasAudio.h:19