Avionics
Dropship Simulator
MovingMap.cpp
Go to the documentation of this file.
1 #include "Instrument.h"
2 
3 MovingMap::MovingMap(int prmX, int prmY, float prmXScale, float prmYScale): Instrument(prmX, prmY, prmXScale, prmYScale)
4 {
5 }
6 
7 void MovingMap::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  compass.width = 530;
12  compass.height = 530;
13  compass.pathAndFilename = "Textures/Instruments/MFD Compass.png";
14  compass.Initialize(logger, bus, prmDevice, prmScreenHeight, x, y, prmFlip);
15  compass.x = 0;
16  compass.y = 0;
17  compass.z = 0.9f; // the artificial horizon is at 1.0, text is at 0.5, overlay is at 0.6
18 
19  waypointSprite.width = 28;
21  waypointSprite.pathAndFilename = "Textures/Instruments/Waypoint.png";
22  waypointSprite.elementName = "FlightRoute";
23  waypointSprite.Initialize(logger, bus, prmDevice, prmScreenHeight, x, y, prmFlip);
24  waypointSprite.z = 0.8f;
25 
26  course.width = 1;
27  //course.height
28  course.pathAndFilename = "Textures/Pixel.png";
29  course.elementName = "FlightRoute";
30  course.Initialize(logger, bus, prmDevice, prmScreenHeight, x, y, prmFlip);
31  course.z = 0.8f;
32 }
33 
34 void MovingMap::Render(float fElapsed)
35 {
37  if ((bus->HeadingTrue - compass.rotate) > D3DX_PI)
38  compass.rotate += D3DX_PI*2.0f;
39  else if ((bus->HeadingTrue - compass.rotate) <-D3DX_PI)
40  compass.rotate -= D3DX_PI*2.0f;
41 
42  compass.Update();
43  compass.Draw();
44 
45  WCHAR msg[99];
46  int hdgDegree = static_cast<int>(D3DXToDegree(compass.rotate));
47  if (hdgDegree > 360) hdgDegree -= 360;
48  if (hdgDegree < 0) hdgDegree += 360;
49  swprintf_s(msg, 99, L"%03i", hdgDegree);
50  DrawTextW(msg, 280, 64, DT_NOCLIP, D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f), 1, "HeadingReadout");
51 
52  float scale = 60.0f;
53  float pixelPerKm = 265.0f / scale;
54  D3DXMATRIX matRot;
55  D3DXMatrixRotationZ(&matRot, -compass.rotate);
56 
57  D3DXVECTOR2 lastWaypoint, nextWaypoint;
58  lastWaypoint.x = 265;
59  lastWaypoint.y = 265;
60  for (UINT i = 0; i < bus->waypoints.size(); i++)
61  {
62  Waypoint waypoint = bus->waypoints.at(i);
63  D3DXVECTOR3 diff = bus->Location - waypoint.absoluteLocation();
64  D3DXVECTOR2 diff2d = D3DXVECTOR2(-diff.x * pixelPerKm, -diff.y * pixelPerKm);
65  D3DXVec2TransformCoord(&diff2d, &diff2d, &matRot);
66 
67  nextWaypoint = D3DXVECTOR2(265,265) + diff2d;
68  waypointSprite.x = static_cast<int>(nextWaypoint.x) - 14; // offert from middle to top left of 28x28 sprite
69  waypointSprite.y = static_cast<int>(nextWaypoint.y) - 14; // offert from middle to top left of 28x28 sprite
70  if (i == 0)
71  waypointSprite.color = 0xFFFF00FF; // first one only
72  else
73  waypointSprite.color = 0xFFFFFFFF;
74  switch (waypoint.type)
75  {
76  case Waypoint::WaypointType::FlyoverFix:
77  waypointSprite.texCoord = D3DXVECTOR2(0, 0);
78  waypointSprite.texSize = D3DXVECTOR2(1.0, 1.0f / 3.0f);
79  waypointSprite.rotate = 0.0f;
80  break;
81  case Waypoint::WaypointType::FinalApproachFix:
82  waypointSprite.texCoord = D3DXVECTOR2(0, 1.0f / 3.0f);
83  waypointSprite.texSize = D3DXVECTOR2(1.0, 1.0f / 3.0f);
84  waypointSprite.rotate = 0.0f;
85  break;
86  case Waypoint::WaypointType::TouchdownZone:
87  waypointSprite.texCoord = D3DXVECTOR2(0, 2.0f / 3.0f);
88  waypointSprite.texSize = D3DXVECTOR2(1.0, 1.0f / 3.0f);
89  waypointSprite.rotate = compass.rotate-D3DXToRadian(90.0f) ;
90  break;
91  }
94 
95  swprintf_s(msg, 99, L"%S", waypoint.FixId.c_str());
96  DrawTextW(msg, x + waypointSprite.x + 32, y + waypointSprite.y + 3, DT_NOCLIP, waypointSprite.color, 0, "FlightRoute");
97 
98 
99  course.height = static_cast<int>(sqrtf(powf(nextWaypoint.x - lastWaypoint.x, 2.0f) + powf(nextWaypoint.y - lastWaypoint.y, 2.0f)));
100  course.x = static_cast<int>((nextWaypoint.x + lastWaypoint.x)*0.5f);
101  course.y = static_cast<int>(min(nextWaypoint.y, lastWaypoint.y) - (course.height - fabsf(nextWaypoint.y - lastWaypoint.y))*0.5f);
102  if (i == 0)
103  course.color = 0xFFFF00FF; // first one only
104  else
105  course.color = 0xFFFFFFFF;
106 
107  course.rotate = -atan2f(lastWaypoint.y - nextWaypoint.y, lastWaypoint.x - nextWaypoint.x) + D3DX_PI*0.5f;
108  course.Update();
109  course.Draw();
110 
111  lastWaypoint = nextWaypoint;
112  }
113 
114 };
D3DXVECTOR3 absoluteLocation() const
Definition: Waypoint.h:23
virtual void Initialize(Bus *prmBus, Logger *prmLogger, DEVICE_OBJECT *prmDevice, int prmScreenWidth, int prmScreenHeight, std::vector< Font > *prmFonts, bool prmFlip)
Definition: Instrument.h:45
Definition: Logger.h:5
int y
Definition: Sprite.h:16
D3DXVECTOR2 texSize
Definition: Sprite.h:24
std::vector< Waypoint > waypoints
Definition: Bus.h:367
void Update()
Definition: Sprite.h:50
WaypointType type
Definition: Waypoint.h:21
Sprite waypointSprite
Definition: Instrument.h:258
float rotate
Definition: Sprite.h:21
int x
Definition: Sprite.h:16
float z
Definition: Sprite.h:17
D3DXVECTOR2 texCoord
Definition: Sprite.h:23
float HeadingTrue
(4) Heading–primary flight crew reference (if selectable, record discrete, true or magnetic); ...
Definition: Bus.h:44
int height
Definition: Sprite.h:16
Sprite compass
Definition: Instrument.h:257
Definition: Bus.h:12
Bus * bus
Definition: Instrument.h:21
Sprite course
Definition: Instrument.h:259
void Draw()
Definition: Sprite.h:64
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 elementName
Definition: Sprite.h:19
std::string pathAndFilename
Definition: Sprite.h:18
void Render(float fElapsed) override
Definition: MovingMap.cpp:34
Logger * logger
Definition: Instrument.h:22
std::string FixId
Definition: Waypoint.h:20
void Initialize(Bus *prmBus, Logger *prmLogger, DEVICE_OBJECT *prmDevice, int prmScreenWidth, int prmScreenHeight, std::vector< Font > *prmFonts, bool prmFlip) override
Definition: MovingMap.cpp:7
MovingMap(int prmX, int prmY, float prmXScale, float prmYScale)
Definition: MovingMap.cpp:3
void Initialize(Logger *prmLogger, Bus *prmBus, DEVICE_OBJECT *prmpDevice, int prmScreenHeight, int prmElementX, int prmElementY, bool prmFlip)
Definition: Sprite.h:26
D3DXVECTOR3 Location
Definition: Bus.h:359