Rise
The Vieneo Province
TCASOverlay.cpp
Go to the documentation of this file.
1 #include "../Instrument.h"
2 
3 TCASOverlay::TCASOverlay(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("TCAS::ctor");
7  defaultFont = 1;
8 
9  noThreat = new Sprite(logger, pDevice, "Textures/Instruments/TCAS.png", x, y, 0.3f, 0, 0, 28, 28, 0xFFFFFFFF, xScale, yScale);
10  proximate = new Sprite(logger, pDevice, "Textures/Instruments/TCAS.png", x, y, 0.3f, 28, 0, 28, 28, 0xFFFFFFFF, xScale, yScale);
11  potentialThreat = new Sprite(logger, pDevice, "Textures/Instruments/TCAS.png", x, y, 0.3f, 56, 0, 28, 28, 0xFFFFFFFF, xScale, yScale);
12  collisionThreat = new Sprite(logger, pDevice, "Textures/Instruments/TCAS.png", x, y, 0.3f, 84, 0, 28, 28, 0xFFFFFFFF, xScale, yScale);
13 
14  // offset from middle to top left of 28x28 sprite
15  iconOffsetX = 14 * xScale;
16  iconOffsetY = 14 * yScale;
17 
18  relativeCenter = D3DXVECTOR2(530.0f * 0.5f * xScale, 530.0f * 0.5f * yScale);
19 }
20 
22 {
23  for (UINT i = 0; i < targets.size(); i++)
24  {
25  const s_network_objects target = targets.at(i);
26 
27  DWORD color = 0xFF0088FF;
28  if (target.ordinal == bus->TCASTargetOrdinal)
29  {
30  if (bus->TCAS == Bus::TcasEnum::Traffic_Advisory)
31  color = 0xFFFFAA00;
32  else if (bus->TCAS >= Bus::TcasEnum::RA_Climb)
33  color = 0xFFFF0000;
34  }
35 
36  if (color==0xFFFFAA00)
37  {
38  potentialThreat->SetLocation(static_cast<int>(target.acc.x), static_cast<int>(target.acc.y));
40  potentialThreat->Draw(color);
41  }
42  else if (color == 0xFFFF0000)
43  {
44  collisionThreat->SetLocation(static_cast<int>(target.acc.x), static_cast<int>(target.acc.y));
46  collisionThreat->Draw(color);
47  }
48  else
49  {
50  // check altitude for proximate (within 1200 feet, 0.36576 km)
51  if (fabsf(target.acc.z) <= 0.36576f)
52  {
53  proximate->SetLocation(static_cast<int>(target.acc.x), static_cast<int>(target.acc.y));
54  proximate->Update();
55  proximate->Draw(color);
56  }
57  else
58  {
59  noThreat->SetLocation(static_cast<int>(target.acc.x), static_cast<int>(target.acc.y));
60  noThreat->Update();
61  noThreat->Draw(color);
62  }
63  }
64 
65  if (target.acc.z > 0)
66  DrawTextW(target.tcasOnly, static_cast<int>(target.acc.x) - x, static_cast<int>(target.acc.y) - y - 10, 0.4f, DT_NOCLIP, color);
67  else
68  DrawTextW(target.tcasOnly, static_cast<int>(target.acc.x) - x, static_cast<int>(target.acc.y) - y + 10, 0.4f, DT_NOCLIP, color);
69  }
70 }
71 
72 void TCASOverlay::FrameMove(float fElapsed)
73 {
74  headingTrueRad = D3DXToRadian(bus->HeadingTrueDegrees);
75 
76  // so 6.28 - 0 is a 6.28 or -6.28 difference!
77  float diff = headingTrueRad - rotate;
78  if (diff > D3DX_PI)
79  diff -= D3DX_TAU;
80  else if (diff < -D3DX_PI)
81  diff += D3DX_TAU;
82 
83  rotate += diff * fElapsed;
84 
85  /*diff = rotate - bus->AFCS.DesiredHeadingRadians;
86  if (diff > D3DX_PI)
87  diff -= D3DX_TAU;
88  else if (diff < -D3DX_PI)
89  diff += D3DX_TAU;*/
90 
91  pixelPerKmX = 530.0f * 0.25f / bus->MapScaleInnerRingKm * xScale;
92  pixelPerKmY = 530.0f * 0.25f / bus->MapScaleInnerRingKm * yScale;
93 
94  D3DXVECTOR3 posnorml;
95  D3DXVec3Normalize(&posnorml, &playerships[0].position);
96  D3DXMATRIX lookAtLH;
97  D3DXMatrixLookAtLH(&lookAtLH, &playerships[0].position, &northpoleC, &posnorml);
98  D3DXMATRIX matrixRot;
99  D3DXMatrixRotationZ(&matrixRot, rotate);
100  lookAtLH = lookAtLH * matrixRot;
101 
102  targets.clear();
103  for (UINT ii = 1; ii < MAX_SCAN; ii++)
104  {
105  s_network_objects target = playerships[ii];
106 
107  if (!target.active || !target.visible)
108  continue;
109 
110  if (!target.logolight ||
111  //target.docked || // we want to show them but not alert on them
112  target.groundvehicle ||
113  //target.reference == REF_ONGROUND || // we want to show them but not alert on them
114  target.reference == REF_INANOTHER ||
115  target.distance >= 75.0f || // ourcockpit.scanrange || // CRJ-200 was limited to 75 km / 40 nm
116  target.type == VehicleType::FloatingMan ||
117  target.type == VehicleType::BeishtKione)
118  //target.closurerate <= 0.0f) // we want to show them but not alert on them
119  continue;
120 
121  D3DXVECTOR3 result1;
122  D3DXVec3TransformCoord(&result1, &target.position, &lookAtLH);
123  // if they are more than 10,000 feet difference then we skip
124  if (fabsf(result1.z) >= 3.0f)
125  continue;
126 
127  // if distance is beyond 2x scale then skip
128  D3DXVECTOR2 result2 = D3DXVECTOR2(result1.x, result1.y);
129  const float dist = D3DXVec2Length(&result2);
130  if (dist > bus->MapScaleInnerRingKm * 2.0f)
131  continue;
132 
133  const D3DXVECTOR2 diff2d = D3DXVECTOR2(-result2.x * pixelPerKmX, result2.y * pixelPerKmY);
134  D3DXVECTOR2 nextWaypoint = relativeCenter + diff2d;
135  nextWaypoint.x = static_cast<int>(nextWaypoint.x) - iconOffsetX;
136  nextWaypoint.y = static_cast<int>(nextWaypoint.y) - iconOffsetY;
137  target.acc.x = nextWaypoint.x + x;
138  target.acc.y = nextWaypoint.y + y;
139  target.acc.z = -result1.z; // relative altitude!
140  if (fabsf(target.acc.z) < 0.05f)
141  target.acc.z = 0.0f;
142  swprintf_s(target.tcasOnly, 16, L"%02.0f", fabsf(target.acc.z) * 10.0f); // .5 km becomes 05, 3.0 becomes 30
143  if (target.vsi > 0.001f)
144  wcscat_s(target.tcasOnly, 16, L"\u2191"); // up arrow
145  else if (target.vsi < -0.001f)
146  wcscat_s(target.tcasOnly, 16, L"\u2193"); // down arrow
147 
148  target.ordinal = ii;
149 
150  targets.emplace_back(target);
151  }
152 }
void FrameMove(float fElapsed) override
Definition: TCASOverlay.cpp:72
void SetLocation(int absoluteX, int absoluteY)
Definition: Sprite.cpp:90
enum Bus::TcasEnum TCAS
WCHAR tcasOnly[16]
Definition: globals.h:594
D3DXVECTOR3 acc
Definition: globals.h:542
short TCASTargetOrdinal
Definition: Bus.h:252
float HeadingTrueDegrees
Definition: Bus.h:30
D3DXVECTOR3 position
Definition: globals.h:549
Definition: Logger.h:9
Sprite * proximate
Definition: Instrument.h:455
s_network_objects playerships[MAX_SCAN]
Definition: globals.cpp:174
float iconOffsetX
Definition: Instrument.h:461
TCASOverlay(int prmX, int prmY, float prmXScale, float prmYScale, Bus *prmBus, Logger *prmLogger, DeviceObject *prmDevice, std::vector< Font *> prmFonts)
Definition: TCASOverlay.cpp:3
DeviceObject * pDevice
Definition: Instrument.h:17
void Update()
Definition: Sprite.cpp:41
void Draw(D3DXCOLOR prmColor)
Definition: Sprite.cpp:66
float pixelPerKmY
Definition: Instrument.h:459
float iconOffsetY
Definition: Instrument.h:462
Definition: Bus.h:16
const D3DXVECTOR3 northpoleC
Definition: Sprite.h:7
Bus * bus
Definition: Instrument.h:18
float xScale
Definition: Instrument.h:15
UINT defaultFont
Definition: Instrument.h:20
std::vector< s_network_objects > targets
Definition: Instrument.h:460
float rotate
Definition: Instrument.h:465
float MapScaleInnerRingKm
Definition: Bus.h:381
void Render() override
Definition: TCASOverlay.cpp:21
Sprite * potentialThreat
Definition: Instrument.h:456
float pixelPerKmX
Definition: Instrument.h:458
float headingTrueRad
Definition: Instrument.h:463
bool groundvehicle
Definition: globals.h:581
Logger * logger
Definition: Instrument.h:19
unsigned char type
Definition: globals.h:532
D3DXVECTOR2 relativeCenter
Definition: Instrument.h:464
void AddToCallStack(const char *msg)
Definition: Logger.cpp:86
Sprite * collisionThreat
Definition: Instrument.h:457
Sprite * noThreat
Definition: Instrument.h:454
float yScale
Definition: Instrument.h:16