-
Notifications
You must be signed in to change notification settings - Fork 0
/
meteo_radar.cpp
461 lines (374 loc) · 13.9 KB
/
meteo_radar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
#include "..\fs9sdk_3d\fs9sdk.h"
//#include "sim1_lib.h"
#include "meteo_radar.h"
#include <stdio.h>
#include <math.h>
void FSAPI meteo_radarCallback( PGAUGEHDR pgauge, SINT32 service_id, UINT32 extra_data );
#pragma warning (disable:4305 4244)
const double Alt_Coeff = 4294967296.0000010;
const double Lat_Coeff = 477302101697422.31;
const double Lon_Coeff = 51240955760304312.000000;
typedef struct ___LATLONALT
{
__int64 lat;
__int64 lon;
__int64 alt;
}__LATLONALT;
typedef struct __POINT_LATLONALT {
FLOAT64 lat;
FLOAT64 lon;
FLOAT64 alt;
} POINT_LATLONALT;
POBSV get_weather_lla(___LATLONALT lla)
{
POBSV _wx;
_wx = (POBSV)Weather_conditions_at_lla_fixed_point((LATLONALT *)&lla,0x3F);
return(_wx);
}
#define SIM1_READ_VALUE -1000000.0f
//#define PI 3.14159265358979f
//=============================================================================================
void get_LL(FLOAT64 Lat_src,FLOAT64 Lon_src,FLOAT64 S,FLOAT64 OD,FLOAT64 *dLat,FLOAT64 *dLon)
{
double s_from_beg = S;
if(s_from_beg<0) s_from_beg=0;
double _cos_S = cos(s_from_beg/(57.29578 * 60 * 1.853));
double _sin_S = sin(s_from_beg/(57.29578 * 60 * 1.853));
double Lat = 57.29578 * asin( sin(Lat_src/57.29578) *
_cos_S + cos(Lat_src/57.29578) * _sin_S *
cos(OD/57.29578)
);
double cos_Lon_S_Lon = (_cos_S - sin(Lat_src/57.29578)*sin(Lat/57.29578))/
(cos(Lat_src/57.29578)*cos(Lat/57.29578));
double Lon;
double s_Lon = Lon_src<0?Lon_src+360.0f:Lon_src;
if(OD<=180) Lon = (acos(cos_Lon_S_Lon) + s_Lon/57.29578)*57.29578;
else Lon = (-acos(fabs(cos_Lon_S_Lon)>1.0f?cos_Lon_S_Lon>0?1.0f:-1.0f:cos_Lon_S_Lon) + s_Lon/57.29578)*57.29578;
if(Lon>180) Lon = Lon-360.0;
*dLat=Lat;
*dLon=Lon;
}
//=============================================================================================
BOOL inline IsCloud (POBSV wx, float alt) {
BOOL bOK = FALSE;
if (!wx)
return FALSE;
PCLOUD_LAYER layer = wx->cloud;
while (layer) {
if (layer->cloud_base <= alt && layer->cloud_tops >= alt && layer->cloud_coverage > 0)
bOK = TRUE;
layer = layer->next_layer;
}
return bOK;
}
int inline GetCloudIntense (POBSV wx, float alt, float fHorizontalDistance, float fZoomSelectorPos, BOOL bIsVARUOn) {
int c = 0, p=0, t=0, i=0, h = 0;
if (!wx)
return 0;
PCLOUD_LAYER layer = wx->cloud;
while (layer) {
if (layer->cloud_coverage > 0 && layer->cloud_base <= alt + 0.035 * fHorizontalDistance * 500 / 0.3048 && layer->cloud_tops >= alt - 0.035 * fHorizontalDistance * 500 / 0.3048) {
if (c < layer->cloud_coverage)
c = layer->cloud_coverage;
if (t < layer->cloud_turbulence)
t = layer->cloud_turbulence;
if (layer->cloud_type == CLOUD_TYPE_THUNDERSTORM)
h = 1;
}
if (layer->precip_type > 0 && layer->cloud_tops >= alt - 0.035 * fHorizontalDistance * 500 / 0.3048)
if (p < layer->precip_rate + 1)
p = layer->precip_rate + 1;
layer = layer->next_layer;
}
i = c + p * 2 + t + h * 4;
if (i > 20) i = 20;
if (!bIsVARUOn)
return i / (1 + 0.5 *(fHorizontalDistance / fZoomSelectorPos));
else
return i;
}
//==========================================================================================
//////////////////////////////////////////////////////////////////////////////
//Ãëîáàëüíûå ïåðåìåííûå
//////////////////////////////////////////////////////////////////////////////
LPDWORD lpdwDisplayRender; // ðàñòð ÝËÒ ÐËÑ
BITMAPINFO BitsInfo; // ìåòàäàííûå ðàñòðà
LPDWORD lpdwGrid; // ìàòðèöà äëÿ õðàíåíèÿ äàííûõ ñ ïðèåìíèêà àíòåííû
int nGridRows = 0; // êîë-âî ñòðîê ìàòðèöû
int nGridCols = 0; // êîë-âî ñòîëáöîâ ìàòðèöû
int iWorkMode = 0; // ðåæèì ðàáîòû (0 - âûêë, 1 - ãîòîâ, 2 - çåìëÿ, 3 - ìåòåî, 4 - êîíòóð, 5 - ñíîñ)
int iPrdSelected = 1; // âûáðàííûé ÏÐÄ (1 - îñíîâíîé, 2 - ðåçåðâíûé)
float fAntennaAzimuth = 0; // îòíîñèòåëüíûé àçèìóò ðàçâîðîòà àíòåííû
int iCurrentCol = 30; // çàïîëíÿåìûé ñòîëáåö ìàòðèöû
int iPrevCol = 30; // ïðåäûäóùèé çàïîëíåííûé ñòîëáåö ìàòðèöû
int iPrev2Col = 30; // ïðåäûäóùèé çàïîëíåííûé ñòîëáåö ìàòðèöû
float fAntennaTrueAzimuth = 0; // èñòèííûé àçèìóò àíòåííû (îòíîñèòåëüíûé àçèìóò + èñòèííûé ÏÓ ñàìîëåòà)
int iAntennaMoveDirection = 0; // íàïðàâëåíèå äâèæåíèÿ àíòåííû (0 - âëåâî, 1 - âïðàâî)
int iInterleaveZone = 0; // ôëàã ÷åðåäîâàíèÿ ñêàíèðîâàíèÿ çîí (âåðõíèå ðÿäû = 1, íèæíèå ðÿäû = 0)
BOOL bManualRotate = FALSE; // àíòåííà â ðåæèìå ðó÷íîãî óïðàâëåíèÿ ðàçâîðîòîì
BOOL bPowerSwitchPos = FALSE; // âûêëþ÷àòåëü ïèòàíèÿ ÐËÑ
float fAngleSelectorPos = 0; // ïîëîæåíèå ðó÷êè íàñòðîéêè óãëà íàêëîíà àíòåííû
int iModeSelectorPos = 1; // ïîëîæåíèå ïåðåêëþ÷àòåëÿ âûáîðà ðåæèìà ðàáîòû ÐËÑ
float fZoomSelectorPos = 10; // ïîëîæåíèå ðó÷êè íàñòðîéêè ìàñøòàáà
BOOL bStabTumblerPos = FALSE; // òóìáëåð "ÑÒÀÁÈËÈÇÀÖÈß ÀÍÒÅÍÍÛ"
BOOL bPrdTumblerPos = TRUE; // òóìáëåð âûáîðà ÏÐÄ (îñíîâíîé - TRUE, ðåçåðâíûé - FALSE)
MODULE_VAR lat_var = {PLANE_LATITUDE}; // / 40007000.0f * 360.0f
MODULE_VAR lon_var = {PLANE_LONGITUDE}; // / 281474976710656.0f * 360.0f
MODULE_VAR alt_var = {PLANE_ALTITUDE};
MODULE_VAR hed_var = {PLANE_HEADING_DEGREES_TRUE};
MODULE_VAR pitch_var = {PLANE_PITCH_DEGREES};
MODULE_VAR bank_var = {PLANE_BANK_DEGREES};
MODULE_VAR forward_var = {FORWARD_GROUND_VELOCITY};
MODULE_VAR side_var = {SIDE_GROUND_VELOCITY};
MODULE_VAR radio_alt= {RADIO_HEIGHT}; // âûñîòà íàä ìåñòíîñòüþ
POINT_LATLONALT aircraft_point; // ïîçèöèÿ èçëó÷àòåëÿ ÐËÑ
float fDriftAngle; // óãîë ñíîñà
#define DISPLAY_WIDTH 328
#define DISPLAY_HEIGHT 206
#define DISPLAY_ELEMENT_SIZE 4
const int DISPLAY_MEMORY_SIZE = DISPLAY_WIDTH*DISPLAY_HEIGHT*DISPLAY_ELEMENT_SIZE;
void CreateDisplayRender (void);
void CreateGrid (void);
int iReadyTimer = 0; // òàéìåð ãîòîâíîñòè ïðîãðåâà òðóáêè
DWORD inline GetColor (float x, float y) {
int xc = (int)x;
int yc = (int)y;
return *(lpdwDisplayRender + (int)yc * DISPLAY_WIDTH + (int)xc);
}
/*
void inline MixColor (int x, int y, DWORD dwColor) {
DWORD dwColor2;
BYTE r, g, b;
BYTE r2, g2, b2;
if (x <=0 || y <= 0 || x >= DISPLAY_WIDTH || y >= DISPLAY_HEIGHT) return;
dwColor2 = *(lpdwDisplayRender + (int)y * DISPLAY_WIDTH + (int)x);
r = (BYTE)(dwColor & 0xFF);
g = (BYTE)((dwColor & 0xFF00) >> 8);
b = (BYTE)((dwColor & 0xFF0000) >> 16);
r2 = (BYTE)(dwColor2 & 0xFF);
g2 = (BYTE)((dwColor2 & 0xFF00) >> 8);
b2 = (BYTE)((dwColor2 & 0xFF0000) >> 16);
*(lpdwDisplayRender + (int)y * DISPLAY_WIDTH + (int)x) = RGB (r+r2/2, g+g2/2, b+b2/2);
}*/
void inline MixColor (int x, int y, DWORD dwColor) {
if (x <=0 || y <= 0 || x >= DISPLAY_WIDTH || y >= DISPLAY_HEIGHT) return;
*(lpdwDisplayRender + (int)y * DISPLAY_WIDTH + (int)x) = dwColor;
}
void inline SetColor (int x, int y, DWORD dwColor) {
if (x <=0 || y <= 0 || x >= DISPLAY_WIDTH || y >= DISPLAY_HEIGHT) return;
*(lpdwDisplayRender + (int)y * DISPLAY_WIDTH + (int)x) = dwColor;
}
void inline DrawFilledCircle (float x, float y, int ri, DWORD dwColor) {
int xc = (int)x;
int yc = (int)y;
switch (ri) {
case 2:
MixColor(xc-1,yc-1,dwColor);
SetColor(xc,yc-1,dwColor);
MixColor(xc+1,yc-1,dwColor);
SetColor(xc-1,yc,dwColor);
SetColor(xc,yc,dwColor);
SetColor(xc+1,yc,dwColor);
MixColor(xc-1,yc+1,dwColor);
SetColor(xc,yc+1,dwColor);
MixColor(xc+1,yc+1,dwColor);
break;
case 3:
MixColor(xc-1,yc-2,dwColor);
SetColor(xc,yc-2,dwColor);
MixColor(xc+1,yc-2,dwColor);
MixColor(xc-2,yc-1,dwColor);
SetColor(xc-1,yc-1,dwColor);
SetColor(xc,yc-1,dwColor);
SetColor(xc+1,yc-1,dwColor);
MixColor(xc+2,yc-1,dwColor);
SetColor(xc-2,yc,dwColor);
SetColor(xc-1,yc,dwColor);
SetColor(xc,yc,dwColor);
SetColor(xc+1,yc,dwColor);
SetColor(xc+2,yc,dwColor);
MixColor(xc-2,yc+1,dwColor);
SetColor(xc-1,yc+1,dwColor);
SetColor(xc,yc+1,dwColor);
SetColor(xc+1,yc+1,dwColor);
MixColor(xc+2,yc+1,dwColor);
MixColor(xc-1,yc+2,dwColor);
SetColor(xc,yc+2,dwColor);
MixColor(xc+1,yc+2,dwColor);
break;
}
/*
for (int r = 1; r <= ri; r++) {
for (float a = 0; a < 360; a+= 30) {
int xcc = (int)(xc + cos (a * PI / 360) * r);
int ycc = (int)(yc + sin (a * PI / 360) * r);
if (xcc > 0 && ycc > 0 && xcc < DISPLAY_WIDTH && ycc < DISPLAY_HEIGHT)
*(lpdwDisplayRender + (int)ycc * DISPLAY_WIDTH + (int)xcc) = dwColor;
}
}
*/
}
void inline DrawFilledCircle2 (float x, float y, int ri, DWORD dwColor) {
int xc = (int)x;
int yc = (int)y;
for (int r = 1; r <= ri; r++) {
for (float a = 0; a < 360; a+= 30) {
int xcc = (int)(xc + cos (a * PI / 360) * r);
int ycc = (int)(yc + sin (a * PI / 360) * r);
if (xcc > 0 && ycc > 0 && xcc < DISPLAY_WIDTH && ycc < DISPLAY_HEIGHT)
*(lpdwDisplayRender + (int)ycc * DISPLAY_WIDTH + (int)xcc) = dwColor;
}
}
}
void inline DrawFilledCircle3 (float x, float y, int ri, DWORD dwColor) {
int xc = (int)x;
int yc = (int)y;
for (int r = 1; r <= ri; r++) {
for (float a = 0; a < 360; a+= 30) {
int xcc = (int)(xc + cos (a * PI / 180) * r);
int ycc = (int)(yc + sin (a * PI / 180) * r);
if (xcc > 0 && ycc > 0 && xcc < DISPLAY_WIDTH && ycc < DISPLAY_HEIGHT)
if (r >= ri - 1) {
DWORD dwColor2;
int r, g, b;
int r2, g2, b2;
if (x <=0 || y <= 0 || x >= DISPLAY_WIDTH || y >= DISPLAY_HEIGHT) return;
dwColor2 = *(lpdwDisplayRender + (int)ycc * DISPLAY_WIDTH + (int)xcc);
r = (int)(dwColor & 0xFF);
g = (int)((dwColor & 0xFF00) >> 8);
b = (int)((dwColor & 0xFF0000) >> 16);
r2 = (int)(dwColor2 & 0xFF);
g2 = (int)((dwColor2 & 0xFF00) >> 8);
b2 = (int)((dwColor2 & 0xFF0000) >> 16);
*(lpdwDisplayRender + (int)ycc * DISPLAY_WIDTH + (int)xcc) = RGB ((r+r2)/2, (g+g2)/2, (b+b2)/2);
}
else {
*(lpdwDisplayRender + (int)ycc * DISPLAY_WIDTH + (int)xcc) = dwColor;
}
}
}
}
BOOL inline FadeExtremeWeather (int y, int x) {
int iOK = 0;
if (x > 0)
if (*(lpdwGrid + y * (nGridCols - 1) + (x-1)) > 6) iOK++;
if (y > 0)
if (*(lpdwGrid + (y-1) * (nGridCols - 1) + x) > 6) iOK++;
if (x < nGridCols - 1)
if (*(lpdwGrid + y * (nGridCols - 1) + (x+1)) > 6) iOK++;
if (y < nGridRows - 1)
if (*(lpdwGrid + (y+1) * (nGridCols - 1) + x) > 6) iOK++;
return (iOK > 3);
}
/////////////////////////////////////////////////////////////////////////////
// Ìîäóëü ëîãèêè
/////////////////////////////////////////////////////////////////////////////
#define GAUGE_NAME "Logic"
#define GAUGEHDR_VAR_NAME gaugehdr_logic
#define GAUGE_W 1
#include "logic.cpp"
/////////////////////////////////////////////////////////////////////////////
// Ýêðàí ÐËÑ
/////////////////////////////////////////////////////////////////////////////
//#define GAUGE_NAME "Display"
//#define GAUGEHDR_VAR_NAME gaugehdr_display
//#define GAUGE_W 722
//#include "display.cpp"
/////////////////////////////////////////////////////////////////////////////
// Ýêðàí ÐËÑ (âàðèàíò 2)
/////////////////////////////////////////////////////////////////////////////
#define GAUGE_NAME "ICU"
#define GAUGEHDR_VAR_NAME gaugehdr_display2
#define GAUGE_W 722
#include "display2.cpp"
/////////////////////////////////////////////////////////////////////////////
// Ïóëüò ÐËÑ
/////////////////////////////////////////////////////////////////////////////
//#define GAUGE_NAME "Control"
//#define GAUGEHDR_VAR_NAME gaugehdr_control
//#define GAUGE_W 251
//#include "control.cpp"
/////////////////////////////////////////////////////////////////////////////
// Ïóëüò óïðàâëåíèÿ ðàçâîðîòîì ÐËÑ
/////////////////////////////////////////////////////////////////////////////
//#define GAUGE_NAME "RotateControl"
//#define GAUGEHDR_VAR_NAME gaugehdr_rotate_control
//#define GAUGE_W 43
//#include "rotate_control.cpp"
//==========================================================================================
void CreateDisplayRender (void) {
// ñîçäàåì ðàñòð ÝËÒ ÐËÑ
// ðàçìåðíîñòüþ 328õ206 + 1 ñòðîêà çàïàñà 32 bit
lpdwDisplayRender = (LPDWORD)malloc (DISPLAY_MEMORY_SIZE + DISPLAY_WIDTH * 4);
memset (&BitsInfo, 0, sizeof (BITMAPINFO));
BitsInfo.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
BitsInfo.bmiHeader.biWidth = DISPLAY_WIDTH;
BitsInfo.bmiHeader.biHeight = DISPLAY_HEIGHT;
BitsInfo.bmiHeader.biPlanes = 1;
BitsInfo.bmiHeader.biBitCount = 32;
BitsInfo.bmiHeader.biCompression = BI_RGB;
BitsInfo.bmiHeader.biSizeImage = 0;
BitsInfo.bmiHeader.biXPelsPerMeter = 1;
BitsInfo.bmiHeader.biYPelsPerMeter = 1;
BitsInfo.bmiHeader.biClrUsed = 0;
BitsInfo.bmiHeader.biClrImportant = 0;
}
void CreateGrid (void) {
// ñîçäàåì ìàòðèöó
lpdwGrid = (LPDWORD)malloc (nGridRows * nGridCols * 4);
iCurrentCol = (int)(nGridCols / 2);
}
void FSAPI module_init(void)
{
iReadyTimer = 15*18;
// ñîçäàåì ðàñòð ÝËÒ ÐËÑ
CreateDisplayRender ();
// ñîçäàåì ìàòðèöó äàííûõ ñ ïðèåìíèêà àíòåííû ÐËÑ
// âêëþ÷àåì îñíîâíîé ÏÐÄ
nGridCols = 61;
nGridRows = 10;
CreateGrid ();
}
void FSAPI module_deinit(void)
{
// óäàëÿåì ðàñòð ÝËÒ ÐËÑ
if (lpdwDisplayRender)
free (lpdwDisplayRender);
// óäàëÿåì ìàòðèöó äàííûõ ñ ïðèåìíèêà àíòåííû ÐËÑ
if (lpdwGrid)
free (lpdwGrid);
}
BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
{
return TRUE;
}
GAUGESIMPORT ImportTable =
{
{ 0x0000000F, (PPANELS)NULL },
{ 0x00000002, (PGLOBAL)NULL },
{ 0x00000001, (PFS6API)NULL },
{ 0x00000019, (PSIM1)NULL },
{ 0x00000027, (PSOUND)NULL },
{ 0x00000010, (PCONTROLS)NULL },
{ 0x0000001c, (PWEATHER)NULL },
{ 0x0000000E, (g3d_linkage *)NULL },
{ 0x00000000, NULL }
};
/* This is the module's export table. */
GAUGESLINKAGE Linkage =
{
0x00000013,
module_init,
module_deinit,
0,
0,
FS9LINK_VERSION,
{
(&gaugehdr_logic),
// (&gaugehdr_display),
(&gaugehdr_display2),
// (&gaugehdr_control),
// (&gaugehdr_rotate_control),
0
}
};