Rise
The Vieneo Province
Loading...
Searching...
No Matches
AttitudeIndicator2.cpp
Go to the documentation of this file.
1#include "../Instrument.h"
2
3AttitudeIndicator2::AttitudeIndicator2(int prmX, int prmY, float prmXScale, float prmYScale, Bus* prmBus, Logger* prmLogger, DeviceObject* prmDevice, std::vector<Font*> prmFonts) :
4 Instrument(prmX, prmY, prmXScale, prmYScale, prmBus, prmLogger, prmDevice, prmFonts)
5{
6 logger->AddToCallStack("AttitudeIndicator2::ctor");
7
8 // so 1:1 scale is 143x137
9 float width = 143;
10 float height = 137;
11 int textureWidth = 240;
12 int textureHeight = 600;
13
14 // to make sure we don't show blackness we need to expand based on hypotenuse
15
16 // old design which showed 45 degrees so that is 1/4 of the height
17 float tvHeight = height; // displayed height
18 tvHalfHeight = tvHeight * 0.5f;
19 float tvWidth = width;
20 float tvScale = height / tvHeight; // to blow up to fit the height
21 tvpitchscale = 2.0f / RiseMath::ToRadian(1);// tvHeight / RiseMath::ToRadian(45.0f); // 2 px per degree converted to radian
22 tvvertoffset = textureHeight * 0.5f; // halfway down on the sprite
23 const float hypotenuse = sqrtf(powf(width, 2.0f) + powf(height, 2.0f));
24 tvLeftRightMargins = static_cast<int>((hypotenuse - tvWidth) * 0.5f);
25 tvTopBottomMargins = static_cast<int>((hypotenuse - tvHeight) * 0.5f);
26
27 tvleft = static_cast<int>(textureWidth * 0.5f - tvWidth * 0.5f) - tvLeftRightMargins;
28 tvright = static_cast<int>(textureWidth * 0.5f + tvWidth * 0.5f) + tvLeftRightMargins;
29 tvTop = static_cast<int>(tvvertoffset - tvHalfHeight - tvTopBottomMargins);
31
32 scissor_rect.left = x;
33 scissor_rect.top = y;
34 scissor_rect.right = x + static_cast<long>(width);
35 scissor_rect.bottom = y + static_cast<long>(height);
36
37 artificialHorizon = new Sprite(logger, pDevice, "Textures/Instruments/NewHorizon.png", prmX - tvLeftRightMargins, prmY - tvTopBottomMargins, 0.1f, 0, 0, textureWidth, textureHeight, 0xFFFFFFFF, tvScale, tvScale);
38 artificialHorizon->SetRotationCenter(RiseMath::Vector2(textureWidth * 0.5f - tvleft, tvHalfHeight + tvTopBottomMargins));
39
40 commandBars = new Sprite(logger, pDevice, "Textures/Instruments/command bars.png", prmX, prmY, 0.9f, 0, 0, 219, 70, 0xFFFFFFFF, 0.338f, 0.338f);
41 cbpitchscale = 2.0f / RiseMath::ToRadian(1); // 67 pixels for 10 degrees converted to radian
42 cbvertoffset = y + 56.0f;
43
44 vector = new Sprite(logger, pDevice, "Textures/Instruments/vector-prograde.png", prmX, prmY, 0.5f, 0, 0, 32, 32, 0xFFFFFFFF);
45 reticle = new Sprite(logger, pDevice, "Textures/Instruments/reticle.png", prmX, prmY, 0.5f, 0, 0, 32, 32, 0xFFFFFFFF);
46
47 localizerBox = new Sprite(logger, pDevice, "Textures/Instruments/localizer.png", prmX + 42, prmY + 115, 0.4f, 0, 0, 120, 19, 0xFFFFFFFF, prmXScale * 0.5f, prmYScale * 0.5f);
48 failFlagLocalizer = new Sprite(logger, pDevice, "Textures/Instruments/yellow_x.png", prmX + 42, prmY + 115, 0.5f, 0, 0, 38, 55, 0xFFFFFFFF, prmXScale * 1.579f, prmYScale * 0.173f);
49 glideslopeBox = new Sprite(logger, pDevice, "Textures/Instruments/glideslope.png", prmX + 118, prmY + 39, 0.4f, 0, 0, 19, 120, 0xFFFFFFFF, prmXScale * 0.5f, prmYScale * 0.5f);
50 localizerBug = new Sprite(logger, pDevice, "Textures/Instruments/glideslope-bug.png", prmX + 76, prmY + 38, 0.5f, 0, 0, 18, 18, 0xFFFFFFFF, prmXScale * 0.5f, prmYScale * 0.5f);
51 failFlagGlideslope = new Sprite(logger, pDevice, "Textures/Instruments/yellow_x.png", prmX + 118, prmY + 39, 0.5f, 0, 0, 38, 55, 0xFFFFFFFF, prmXScale * 0.25f, prmYScale * 1.091f);
52 glideslopeBug = new Sprite(logger, pDevice, "Textures/Instruments/glideslope-bug.png", prmX + 70, prmY + 38, 0.5f, 0, 0, 18, 18, 0xFFFFFFFF, prmXScale * 0.5f, prmYScale * 0.5f);
53
54 aoaHigh = new Sprite(logger, pDevice, "Textures/Instruments/aoahigh.dds", prmX + 55, prmY - 2, 0.5f, 0, 0, 32, 32, 0xFFFFFFFF);
55 aoa = new Sprite(logger, pDevice, "Textures/Instruments/aoa.dds", prmX, prmY, 0.5f, 0, 0, 32, 32, 0xFFFFFFFF);
56 aoaLow = new Sprite(logger, pDevice, "Textures/Instruments/aoalow.dds", prmX + 55, prmY + 108, 0.5f, 0, 0, 32, 32, 0xFFFFFFFF);
57
58 bankAngle = new Sprite(logger, pDevice, "Textures/Instruments/bankAngle.png", prmX, prmY, 0.5f, 0, 0, 142, 138, 0xFFFFFFFF);
59 slipSkid = new Sprite(logger, pDevice, "Textures/Instruments/slipSkid.png", prmX, prmY, 0.5f, 0, 0, 142, 138, 0xFFFFFFFF);
60
61 markerBeacon = new Sprite(logger, pDevice, "Textures/Instruments/markerBeacons.png", prmX + 40, prmY + 42, 0.5f, 0, 0, 64, 16, 0xFFFFFFFF);
62}
63
65{
66 HRESULT hr;
67
68 RECT oldScissorRect;
69 V(pDevice->GetScissorRect(&oldScissorRect));
70
71 try
72 {
74 }
75 catch (...) // this is because if there is nothing in the buffer drawn this will throw an unhandled exception!
76 {
77 }
78
80
81 // artificial horizon is at 1.0
83
84 // then command bars at 0.9
87
89 {
91
94 else
96 }
97
98 // test mode
99 //bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::Glideslope;
100 //bus->GlideslopeDeviationRadians = 999;// RiseMath::ToRadian(sinf(Rendering::ClientTime()) * 1.4f);
102 {
104
105 if (glideslopeAlive)
107 else
109 }
110
111
112 // aoa bugs
113 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
114 switch (lastAOA)
115 {
116 case 0: aoaHigh->Draw(); break;
117 case 1: aoa->Draw(); break;
118 case 2: aoaLow->Draw(); break;
119 }
120
121 if (velocityVec.z == 1.0f)
122 vector->Draw(0xFFFFFFFF); // white
123 else if (velocityVec.z < 0.0f)
124 vector->Draw(0xFFFFFF00); // amber
125
126
127 if (reticleVec.z == 1.0f)
128 reticle->Draw(0xFF00FF00); // green
129 else if (reticleVec.z < 0.0f)
130 reticle->Draw(0xFFFF0000); // red
131
132 bankAngle->Draw();
133 if (bus->PressureAltitudeKm < 100.0f)
134 slipSkid->Draw();
135
138
139 V(pDevice->pSprite->Flush());
140
141 V(pDevice->SetScissorRect(&oldScissorRect));
142}
143
145{
150 roll += (bus->RollAttitudeRadians - roll) * fElapsed;
151 pitch += (bus->PitchAttitudeRadians - pitch) * fElapsed;
152 const int tvPitch = static_cast<int>(pitch * tvpitchscale);
153
154 // test mode
155 //tvpitch = 0;
156 //roll = sinf(Rendering::ClientTime());
160
162 {
163 const bool orbital = bus->AFCS.DorOn && !bus->AFCS.DorAircraft && bus->orbit.guidance.attitude;
164 commandBars->rotate = orbital ? 0.0f : -bus->AFCS.DesiredRollRadians + roll;
165
166 float pitchDev = (orbital ? float(bus->orbit.guidance.pitch) : bus->AFCS.DesiredPitchRadians) - pitch;
167 if (orbital) pitchDev = std::clamp(pitchDev, RiseMath::ToRadian(-20.0f), RiseMath::ToRadian(20.0f));
168
169 // test mode
170 //commandBars->rotate = pitchDev = 0;
171 commandBars->SetLocation(x + 35, static_cast<int>(cbvertoffset - pitchDev * cbpitchscale));
173 }
174
175 // test mode
176 //bus->AFCS.CurrentLateralMode = Bus::Afcs::LateralModes::Localizer;
177 //bus->LocalizerDeviationRadians = 999.0f;// RiseMath::ToRadian(cosf(Rendering::ClientTime()) * 5.0f);
179 if (fabsf(deg) <= 2.5f)
180 {
181 localizerBug->SetLocation(x + 44 + static_cast<int>(47.0f * (deg + 2.5f) / 5.0f), y + 115);
183 if (!localizerAlive)
184 {
185 localizerAlive = true;
186 Command command;
187 command.name = "AuralLocalizerAlive";
188 bus->commandStream.emplace_back(command);
189 }
190 }
191 else if (fabsf(deg) > 3.0f)
192 {
193 localizerAlive = false;
194 }
195
197 if (fabsf(deg) <= 0.7f)
198 {
199 glideslopeBug->SetLocation(x + 118, y + 40 + static_cast<int>(48.0f * (deg + 0.7f) / 1.4f));
202 {
203 glideslopeAlive = true;
204 Command command;
205 command.name = "AuralGlideslopeAlive";
206 bus->commandStream.emplace_back(command);
207 }
208 }
209 else if (fabsf(deg) > 1.0f)
210 {
211 glideslopeAlive = false;
212 }
213
214 // aoa bugs
215 // test mode
216 //bus->AngleOfAttackRadians = RiseMath::ToRadian(0);
217 if (bus->PressureAltitudeKm < 100.0f)
218 {
219 const auto offsety = static_cast<short>(-bus->AngleOfAttackRadians * cbpitchscale + cbvertoffset); // 2 pixels per degree
220 char thisAOA;
221 if (offsety < 24)
222 thisAOA = 0;
223 else if (offsety > 128)
224 thisAOA = 2;
225 else
226 {
227 thisAOA = 1;
228 aoa->SetLocation(x + 55, y - 31 + offsety);
229 aoa->Update();
230 }
231 if (((lastAOA == 2 && thisAOA == 0) || (lastAOA == 0 && thisAOA == 2)) &&
232 playerships[0].reference != REF_ONGROUND && //bus->IndicatedAirspeedKms > 0.02f &&
233 ourcockpit.power > 0.5f)
234 {
235 Command command;
236 command.name = "AuralAOA";
237 bus->AddCommand(command, true);
238 }
239 lastAOA = thisAOA;
240 }
241 else
242 lastAOA = -1;
243
244
245 // Velocity vector
246 // test mode
247 //bus->FlightPathAngleDegrees = RiseMath::Vector2(0,0);
248 if (bus->FlightPathVectorDegrees.x != 999.0f && bus->FlightPathVectorDegrees.y != 999.0f)
249 {
250 // Adjust for center of ADI
251 if (fabsf(bus->FlightPathVectorDegrees.x) > 90.0f)
252 {
253 velocityVec.z = -1.0f;
254 if (bus->FlightPathVectorDegrees.x > 90.0f)
255 velocityVec.x = 72.0f - (bus->FlightPathVectorDegrees.x - 180.0f) * 2.0f;
256 else
257 velocityVec.x = 72.0f - (bus->FlightPathVectorDegrees.x + 180.0f) * 2.0f;
258 }
259 else
260 {
261 velocityVec.z = 1.0f;
262 velocityVec.x = 72.0f + bus->FlightPathVectorDegrees.x * 2.0f;
263 }
265 if (velocityVec.x < 1)
266 velocityVec.x = 1;
267 else if (velocityVec.x > 143)
268 velocityVec.x = 143;
269 if (velocityVec.y < 1)
270 velocityVec.y = 1;
271 else if (velocityVec.y > 137)
272 velocityVec.y = 137;
273 // Adjust for upper left of sprite
274 velocityVec.x -= 16.0f;
275 velocityVec.y -= 16.0f;
276 vector->SetLocation(x + static_cast<int>(velocityVec.x), y + static_cast<int>(velocityVec.y));
277 vector->Update();
278 }
279 else
280 velocityVec.z = 0.0f;
281
282
283 // Bearing/mark reticle
284 // test mode
285 //bus->TargetBearingDeg = mark = 0;
286 if (bus->TargetBearingDeg != 999.0f && mark != 999.0f)
287 {
288 // Adjust for center of ADI
289 if (fabsf(bus->TargetBearingDeg) > 90.0f)
290 {
291 reticleVec.z = -1.0f;
292 if (bus->TargetBearingDeg > 90.0f)
293 reticleVec.x = 72.0f - (bus->TargetBearingDeg - 180.0f) * 2.0f;
294 else
295 reticleVec.x = 72.0f - (bus->TargetBearingDeg + 180.0f) * 2.0f;
296 }
297 else
298 {
299 reticleVec.z = 1.0f;
300 reticleVec.x = 72.0f + bus->TargetBearingDeg * 2.0f;
301 }
303 if (reticleVec.x < 1.0f)
304 reticleVec.x = 1.0f;
305 else if (reticleVec.x > 143)
306 reticleVec.x = 143;
307 if (reticleVec.y < 1.0f)
308 reticleVec.y = 1.0f;
309 else if (reticleVec.y > 137)
310 reticleVec.y = 137;
311 // Adjust for upper left of sprite
312 reticleVec.x -= 16.0f;
313 reticleVec.y -= 16.0f;
314 reticle->SetLocation(x + static_cast<int>(reticleVec.x), y + static_cast<int>(reticleVec.y));
315 reticle->Update();
316 }
317 else
318 reticleVec.z = 0.0f;
319
321 bankAngle->Update();
322
323 if (playerships[0].reference != REF_ONGROUND)
325 else
327 slipSkid->Update();
328
329 // The length of a dot is 1 time unit. A dash is 3 time units. The space between symbols(dots and dashes) of the same letter is 1 time unit.
330 // 111011101110 // 2 seconds
331 // 111010111010
332 // 101010101010
333 // 111111111111
334 // test mode
335 //bus->MarkerBeacon = Bus::MarkerBeaconTypes::Inner;
336 markerBeaconTime += fElapsed;
337 if (markerBeaconTime >= 0.125f) // 8 every 2 seconds or 4 every 1 second ... or 1 every .25 seconds
338 {
339 markerBeaconTime = 0.0f;
341 if (markerBeaconBits >= 4096)
343 }
344 switch (bus->MarkerBeacon)
345 {
347 markerBeacon->SetRectangle(0, 1, 21, 16);
349 markerBeaconColor = (markerBeaconBits & 0x00000EEE) ? 0x80FFFFFF : 0x80808080;
350 break;
352 markerBeacon->SetRectangle(0, 22, 42, 16);
354 markerBeaconColor = (markerBeaconBits & 0x00000EBA) ? 0x80FFFFFF : 0x80808080;
355 break;
357 markerBeacon->SetRectangle(0, 43, 64, 16);
359 markerBeaconColor = (markerBeaconBits & 0x00000AAA) ? 0x80FFFFFF : 0x80808080;
360 break;
361 default:
365 }
366}
#define V(expression)
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
@ REF_ONGROUND
Definition ServerTypes.h:43
void FrameMove(float fElapsed) override
Sprite * markerBeacon
Definition Instrument.h:554
Sprite * glideslopeBox
Definition Instrument.h:543
Sprite * failFlagLocalizer
Definition Instrument.h:541
AttitudeIndicator2(int prmX, int prmY, float prmXScale, float prmYScale, Bus *prmBus, Logger *prmLogger, DeviceObject *prmDevice, std::vector< Font * > prmFonts)
Sprite * localizerBug
Definition Instrument.h:546
Sprite * localizerBox
Definition Instrument.h:545
Sprite * glideslopeBug
Definition Instrument.h:544
RiseMath::Vector3 velocityVec
Definition Instrument.h:570
Sprite * failFlagGlideslope
Definition Instrument.h:542
Sprite * artificialHorizon
Definition Instrument.h:539
RiseMath::Vector3 reticleVec
Definition Instrument.h:569
Definition Bus.h:20
float RollAttitudeRadians
Definition Bus.h:48
float PressureAltitudeKm
Definition Bus.h:31
float PitchAttitudeRadians
Definition Bus.h:47
float LocalizerDeviationRadians
Definition Bus.h:158
struct Bus::Afcs AFCS
@ Inner
Definition Bus.h:167
@ Outer
Definition Bus.h:165
@ Middle
Definition Bus.h:166
float SlipSkidRadians
Definition Bus.h:387
void AddCommand(const Command &command, bool onlyOne)
Definition Bus.cpp:5
enum Bus::MarkerBeaconTypes MarkerBeacon
RiseMath::Vector2 FlightPathVectorDegrees
Definition Bus.h:452
float GlideslopeDeviationRadians
Definition Bus.h:159
float TargetBearingDeg
Definition Bus.h:503
Orbital::BusState orbit
Definition Bus.h:481
float AngleOfAttackRadians
Definition Bus.h:175
std::vector< Command > commandStream
Definition Bus.h:442
Rendering::RenderSprite * pSprite
HRESULT GetScissorRect(RECT *rect) const
HRESULT SetScissorRect(RECT *rect) const
Bus * bus
Definition Instrument.h:22
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
void AddToCallStack(const char *msg)
Definition Logger.cpp:355
void SetLocation(int absoluteX, int absoluteY)
Definition Sprite.cpp:99
float rotate
Definition Sprite.h:35
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
void SetRectangle(int top, int left, int right, int bottom)
Definition Sprite.cpp:105
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
float mark
Definition globals.cpp:45
Scockpit ourcockpit
Definition globals.cpp:114
auto ToRadian(T value)
Definition ClientMath.h:13
constexpr float Tau
Definition ClientMath.h:12
auto ToDegree(T value)
Definition ClientMath.h:14
constexpr float HalfPi
Definition ClientMath.h:12
float DesiredPitchRadians
Definition Bus.h:141
float DesiredRollRadians
Definition Bus.h:140
bool DorOn
Definition Bus.h:148
enum Bus::Afcs::LateralModes CurrentLateralMode
bool DorAircraft
Definition Bus.h:149
enum Bus::Afcs::VerticalModes CurrentVerticalMode
std::string name
Definition Command.h:11
float power
Definition globals.h:599