Avionics
Dropship Simulator
AltitudeTape.cpp
Go to the documentation of this file.
1 #include "../Instrument.h"
2 
3 AltitudeTape::AltitudeTape(int prmX, int prmY, int prmWidth, int prmHeight, std::string prmTextureFile, float prmModulateKm) : Instrument(prmX, prmY, 1, 1)
4 {
5  width = prmWidth;
6  height = prmHeight;
7  textureFile = prmTextureFile;
8  modulateKm = prmModulateKm;
9 }
10 
11 void AltitudeTape::Initialize(Bus* prmBus, Logger* prmLogger, DEVICE_OBJECT* prmDevice, int prmScreenWidth, int prmScreenHeight, std::vector<Font>* prmFonts, bool prmFlip)
12 {
13  Instrument::Initialize(prmBus, prmLogger, prmDevice, prmScreenWidth, prmScreenHeight, prmFonts, prmFlip);
14 
15  sprite.width = width;
18  sprite.Initialize(logger, bus, prmDevice, prmScreenHeight, x, y, prmFlip);
19  sprite.z = 0.9f; // the artificial horizon is at 1.0, text is at 0.5, overlay is at 0.6
20  sprite.texSize.y = 0.5f;
21 
23  tvpitchscale = 0.5f * modulateKm; // 10 px per 20 knot
24  vertoffset = -4.0f / static_cast<float>(sprite.desc.Height) + 0.25f;
25 
26 }
27 
28 void AltitudeTape::Render(float fElapsed)
29 {
30  alt += (bus->PressureAltitude - alt)*0.25f;
31 
32  // 0.5 to 0.25 to 0.75
33  float temp = fmodf(-alt * tvpitchscale, 0.5f) + vertoffset;
34  if (temp < 0.0f) temp += 0.5f;
35  if (temp > 0.5f) temp -= 0.5f;
36  sprite.texCoord.y = temp;
37  sprite.Update();
38  sprite.Draw();
39 
43 
44  WCHAR msg[99];
45  float wholealt = floorf(alt*modulateKm);
46  swprintf_s(msg, 99, L"%3.0f", wholealt);
47  DrawTextW(msg, x + 15, y + 150, DT_NOCLIP, D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f), 1, "AltitudeReadout?");
48 
49  float fractalt = (alt*modulateKm - wholealt)*1000.0f;
50  swprintf_s(msg, 99, L"%03.0f", floorf(fractalt));
51  DrawTextW(msg, x + 55, y + 155, DT_NOCLIP, D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f), 0, "AltitudeReadout?");
52 };
virtual void Initialize(Bus *prmBus, Logger *prmLogger, DEVICE_OBJECT *prmDevice, int prmScreenWidth, int prmScreenHeight, std::vector< Font > *prmFonts, bool prmFlip)
Definition: Instrument.h:45
std::string textureFile
Definition: Instrument.h:134
AltitudeTape(int prmX, int prmY, int prmWidth, int prmHeight, std::string prmTextureFile, float prmModulateKm)
Definition: AltitudeTape.cpp:3
float PressureAltitude
Definition: Bus.h:40
Sprite sprite
Definition: Instrument.h:133
float modulateKm
Definition: Instrument.h:139
Definition: Logger.h:5
int height
Definition: Instrument.h:30
D3DXVECTOR2 texSize
Definition: Sprite.h:24
void Update()
Definition: Sprite.h:50
D3D10_TEXTURE2D_DESC desc
Definition: Sprite.h:15
float z
Definition: Sprite.h:17
D3DXVECTOR2 texCoord
Definition: Sprite.h:23
int height
Definition: Sprite.h:16
Definition: Bus.h:12
float tvpitchscale
Definition: Instrument.h:135
Bus * bus
Definition: Instrument.h:21
void Draw()
Definition: Sprite.h:64
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
float vertoffset
Definition: Instrument.h:136
std::string pathAndFilename
Definition: Sprite.h:18
Logger * logger
Definition: Instrument.h:22
void Initialize(Bus *prmBus, Logger *prmLogger, DEVICE_OBJECT *prmDevice, int prmScreenWidth, int prmScreenHeight, std::vector< Font > *prmFonts, bool prmFlip) override
void Render(float fElapsed) override
void Initialize(Logger *prmLogger, Bus *prmBus, DEVICE_OBJECT *prmpDevice, int prmScreenHeight, int prmElementX, int prmElementY, bool prmFlip)
Definition: Sprite.h:26