Rise
The Vieneo Province
Loading...
Searching...
No Matches
AttitudeIndicator.cpp
Go to the documentation of this file.
1#include "../Instrument.h"
3
4AttitudeIndicator::AttitudeIndicator(int prmX, int prmY, float prmXScale, float prmYScale, Bus* prmBus, Logger* prmLogger, DeviceObject* prmDevice, std::vector<Font*> prmFonts) :
5 Instrument(prmX, prmY, prmXScale, prmYScale, prmBus, prmLogger, prmDevice, prmFonts)
6{
7 logger->AddToCallStack("AttitudeIndicator::ctor");
8
9 // so 1:1 scale is 83x89
10 // to make sure we don't show blackness we need to expand based on hypotenuse
11
12 // old design which showed 45 degrees so that is 1/4 of the height
13 float tvrange = 89.0f * prmYScale; // displayed height
14 tvpitchscale = tvrange / RiseMath::ToRadian(45.0f); // 2 px per degree converted to radian
15 tvvertoffset = 480.0f * 0.5f + 1.0f; // halfway down on the sprite
16 const float hypotenuse = sqrtf(powf(83.0f * prmXScale, 2.0f) + powf(tvrange, 2.0f));
17 xMargins = static_cast<int>((hypotenuse - 83.0f * prmXScale) * 0.5f);
18 yMargins = static_cast<int>((hypotenuse - tvrange) * 0.5f);
19 tvrange += yMargins * 2.0f;
20 halftvrange = tvrange * 0.5f;
21
22 scissor_rect.left = x;
23 scissor_rect.top = y;
24 scissor_rect.right = x + static_cast<long>(83.0f * xScale);
25 scissor_rect.bottom = y + static_cast<long>(89.0f * yScale);
26
27 artificialHorizon = new Sprite(logger, pDevice, "Textures/Instruments/FlatHorizon.png", prmX - xMargins, prmY - yMargins, 0.1f, 0, 0, 150, 480, 0xFFFFFFFF, prmXScale, prmYScale);
28 artificialHorizon->SetRotationCenter(RiseMath::Vector2(83.0f * 0.5f * xScale + xMargins, 89.0f * 0.5f * yScale + yMargins));
29 // 83x89 vs ="348" height="344
30 commandBars = new Sprite(logger, pDevice, "Textures/Instruments/command bars.png", prmX, prmY, 0.9f, 0, 0, 219, 70, 0xFFFFFFFF, prmXScale * 0.24f, prmYScale * 0.26f);
31 failFlagLocalizer = new Sprite(logger, pDevice, "Textures/Instruments/yellow_x.png", prmX + 27, prmY + 81, 0.5f, 0, 0, 38, 55, 0xFFFFFFFF, prmXScale * 0.78f, prmYScale * 0.09f);
32 failFlagGlideslope = new Sprite(logger, pDevice, "Textures/Instruments/yellow_x.png", prmX + 70, prmY + 30, 0.5f, 0, 0, 38, 55, 0xFFFFFFFF, prmXScale * 0.13f, prmYScale * 0.56f);
33 // Match the texture bounds; sampling past them stretches the white border.
34 glideslopeBox = new Sprite(logger, pDevice, "Textures/Instruments/glideslope.png", prmX + 70, prmY + 31, 0.4f, 0, 0, 19, 120, 0xFFFFFFFF, prmXScale * 0.24f, prmYScale * 0.26f);
35 glideslopeBug = new Sprite(logger, pDevice, "Textures/Instruments/glideslope-bug.png", prmX + 70, prmY + 38, 0.5f, 0, 0, 18, 18, 0xFFFFFFFF, prmXScale * 0.24f, prmYScale * 0.26f);
36 localizerBox = new Sprite(logger, pDevice, "Textures/Instruments/localizer.png", prmX + 27, prmY + 81, 0.4f, 0, 0, 120, 19, 0xFFFFFFFF, prmXScale * 0.24f, prmYScale * 0.26f);
37 localizerBug = new Sprite(logger, pDevice, "Textures/Instruments/glideslope-bug.png", prmX + 76, prmY + 38, 0.5f, 0, 0, 18, 18, 0xFFFFFFFF, prmXScale * 0.24f, prmYScale * 0.26f);
38 aoaHigh = new Sprite(logger, pDevice, "Textures/Instruments/aoahigh.dds", prmX + 25, prmY - 7, 0.5f, 0, 0, 32, 32, 0xFFFFFFFF);
39 aoa = new Sprite(logger, pDevice, "Textures/Instruments/aoa.dds", prmX, prmY, 0.5f, 0, 0, 32, 32, 0xFFFFFFFF);
40 aoaLow = new Sprite(logger, pDevice, "Textures/Instruments/aoalow.dds", prmX + 25, prmY + 64, 0.5f, 0, 0, 32, 32, 0xFFFFFFFF);
41 reticle = new Sprite(logger, pDevice, "Textures/Instruments/reticle.png", prmX, prmY, 0.5f, 0, 0, 32, 32, 0xFFFFFFFF);
42 vector = new Sprite(logger, pDevice, "Textures/Instruments/vector.png", prmX, prmY, 0.5f, 0, 0, 32, 32, 0xFFFFFFFF);
43
44 cbpitchscale = 2.1f / RiseMath::ToRadian(1); // 67 pixels for 10 degrees converted to radian
45 cbvertoffset = y + 36.0f;
46}
47
49{
50 HRESULT hr;
51
52 RECT oldScissorRect;
53 V(pDevice->GetScissorRect(&oldScissorRect));
54
55 try
56 {
58 }
59 catch (...) // this is because if there is nothing in the buffer drawn this will throw an unhandled exception!
60 {
61 }
62
64
65 // artificial horizon is at 1.0
67
68 // then command bars at 0.9
71
72 // tests
73 //bus->AFCS.CurrentLateralMode = Bus::Afcs::LateralModes::Localizer;
74 //static float boo = 0.0f;
75 //boo += 0.01f;
76 //bus->LocalizerDeviationRadians = RiseMath::ToRadian(sinf(boo)*2.6f); // want it from 2.5 degrees to -2.5 degrees
77
79 {
81
84 else
86 }
87
88 // tests
89 //bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::Glideslope;
90 //static float boo = 0.0f;
91 //boo += 0.01f;
92 //bus->GlideslopeDeviationRadians = RiseMath::ToRadian(sinf(boo)*0.8f); // want it from 0.8 degrees to -0.8 degrees
93
95 {
97
100 else
102 }
103
104
105 // aoa bugs
106 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
107 switch (lastAOA)
108 {
109 case 0: aoaHigh->Draw(); break;
110 case 1: aoa->Draw(); break;
111 case 2: aoaLow->Draw(); break;
112 }
113
114
116 DrawText(L"AF", 1, 0, 0.9f, DT_NOCLIP, 0xFF00FF00, 1, "AF");
117
118
119 if (velocityVec.z == 1.0f)
120 vector->Draw(0xFF00FF00); // green
121 else if (velocityVec.z < 0.0f)
122 vector->Draw(0xFFFF0000); // red
123
124
125 if (reticleVec.z == 1.0f)
126 reticle->Draw(0xFF00FF00); // green
127 else if (reticleVec.z < 0.0f)
128 reticle->Draw(0xFFFF0000); // red
129
130
131 V(pDevice->pSprite->Flush());
132
133 V(pDevice->SetScissorRect(&oldScissorRect));
134}
135
137{
142 roll += (bus->RollAttitudeRadians - roll) * fElapsed;
143 pitch += (bus->PitchAttitudeRadians - pitch) * fElapsed;
145
146 artificialHorizon->SetRectangle(static_cast<int>(tvvertoffset - halftvrange - tvpitch), 34 - xMargins, 117 + xMargins, static_cast<int>(tvvertoffset + halftvrange - tvpitch));
149
151 {
152 const bool orbital = bus->AFCS.DorOn && !bus->AFCS.DorAircraft && bus->orbit.guidance.attitude;
153 commandBars->rotate = orbital ? 0.0f : -bus->AFCS.DesiredRollRadians + roll;
155 commandBars->rotate *= 2.0f;
156
157 float pitchDev = (orbital ? float(bus->orbit.guidance.pitch) : bus->AFCS.DesiredPitchRadians) - pitch;
159 pitchDev *= 2.0f;
160 if (pitchDev > RiseMath::ToRadian(20.0f)) pitchDev = RiseMath::ToRadian(20.0f);
161 if (pitchDev < RiseMath::ToRadian(-20.0f)) pitchDev = RiseMath::ToRadian(-20.0f);
162
163 commandBars->SetLocation(x + 15, static_cast<int>(cbvertoffset - pitchDev * cbpitchscale));
165 }
166
167 //bus->AFCS.CurrentLateralMode = Bus::Afcs::LateralModes::Localizer;
168 //bus->LocalizerDeviationRadians = RiseMath::ToRadian(cosf(Rendering::ClientTime()) * 5.0f);
170 if (fabsf(deg) <= 2.5f)
171 {
172 localizerBug->SetLocation(x + 27 + static_cast<int>(26.0f * (deg + 2.5f) / 5.0f), y + 81);
174 if (!localizerAlive)
175 {
176 localizerAlive = true;
177 Command command;
178 command.name = "AuralLocalizerAlive";
179 bus->commandStream.emplace_back(command);
180 }
181 }
182 else
183 {
184 localizerAlive = false;
185 }
186
187 //bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::Glideslope;
188 //bus->GlideslopeDeviationRadians = RiseMath::ToRadian(sinf(Rendering::ClientTime()) * 1.4f);
190 if (fabsf(deg) <= 0.7f)
191 {
192 glideslopeBug->SetLocation(x + 70, y + 30 + static_cast<int>(28.0f * (deg + 0.7f) / 1.4f));
195 {
196 glideslopeAlive = true;
197 Command command;
198 command.name = "AuralGlideslopeAlive";
199 bus->commandStream.emplace_back(command);
200 }
201 }
202 else
203 {
204 glideslopeAlive = false;
205 }
206
207 // aoa bugs
208 const short offsety = static_cast<short>(RiseMath::ToDegree(-bus->AngleOfAttackRadians) * 2.0f) + 38; // 2 pixels per degree
209 char thisAOA;
210 if (offsety < 0)
211 thisAOA = 0;
212 else if (offsety > 71)
213 thisAOA = 2;
214 else
215 {
216 thisAOA = 1;
217 aoa->SetLocation(x + 25, y - 7 + offsety);
218 aoa->Update();
219 }
220 if (((lastAOA == 2 && thisAOA == 0) || (lastAOA == 0 && thisAOA == 2)) &&
221 playerships[0].reference != REF_ONGROUND && bus->IndicatedAirspeedKms > 0.02f &&
222 ourcockpit.power > 0.5f)
223 {
224 Command command;
225 command.name = "AuralAOA";
226 bus->AddCommand(command, true);
227 }
228 lastAOA = thisAOA;
229
230
231 // Velocity vector
232 if (bus->FlightPathVectorDegrees.x != 999.0f && bus->FlightPathVectorDegrees.y != 999.0f)
233 {
234 // Adjust for center of ADI
235 if (fabsf(bus->FlightPathVectorDegrees.x) > 90.0f)
236 {
237 velocityVec.z = -1.0f;
238 if (bus->FlightPathVectorDegrees.x > 90.0f)
239 velocityVec.x = 66.0f - ((bus->FlightPathVectorDegrees.x - 180.0f) / 31.289076f) * 41.5f;
240 else
241 velocityVec.x = 66.0f - ((bus->FlightPathVectorDegrees.x + 180.0f) / 31.289076f) * 41.5f;
242 }
243 else
244 {
245 velocityVec.z = 1.0f;
246 velocityVec.x = 66.0f + (bus->FlightPathVectorDegrees.x / 31.289076f) * 41.5f;
247 }
248 velocityVec.y = 69.0f - (bus->FlightPathVectorDegrees.y / 31.289076f) * 44.0f;
249 if (velocityVec.x < 24.0f)
250 velocityVec.x = 24.0f;
251 else if (velocityVec.x > 107.0f)
252 velocityVec.x = 107.0f;
253 if (velocityVec.y < 24.0f)
254 velocityVec.y = 24.0f;
255 else if (velocityVec.y > 113.0f)
256 velocityVec.y = 113.0f;
257 // Adjust for upper left of sprite
258 velocityVec.x -= 16.0f;
259 velocityVec.y -= 16.0f;
260 vector->SetLocation(static_cast<int>(velocityVec.x), static_cast<int>(velocityVec.y));
261 vector->Update();
262 }
263 else
264 velocityVec.z = 0.0f;
265
266
267 // Bearing/mark reticle
268 if (bus->TargetBearingDeg != 999.0f && mark != 999.0f)
269 {
270 // Adjust for center of ADI
271 if (fabsf(bus->TargetBearingDeg) > 90.0f)
272 {
273 reticleVec.z = -1.0f;
274 if (bus->TargetBearingDeg > 90.0f)
275 reticleVec.x = 41.5f - ((bus->TargetBearingDeg - 180.0f) / 31.289076f) * 41.5f;
276 else
277 reticleVec.x = 41.5f - ((bus->TargetBearingDeg + 180.0f) / 31.289076f) * 41.5f;
278 reticleVec.y = 44.0f - (mark / 31.289076f) * 44.0f;
279 }
280 else
281 {
282 reticleVec.z = 1.0f;
283 reticleVec.x = 41.5f + (bus->TargetBearingDeg / 31.289076f) * 41.5f;
284 reticleVec.y = 44.0f + (-mark / 31.289076f) * 44.0f;
285 }
286 if (reticleVec.x < 0.0f)
287 reticleVec.x = 0.0f;
288 else if (reticleVec.x > 83.0f)
289 reticleVec.x = 83.0f;
290 if (reticleVec.y < 0.0f)
291 reticleVec.y = 0.0f;
292 else if (reticleVec.y > 89.0f)
293 reticleVec.y = 89.0f;
294 // Adjust for upper left of sprite
295 reticleVec.x -= 16.0f;
296 reticleVec.y -= 16.0f;
297 reticle->SetLocation(x + static_cast<int>(reticleVec.x), y + static_cast<int>(reticleVec.y));
298 reticle->Update();
299 }
300 else
301 reticleVec.z = 0.0f;
302}
#define V(expression)
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
@ REF_ONGROUND
Definition ServerTypes.h:43
Sprite * localizerBox
Definition Instrument.h:506
AttitudeIndicator(int prmX, int prmY, float prmXScale, float prmYScale, Bus *prmBus, Logger *prmLogger, DeviceObject *prmDevice, std::vector< Font * > prmFonts)
Sprite * glideslopeBox
Definition Instrument.h:504
RiseMath::Vector3 velocityVec
Definition Instrument.h:527
void FrameMove(float fElapsed) override
Sprite * localizerBug
Definition Instrument.h:507
Sprite * failFlagGlideslope
Definition Instrument.h:503
void Render() override
Sprite * glideslopeBug
Definition Instrument.h:505
Sprite * commandBars
Definition Instrument.h:501
RiseMath::Vector3 reticleVec
Definition Instrument.h:526
Sprite * artificialHorizon
Definition Instrument.h:500
Sprite * failFlagLocalizer
Definition Instrument.h:502
Definition Bus.h:20
float RollAttitudeRadians
Definition Bus.h:48
float PitchAttitudeRadians
Definition Bus.h:47
float LocalizerDeviationRadians
Definition Bus.h:158
float IndicatedAirspeedKms
Definition Bus.h:34
struct Bus::Afcs AFCS
void AddCommand(const Command &command, bool onlyOne)
Definition Bus.cpp:5
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
float xScale
Definition Instrument.h:19
void DrawText(const WCHAR *str, int relativeX, int relativeY, float prmZ, int flags, RiseMath::Color color, int font=-1, std::string elementName="", int width=0, int height=0) const
Definition Instrument.h:49
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
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
@ Localizer
Definition Bus.h:116
@ Glideslope
Definition Bus.h:104
bool DorOn
Definition Bus.h:148
enum Bus::Afcs::LateralModes CurrentLateralMode
bool AutopilotEngaged
Definition Bus.h:87
bool DorAircraft
Definition Bus.h:149
enum Bus::Afcs::VerticalModes CurrentVerticalMode
std::string name
Definition Command.h:11
float power
Definition globals.h:599