Avionics
Dropship Simulator
FlightModeAnnunciator.cpp
Go to the documentation of this file.
1 #include "../Instrument.h"
2 
3 FlightModeAnnunciator::FlightModeAnnunciator(int prmX, int prmY, float prmXScale, float prmYScale): Instrument(prmX, prmY, prmXScale, prmYScale)
4 {
5 }
6 
7 void FlightModeAnnunciator::Initialize(Bus* prmBus, Logger* prmLogger, DEVICE_OBJECT* prmDevice, int prmScreenWidth, int prmScreenHeight, std::vector<Font>* prmFonts, bool prmFlip)
8 {
9  Instrument::Initialize(prmBus, prmLogger, prmDevice, prmScreenWidth, prmScreenHeight, prmFonts, prmFlip);
10 
11  pixel.pathAndFilename = "Textures/Pixel.png";
12  pixel.Initialize(logger, bus, prmDevice, prmScreenHeight, 0, 0, prmFlip);
13  pixel.z = 0.6f; // needs to be below the text level
14 }
15 
16 void FlightModeAnnunciator::Render(float fElapsed)
17 {
18  DWORD vsiTextColor = 0xFF00FF00;
19  DWORD vsiBackColor = 0xFF000000;
20  DWORD altTextColor = 0xFF00FF00;
21  DWORD altBackColor = 0xFF000000;
23  {
24  verticalModeTimer = 0.0f; // reset
26  }
27  verticalModeTimer += fElapsed;
28  if (verticalModeTimer <= 3.0f)
29  {
30  if (bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::VerticalSpeed)
31  {
32  vsiBackColor = 0xFF00FF00; // green
33  vsiTextColor = 0xFF000000; // black
34  }
35  if (bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::Altitude ||
36  bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::Pitch)
37  {
38  altBackColor = 0xFF00FF00; // green
39  altTextColor = 0xFF000000; // black
40  }
41  }
42 
43  DWORD hdgTextColor = 0xFF00FF00;
44  DWORD hdgBackColor = 0xFF000000;
46  {
47  lateralModeTimer = 0.0f; // reset
49  }
50  lateralModeTimer += fElapsed;
51  if (lateralModeTimer <= 3.0f)
52  {
53  if (bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Heading ||
54  bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Roll ||
55  bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Navigation)
56  {
57  hdgBackColor = 0xFF00FF00; // green
58  hdgTextColor = 0xFF000000; // black
59  }
60  }
61  DWORD apTextColor = 0xFF00FF00;
62  DWORD apBackColor = 0xFF000000;
64  {
65  autopilotModeTimer = 0.0f;
67  }
68  autopilotModeTimer += fElapsed;
70  if (autopilotModeTimer <= 3.0f)
71  {
73  {
74  apTextColor = 0xFF000000;
75  apBackColor = 0xFF00FF00;
76  }
77  else if (fmodf(autopilotModeTimer, 0.5f) < 0.25f)
78  apTextColor = 0xFFFFFFFF;
79  else
80  apTextColor = 0xFF000000;
81  }
82 
83  DrawTextW(L"→", 129 - 26, 33 + 9, DT_NOCLIP, 0xFF00FF00, 2, "Autopilot");
84 
85 
87  pixel.x = 129;
88  pixel.y = 34;
89  pixel.width = 82;
90  pixel.height = 27;
91  pixel.color = apBackColor;
92  pixel.Update();
93  pixel.Draw();
95  DrawTextW(L"AP", 129 + 27, 33, DT_NOCLIP, apTextColor, 1, "Autopilot");
97  DrawTextW(L"AT", 129 + 27, 63, DT_NOCLIP, apTextColor, 1, "Autothrottle");
98 
100  pixel.x = 504;
101  pixel.y = 34;
102  pixel.width = 82;
103  pixel.height = 27;
104  pixel.color = vsiBackColor;
105  pixel.Update();
106  pixel.Draw();
107 
108  WCHAR msg[99];
109 
110  if (bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::VerticalSpeed)
111  {
112  char arrow;
113  if (bus->AFCS.DesiredVsi > 0)
114  arrow = 24; // up arrow
115  else if (bus->AFCS.DesiredVsi < 0)
116  arrow = 25; // down arrow
117  else
118  arrow = 32; // space
119 
120  swprintf_s(msg, 99, L"%c%4.0f", arrow, bus->AFCS.DesiredVsi*60.0f*1000.0f); // meters per minute
121  DrawTextW(msg, 504 + 12, 63, DT_NOCLIP, D3DXCOLOR(0.0f, 1.0f, 1.0f, 1.0f), 1, "VerticalSpeedSelected");
122 
123  DrawTextW(L"VS", 504 + 27, 33, DT_NOCLIP, vsiTextColor, 1, "VerticalSpeedSelected");
124  }
125 
127  pixel.x = 6;
128  pixel.y = 34; // 63 for digital readout
129  pixel.width = 77;
130  pixel.height = 27;
131  pixel.color = 0xFF000000;
132  pixel.Update();
133  pixel.Draw();
134 
136  pixel.x = 370;
137  pixel.y = 34; // 63 for digital readout, 3 for standby vertical
138  pixel.width = 82;
139  pixel.height = 27;
140  pixel.color = altBackColor;
141  pixel.Update();
142  pixel.Draw();
143 
145  {
146  float wholealt = floorf(bus->AFCS.DesiredAltitude);
147  swprintf_s(msg, 99, L"%3.0f", wholealt);
148  DrawTextW(msg, 370 + 6, 63, DT_NOCLIP, D3DXCOLOR(0.0f, 1.0f, 1.0f, 1.0f), 1, "AltitudeSelected");
149 
150  float fractalt = (bus->AFCS.DesiredAltitude - wholealt)*1000.0f;
151  if (fractalt >= 1000.0f) fractalt = 0.0f;
152  swprintf_s(msg, 99, L"%03.0f", fractalt);
153  DrawTextW(msg, 370 + 46, 63 + 5, DT_NOCLIP, D3DXCOLOR(0.0f, 1.0f, 1.0f, 1.0f), 0, "AltitudeSelected");
154  }
155  if (bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::Altitude)
156  {
157  DrawTextW(L"ALT", 370 + 21, 33, DT_NOCLIP, altTextColor, 1, "AltitudeSelected");
158  }
159  else if (bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::Pitch)
160  {
161  DrawTextW(L"FPA", 370 + 21, 33, DT_NOCLIP, altTextColor, 1, "AltitudeSelected");
162  }
163  else if (bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::GlideSlope)
164  {
165  DrawTextW(L"APPR", 370 + 16, 33, DT_NOCLIP, altTextColor, 1, "AltitudeSelected");
166  }
167 
168  if (bus->AFCS.StandbyVerticalMode == Bus::Afcs::VerticalModes::Altitude)
169  {
170  DrawTextW(L"ALT", 370 + 21, 3, DT_NOCLIP, 0xFFFFFFFF, 1, "AltitudeSelected");
171  }
172  else if (bus->AFCS.StandbyVerticalMode == Bus::Afcs::VerticalModes::GlideSlope)
173  {
174  DrawTextW(L"G/S", 370 + 21, 3, DT_NOCLIP, 0xFFFFFFFF, 1, "AltitudeSelected");
175  }
176 
177 
179  pixel.x = 245;
180  pixel.y = 34; // 3 for standby lateral
181  pixel.width = 82;
182  pixel.height = 27;
183  pixel.color = hdgBackColor;
184  pixel.Update();
185  pixel.Draw();
186 
187  if (bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Heading)
188  {
189  swprintf_s(msg, 99, L"%03.0f", D3DXToDegree(bus->AFCS.DesiredHeading));
190  DrawTextW(msg, 245 + 21, 63, DT_NOCLIP, D3DXCOLOR(0.0f, 1.0f, 1.0f, 1.0f), 1, "HeadingSelected");
191 
192  DrawTextW(L"HDG", 245 + 21, 33, DT_NOCLIP, hdgTextColor, 1, "HeadingSelected");
193  }
194  else if (bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Roll)
195  {
196  swprintf_s(msg, 99, L"%+3.1f", D3DXToDegree(bus->AFCS.DesiredRoll));
197  DrawTextW(msg, 245 + 21, 63, DT_NOCLIP, D3DXCOLOR(0.0f, 1.0f, 1.0f, 1.0f), 1, "RollSelected");
198 
199  DrawTextW(L"ROLL", 245 + 16, 33, DT_NOCLIP, hdgTextColor, 1, "RollSelected");
200  }
201  else if (bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Navigation)
202  {
203  swprintf_s(msg, 99, L"%03.0f", D3DXToDegree(bus->AFCS.DesiredCourse));
204  DrawTextW(msg, 245 + 21, 63, DT_NOCLIP, D3DXCOLOR(0.0f, 1.0f, 1.0f, 1.0f), 1, "NavSelected");
205 
206  DrawTextW(L"LNAV", 245 + 16, 33, DT_NOCLIP, hdgTextColor, 1, "NavSelected");
207  }
208  else if (bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Localizer)
209  {
210  swprintf_s(msg, 99, L"%03.0f", D3DXToDegree(bus->AFCS.DesiredCourse));
211  DrawTextW(msg, 245 + 21, 63, DT_NOCLIP, D3DXCOLOR(0.0f, 1.0f, 1.0f, 1.0f), 1, "NavSelected");
212 
213  DrawTextW(L"APPR", 245 + 16, 33, DT_NOCLIP, hdgTextColor, 1, "NavSelected");
214  }
215 
216  if (bus->AFCS.StandbyLateralMode == Bus::Afcs::LateralModes::Localizer)
217  {
218  DrawTextW(L"LOC", 245 + 21, 3, DT_NOCLIP, 0xFFFFFFFF, 1, "NavSelected");
219  }
220 };
virtual void Initialize(Bus *prmBus, Logger *prmLogger, DEVICE_OBJECT *prmDevice, int prmScreenWidth, int prmScreenHeight, std::vector< Font > *prmFonts, bool prmFlip)
Definition: Instrument.h:45
Bus::Afcs::VerticalModes oldActiveVerticalMode
Definition: Instrument.h:168
void Initialize(Bus *prmBus, Logger *prmLogger, DEVICE_OBJECT *prmDevice, int prmScreenWidth, int prmScreenHeight, std::vector< Font > *prmFonts, bool prmFlip) override
Definition: Logger.h:5
int y
Definition: Sprite.h:16
enum Bus::Afcs::LateralModes CurrentLateralMode
void Update()
Definition: Sprite.h:50
float DesiredAltitude
Definition: Bus.h:124
float DesiredHeading
Definition: Bus.h:120
Bus::Afcs::LateralModes oldActiveLateralMode
Definition: Instrument.h:166
int x
Definition: Sprite.h:16
float z
Definition: Sprite.h:17
int height
Definition: Sprite.h:16
bool AutothrottleEngaged
Definition: Bus.h:81
Definition: Bus.h:12
void Render(float fElapsed) override
Bus * bus
Definition: Instrument.h:21
void Draw()
Definition: Sprite.h:64
float DesiredRoll
Definition: Bus.h:122
D3DXCOLOR color
Definition: Sprite.h:20
Abstract base class for instrumentation By definition, instruments don&#39;t do any of the work (they don...
Definition: Instrument.h:15
int width
Definition: Sprite.h:16
std::string pathAndFilename
Definition: Sprite.h:18
struct Bus::Afcs AFCS
enum Bus::Afcs::VerticalModes StandbyVerticalMode
Logger * logger
Definition: Instrument.h:22
float DesiredVsi
Definition: Bus.h:119
enum Bus::Afcs::VerticalModes CurrentVerticalMode
float DesiredCourse
Definition: Bus.h:121
bool AutopilotEngaged
Definition: Bus.h:80
FlightModeAnnunciator(int prmX, int prmY, float prmXScale, float prmYScale)
enum Bus::Afcs::LateralModes StandbyLateralMode
void Initialize(Logger *prmLogger, Bus *prmBus, DEVICE_OBJECT *prmpDevice, int prmScreenHeight, int prmElementX, int prmElementY, bool prmFlip)
Definition: Sprite.h:26