zkv1000 / Nasal / animate.nas /
Newer Older
406 lines | 13.92kb
commit initial
Sébastien MARQUE authored on 2017-03-07
1
# animate parts of the screen, popups, widgets, etc.
2
var update = {
3
    AI : func(roll,pitch){
4
        if (pitch > 80 ) {
5
            var pitch = 80;
6
        }
7
        elsif (pitch < -80) {
8
            var pitch = -80;
9
        }
10

            
11
        var RollR = -roll*D2R;
12

            
13
        var AP  = 57.5;
14
        var AN  = 27.5;
15
        var BP  = 37.5;
16
        var BN  = 40;
17

            
18
        var HLAPRN = math.sqrt(1/(math.pow(math.cos(RollR)/AP,2)+(math.pow(math.sin(RollR)/BN,2))));
19
        var HLANBN = math.sqrt(1/(math.pow(math.cos(RollR)/AN,2)+(math.pow(math.sin(RollR)/BN,2))));
20
        var HLAPBP = math.sqrt(1/(math.pow(math.cos(RollR)/AP,2)+(math.pow(math.sin(RollR)/BP,2))));
21
        var HLANBP = math.sqrt(1/(math.pow(math.cos(RollR)/AN,2)+(math.pow(math.sin(RollR)/BP,2))));
22

            
23
        var RAP = ((roll > -90) and (roll <= 90));
24
        var RAN = ((roll <= -90) or (roll > 90));
25
        var RBP = (roll >= 0);
26
        var RBN = (roll < 0);
27

            
28
        if ((pitch >= 0) and (RAP and RBN)) {
29
            var limit = HLAPRN;
30
        }
31
        elsif ((pitch >= 0) and (RAN and RBN)) {
32
            var limit = HLANBN;
33
        }
34
        elsif ((pitch >= 0)and (RAP and RBP)) {
35
            var limit = HLAPBP;
36
        }
37
        elsif ((pitch >= 0)and (RAN and RBP)) {
38
            var limit = HLANBP;
39
        }
40
        elsif ((pitch < 0) and (RAN and RBP)) {
41
            var limit = HLAPRN;
42
        }
43
        elsif ((pitch < 0) and (RAP and RBP)) {
44
            var limit = HLANBN;
45
        }
46
        elsif ((pitch < 0)and (RAN and RBN)) {
47
            var limit = HLAPBP;
48
        }
49
        elsif ((pitch < 0)and (RAP and RBN)) {
50
            var limit = HLANBP;
51
        }
52

            
53
        if (pitch > limit) {
54
            var Hpitch = limit;
55
        }
56
        elsif (-pitch > limit) {
57
            var Hpitch = -limit;
58
        }
59
        else {
60
            var Hpitch = pitch;
61
        }
62

            
63
        me.Horizon.rot.setRotation(RollR, me.PitchScale.getCenter());
64
        me.Horizon.trans.setTranslation(0,Hpitch*6.8571428);
65

            
66
        me.HorizonLine.rot.setRotation(RollR, me.PitchScale.getCenter());
67
        me.HorizonLine.trans.setTranslation(0,pitch*6.8571428);
68
        me.PitchScale.rot.setRotation(RollR, me.PitchScale.getCenter());
69
        me.PitchScale.trans.setTranslation(0,pitch*6.8571428);
70

            
71
        var brot = me.bankPointer.getCenter();
72
        me.bankPointer.rot.setRotation(RollR,brot);
73
        me.bankPointerLineL.rot.setRotation(RollR,brot);
74
        me.bankPointerLineR.rot.setRotation(RollR,brot);
75

            
76
        if (RollR < 0) { #top, right, bottom, left
77
        
78
            me.bankPointerLineL.set("clip", "rect(0,1,1,0)"); #459,500
79
            me.bankPointerLineR.set("clip", "rect(0,459.500,768,0)");
80
        }
81
        elsif (RollR > 0) {
82
            me.bankPointerLineL.set("clip", "rect(0,1024,768,459.500)"); #459,500
83
            me.bankPointerLineR.set("clip", "rect(0,1,1,0)");
84
        }
85
        else {
86
            me.bankPointerLineL.set("clip", "rect(0,1024,768,459.500)"); #459,500
87
            me.bankPointerLineR.set("clip", "rect(0,459.500,768,0)");
88
        }
89
    },
90

            
91
    HDG : func(Heading) {
92
        HSB = Heading + -45;
93
        if (HSB >= 360) {
94
            HSB = HSB -360;
95
        }
96
        elsif (HSB < 0) {
97
            HSB = HSB + 360;
98
        }
99

            
100
        me.HSBug.setRotation(-HSB*D2R);
101
        me.Compass.setRotation(-Heading*D2R);
102
        
103
        if (Heading == 0) {
104
            #Heading = 360;
105
        }
106
        me.CompassText.setText(sprintf("%03.0f°",math.floor(Heading)));
107
    },
108

            
109
    SPD : func(speed)
110
    {
111
        if (speed != nil) {
112
            me.data.speed = speed;
113
            var Offset1 = 0;
114
            var Offset10 = 0;
115

            
116
            if (speed < 20) {
117
                var speed = 20;
118
                me.LindSpeed.set("clip", "rect(114px, 239px, 284,5px, 154px)");
119
            }
120
            elsif (speed >= 20 and  speed < 50) {
121
                me.LindSpeed.set("clip", sprintf("rect(114px, 239px, %1.0fpx, 154px)", math.floor(284.5 + ((speed-20) * 5.71225) ) ) );
122
            }
123
            else {
124
                me.LindSpeed.set("clip", "rect(114px, 239px, 455px, 154px)");
125
            }
126

            
127
            if (speed > 20) {
128
                me.LindSpeed.setTranslation(0,speed*5.71225);
129
            }
130
            else {
131
                #me.SpeedNonLint.setText("---");
132
                me.LindSpeed.setTranslation(0,114,245);
133
            }
134

            
135
            var speed1      = math.mod(speed,10);
136
            var speed10     = int(math.mod(speed/10,10));
137
            var speed100    = int(math.mod(speed/100,10));
138
            var speed0_1    = speed1 - int(speed1);
139
            if (speed1 >= 9) {
140
                var speed10 += speed0_1;
141
            }
142

            
143
            if (speed1 >= 9 and speed10 >= 9) {
144
                var speed100 += speed0_1;
145
            }
146

            
147
            if (speed >= 10) {
148
                var Offset1 = 10;
149
            }
150

            
151
            if (speed >= 100) {
152
                var Offset10 = 10;
153
            }
154

            
155
            me.LindSpeed.setTranslation(0,speed*5.71225);
156
            me.SpeedtLint1.setTranslation(0,(speed1+Offset1)*36);
157
            me.SpeedtLint10.setTranslation(0,(speed10+Offset10)*36);
158
            me.SpeedtLint100.setTranslation(0,(speed100)*36);
159
        }
160
        else {
161
            me.LindSpeed.Element.set("clip", "rect(114px, 239px, 455px, 154px)");
162
        }
163
    },
164

            
165
    SpeedTrend: func(Speedtrent) {
166
        me.data.speedTrent;
167
    },
168
    
169
    SlipSkid: func(slipskid){
170
        me.SlipSkid.setTranslation(slipskid*5.73,0);
171
    },
172

            
173
    ALT : func(Alt) {
174

            
175
        if (Alt !=nil) {
176
            me.AltLint10.show();
177
            me.AltLint100.show();
178
            me.AltLint1000.show();
179
            me.AltLint10000.show();
180
            if (Alt> -1000 and Alt< 1000000) {
181
                var Offset10 = 0;
182
                var Offset100 = 0;
183
                var Offset1000 = 0;
184
                if (Alt< 0) {
185
                    var Ne = 1;
186
                    var Alt= -Alt
187
                }
188
                else {
189
                    var Ne = 0;
190
                }
191

            
192
                var Alt10       = math.mod(Alt,100);
193
                var Alt100      = int(math.mod(Alt/100,10));
194
                var Alt1000     = int(math.mod(Alt/1000,10));
195
                var Alt10000    = int(math.mod(Alt/10000,10));
196
                var Alt20       = math.mod(Alt10,20)/20;
197
                if (Alt10 >= 80) {
198
                    var Alt100 += Alt20
199
                }
200

            
201
                if (Alt10 >= 80 and Alt100 >= 9) {
202
                    var Alt1000 += Alt20
203
                }
204

            
205
                if (Alt10 >= 80 and Alt100 >= 9 and Alt1000 >= 9) {
206
                    var Alt10000 += Alt20
207
                }
208

            
209
                if (Alt> 100) {
210
                    var Offset10 = 100;
211
                }
212

            
213
                if (Alt> 1000) {
214
                    var Offset100 = 10;
215
                }
216

            
217
                if (Alt> 10000) {
218
                    var Offset1000 = 10;
219
                }
220

            
221
                if (!Ne) {
222
                    me.AltLint10.setTranslation(0,(Alt10+Offset10)*1.2498);
223
                    me.AltLint100.setTranslation(0,(Alt100+Offset100)*30);
224
                    me.AltLint1000.setTranslation(0,(Alt1000+Offset1000)*36);
225
                    me.AltLint10000.setTranslation(0,(Alt10000)*36);
226
                    me.LintAlt.setTranslation(0,(math.mod(Alt,100))*0.57375);
227
                    var altCentral = (int(Alt/100)*100);
228
                }
229
                else {
230
                    me.AltLint10.setTranslation(0,(Alt10+Offset10)*-1.2498);
231
                    me.AltLint100.setTranslation(0,(Alt100+Offset100)*-30);
232
                    me.AltLint1000.setTranslation(0,(Alt1000+Offset1000)*-36);
233
                    me.AltLint10000.setTranslation(0,(Alt10000)*-36);
234
                    me.LintAlt.setTranslation(0,(math.mod(Alt,100))*-0.57375);
235
                    var altCentral = -(int(Alt/100)*100);
236
                }
237

            
238
                me["AltBigC"].setText("");
239
                me["AltSmallC"].setText("");
240
                var placeInList = [1,2,3,4,5,6];
241
                foreach(var place; placeInList) {
242
                    var altUP = altCentral + (place*100);
243
                    var offset = -30.078;
244
                    if (altUP < 0) {
245
                        var altUP = -altUP;
246
                        var prefix = "-";
247
                        var offset += 15.039;
248
                    }
249
                    else {
250
                        var prefix = "";
251
                    }
252
                    if (altUP == 0) {
253
                        var AltBigUP    = "";
254
                        var AltSmallUP  = "0";
255
                    }
256
                    elsif (math.mod(altUP,500) == 0 and altUP != 0) {
257
                        var AltBigUP    = sprintf(prefix~"%1d", altUP);
258
                        var AltSmallUP  = "";
259
                    }
260
                    elsif (altUP < 1000 and (math.mod(altUP,500))) {
261
                        var AltBigUP    = "";
262
                        var AltSmallUP  = sprintf(prefix~"%1d", int(math.mod(altUP,1000)));
263
                        var offset = -30.078;
264
                    }
265
                    elsif ((altUP < 10000) and (altUP >= 1000) and (math.mod(altUP,500))) {
266
                        var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
267
                        var AltSmallUP  = sprintf("%1d", int(math.mod(altUP,1000)));
268
                        var offset += 15.039;
269
                    }
270
                    else {
271
                        var AltBigUP    = sprintf(prefix~"%1d", int(altUP/1000));
272
                        var mod = int(math.mod(altUP,1000));
273
                        var AltSmallUP  = sprintf("%1d", mod);
274
                        var offset += 30.078;
275
                    }
276

            
277
                    me["AltBigU"~place].setText(AltBigUP);
278
                    me["AltSmallU"~place].setText(AltSmallUP);
279
                    me["AltSmallU"~place].setTranslation(offset,0);
280
                    var altDOWN = altCentral - (place*100);
281
                    var offset = -30.078;
282
                    if (altDOWN < 0) {
283
                        var altDOWN = -altDOWN;
284
                        var prefix = "-";
285
                        var offset += 15.039;
286
                    }
287
                    else {
288
                        var prefix = "";
289
                    }
290
                    if (altDOWN == 0) {
291
                        var AltBigDOWN  = "";
292
                        var AltSmallDOWN    = "0";
293

            
294
                    }
295
                    elsif (math.mod(altDOWN,500) == 0 and altDOWN != 0) {
296
                        var AltBigDOWN  = sprintf(prefix~"%1d", altDOWN);
297
                        var AltSmallDOWN    = "";
298
                    }
299
                    elsif (altDOWN < 1000 and (math.mod(altDOWN,500))) {
300
                        var AltBigDOWN  = "";
301
                        var AltSmallDOWN    = sprintf(prefix~"%1d", int(math.mod(altDOWN,1000)));
302
                        var offset = -30.078;
303
                    }
304
                    elsif ((altDOWN < 10000) and (altDOWN >= 1000) and (math.mod(altDOWN,500))) {
305
                        var AltBigDOWN  = sprintf(prefix~"%1d", int(altDOWN/1000));
306
                        var AltSmallDOWN    = sprintf("%1d", int(math.mod(altDOWN,1000)));
307
                        var offset += 15.039;
308
                    }
309
                    else {
310
                        var AltBigDOWN  = sprintf(prefix~"%1d", int(altDOWN/1000));
311
                        var mod = int(math.mod(altDOWN,1000));
312
                        var AltSmallDOWN    = sprintf("%1d", mod);
313
                        var offset += 30.078;
314
                    }
315
                    me["AltBigD"~place].setText(AltBigDOWN);
316
                    me["AltSmallD"~place].setText(AltSmallDOWN);
317
                    me["AltSmallD"~place].setTranslation(offset,0);
318
                }
319
            }
320
            else {
321
                me.AltLint10.hide();
322
                me.AltLint100.hide();
323
                me.AltLint1000.hide();
324
                me.AltLint10000.hide();
325
            }
326

            
327
        }
328
    },
329

            
330
    VSI : func(VSI) {
331
        if (VSI != nil) {
332

            
333
            if (VSI > 4250) {
334
                var VSIOffset = -148.21875;
335
            }
336
            elsif (VSI < -4250) {
337
                var VSIOffset = 148.21875;
338
            }
339
            else {
340
                var VSIOffset = (-VSI)*0.034875;
341
            }
342

            
343
            if ((VSI < 100) and (VSI > -100)) {
344
                var VSIText = "";
345
            }
346
            elsif ((VSI < -10000) or (VSI > 10000)) {
347
                var VSIText = "----";
348
            }
349
            else {
350
                var VSIText = sprintf("%1d",int(VSI/50)*50);
351
            }
352
        }
353
        else {
354
            var VSIText = "";
355
            var VSIOffset = 0
356
        }
357
        #print (VSIText ~ " " ~ sprintf("%1.0f", VSI));
358
        me.VSIText.setText(VSIText);
359
        me.VSI.setTranslation(0,VSIOffset);
360
    },
361

            
362
    OMI : func(marker) {
363
        if (marker == 0) {
364
            me.Marker.hide();
365
        }
366
        if (marker == 1) { #OM 
367
            me.Marker.show();
368
            me.MarkerBG.setColorFill(0.603921569,0.843137255,0.847058824);
369
            me.MarkerText.setText('O');
370
        }
371
        elsif (marker == 2) { #MM
372
            me.Marker.show();
373
            me.MarkerBG.setColorFill(1,0.870588235,0.11372549);
374
            me.MarkerText.setText('M');
375
        }
376
        elsif (marker == 3) { #IM
377
            me.Marker.show();
378
            me.MarkerBG.setColorFill(1,1,1);
379
            me.MarkerText.setText('I');
380
        }
381
    },
382

            
383
    ILS: func(ils){
384
        if (ils != nil) {
385
            me.ILS.setTranslation(0,-(ils*86.984));
386
        }
387
        else {
388
            me.ILS.setTranslation(0,0);
389
        }
390
    },
391
};
392

            
393
var widgets = {
394
    SetMap: func(post)
395
    {
396
        if (post = 1) {
397
            #open map on the left
398
        }
399
        elsif (post = 2) {
400
            #open map on the right
401
        }
402
        elsif (post = 0) {
403
            #close map
404
        }
405
    },
406
};