]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD_ladder.cxx
1332bf07784cc0a1e6e8634dc454c2e5c757ee77
[flightgear.git] / src / Instrumentation / HUD / HUD_ladder.cxx
1 // HUD_ladder.cxx -- HUD Ladder Instrument
2 //
3 // Written by Michele America, started September 1997.
4 //
5 // Copyright (C) 1997  Michele F. America  [micheleamerica#geocities:com]
6 // Copyright (C) 2006  Melchior FRANZ  [mfranz#aon:at]
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22 #ifdef HAVE_CONFIG_H
23 #  include <config.h>
24 #endif
25
26 #include <Main/viewer.hxx>
27 #include "HUD.hxx"
28
29
30 // FIXME
31 float get__heading() { return fgGetFloat("/orientation/heading-deg") * M_PI / 180.0; }
32 float get__throttleval() { return fgGetFloat("/controls/engines/engine/throttle"); }
33 float get__aoa() { return fgGetFloat("/sim/frame-rate"); }                                      // FIXME
34 float get__Vx() { return fgGetFloat("/velocities/uBody-fps"); }
35 float get__Vy() { return fgGetFloat("/velocities/vBody-fps"); }
36 float get__Vz() { return fgGetFloat("/velocities/wBody-fps"); }
37 float get__Ax() { return fgGetFloat("/acclerations/pilot/x-accel-fps_sec"); }
38 float get__Ay() { return fgGetFloat("/acclerations/pilot/y-accel-fps_sec"); }
39 float get__Az() { return fgGetFloat("/acclerations/pilot/z-accel-fps_sec"); }
40 #undef ENABLE_SP_FMDS
41
42
43 HUD::Ladder::Ladder(HUD *hud, const SGPropertyNode *n, float x, float y) :
44     Item(hud, n, x, y),
45     _pitch(n->getNode("pitch-input", false)),
46     _roll(n->getNode("roll-input", false)),
47     _width_units(int(n->getFloatValue("display-span"))),
48     div_units(int(fabs(n->getFloatValue("divisions")))),
49     label_pos(n->getIntValue("lbl-pos")),
50     _scr_hole(n->getIntValue("screen-hole")),
51     _compression(n->getFloatValue("compression-factor")),
52     _frl(n->getBoolValue("enable-fuselage-ref-line", false)),
53     _target_spot(n->getBoolValue("enable-target-spot", false)),
54     _velocity_vector(n->getBoolValue("enable-velocity-vector", false)),
55     _drift_marker(n->getBoolValue("enable-drift-marker", false)),
56     _alpha_bracket(n->getBoolValue("enable-alpha-bracket", false)),
57     _energy_marker(n->getBoolValue("enable-energy-marker", false)),
58     _climb_dive_marker(n->getBoolValue("enable-climb-dive-marker", false)),
59     _glide_slope_marker(n->getBoolValue("enable-glide-slope-marker",false)),
60     _glide_slope(n->getFloatValue("glide-slope", -4.0)),
61     _energy_worm(n->getBoolValue("enable-energy-marker", false)),
62     _waypoint_marker(n->getBoolValue("enable-waypoint-marker", false)),
63     _zenith(n->getIntValue("zenith")),
64     _nadir(n->getIntValue("nadir")),
65     _hat(n->getIntValue("hat"))
66 {
67     const char *t = n->getStringValue("type");
68     _type = strcmp(t, "climb-dive") ? PITCH : CLIMB_DIVE;
69
70     if (!_width_units)
71         _width_units = 45;
72
73     _vmax = _width_units / 2;
74     _vmin = -_vmax;
75 }
76
77
78 void HUD::Ladder::draw(void)
79 {
80     if (!_pitch.isValid() || !_roll.isValid())
81         return;
82
83     float x_ini, x_ini2;
84     float x_end, x_end2;
85     float y = 0;
86     int count;
87     float cosine, sine, xvvr, yvvr, Vxx = 0.0, Vyy = 0.0, Vzz = 0.0;
88     float up_vel, ground_vel, actslope = 0.0;
89     float Axx = 0.0, Ayy = 0.0, Azz = 0.0, total_vel = 0.0, pot_slope, t1;
90     float t2 = 0.0, psi = 0.0, alpha, pla;
91     float vel_x = 0.0, vel_y = 0.0, drift;
92     bool pitch_ladder = false;
93     bool climb_dive_ladder = false;
94     bool clip_plane = false;
95
96     GLdouble eqn_top[4] = {0.0, -1.0, 0.0, 0.0};
97     GLdouble eqn_left[4] = {-1.0, 0.0, 0.0, 100.0};
98     GLdouble eqn_right[4] = {1.0, 0.0, 0.0, 100.0};
99
100     Point centroid = get_centroid();
101     Rect box = get_location();
102
103     float half_span = box.right / 2.0;
104     float roll_value = _roll.getFloatValue() * SGD_DEGREES_TO_RADIANS;          // FIXME rad/deg conversion
105     alpha = get__aoa();
106     pla = get__throttleval();
107
108 #ifdef ENABLE_SP_FMDS
109     int lgear, wown, wowm, ilcanclaw, ihook;
110     ilcanclaw = get__iaux2();
111     lgear = get__iaux3();
112     wown = get__iaux4();
113     wowm = get__iaux5();
114     ihook = get__iaux6();
115 #endif
116     float pitch_value = _pitch.getFloatValue();
117
118     if (_type == CLIMB_DIVE) {
119         pitch_ladder = false;
120         climb_dive_ladder = true;
121         clip_plane = true;
122
123     } else { // _type == PITCH
124         pitch_ladder = true;
125         climb_dive_ladder = false;
126         clip_plane = false;
127     }
128
129     //**************************************************************
130     glPushMatrix();
131     // define (0, 0) as center of screen
132     glTranslatef(centroid.x, centroid.y, 0);
133
134     // OBJECT STATIC RETICLE
135     // TYPE FRL (FUSELAGE REFERENCE LINE)
136     // ATTRIB - ALWAYS
137     // Draw the FRL spot and line
138     if (_frl) {
139 #define FRL_DIAMOND_SIZE 2.0
140         glBegin(GL_LINE_LOOP);
141         glVertex2f(-FRL_DIAMOND_SIZE, 0.0);
142         glVertex2f(0.0, FRL_DIAMOND_SIZE);
143         glVertex2f(FRL_DIAMOND_SIZE, 0.0);
144         glVertex2f(0.0, -FRL_DIAMOND_SIZE);
145         glEnd();
146
147         glBegin(GL_LINE_STRIP);
148         glVertex2f(0, FRL_DIAMOND_SIZE);
149         glVertex2f(0, 8.0);
150         glEnd();
151 #undef FRL_DIAMOND_SIZE
152     }
153     // TYPE WATERLINE_MARK (W shaped _    _ )
154     //                                \/\/
155
156     //****************************************************************
157     // TYPE TARGET_SPOT
158     // Draw the target spot.
159     if (_target_spot) {
160 #define CENTER_DIAMOND_SIZE 6.0
161         glBegin(GL_LINE_LOOP);
162         glVertex2f(-CENTER_DIAMOND_SIZE, 0.0);
163         glVertex2f(0.0, CENTER_DIAMOND_SIZE);
164         glVertex2f(CENTER_DIAMOND_SIZE, 0.0);
165         glVertex2f(0.0, -CENTER_DIAMOND_SIZE);
166         glEnd();
167 #undef CENTER_DIAMOND_SIZE
168     }
169
170     //****************************************************************
171     //velocity vector reticle - computations
172     if (_velocity_vector) {
173         Vxx = get__Vx();
174         Vyy = get__Vy();
175         Vzz = get__Vz();
176         Axx = get__Ax();
177         Ayy = get__Ay();
178         Azz = get__Az();
179         psi = get__heading();
180
181         if (psi > 180.0)
182             psi = psi - 360;
183
184         total_vel = sqrt(Vxx * Vxx + Vyy * Vyy + Vzz * Vzz);
185         ground_vel = sqrt(Vxx * Vxx + Vyy * Vyy);
186         up_vel = Vzz;
187
188         if (ground_vel < 2.0) {
189             if (fabs(up_vel) < 2.0)
190                 actslope = 0.0;
191             else
192                 actslope = (up_vel / fabs(up_vel)) * 90.0;
193
194         } else {
195             actslope = atan(up_vel / ground_vel) * SGD_RADIANS_TO_DEGREES;
196         }
197
198         xvvr = (((atan2(Vyy, Vxx) * SGD_RADIANS_TO_DEGREES) - psi)
199                 * (_compression / globals->get_current_view()->get_aspect_ratio()));
200         drift = ((atan2(Vyy, Vxx) * SGD_RADIANS_TO_DEGREES) - psi);
201         yvvr = ((actslope - pitch_value) * _compression);
202         vel_y = ((actslope - pitch_value) * cos(roll_value) + drift * sin(roll_value)) * _compression;
203         vel_x = (-(actslope - pitch_value) * sin(roll_value) + drift * cos(roll_value))
204                 * (_compression / globals->get_current_view()->get_aspect_ratio());
205         //  printf("%f %f %f %f\n",vel_x, vel_y, drift, psi);
206
207         //****************************************************************
208         // OBJECT MOVING RETICLE
209         // TYPE - DRIFT MARKER
210         // ATTRIB - ALWAYS
211         // drift marker
212         if (_drift_marker) {
213             glBegin(GL_LINE_STRIP);
214             glVertex2f((xvvr * 25 / 120) - 6, -4);
215             glVertex2f(xvvr * 25 / 120, 8);
216             glVertex2f((xvvr * 25 / 120) + 6, -4);
217             glEnd();
218         }
219
220         //****************************************************************
221         // Clipping coordinates for ladder to be input from xml file
222         // Clip hud ladder
223         if (clip_plane) {
224             glClipPlane(GL_CLIP_PLANE0, eqn_top);
225             glEnable(GL_CLIP_PLANE0);
226             glClipPlane(GL_CLIP_PLANE1, eqn_left);
227             glEnable(GL_CLIP_PLANE1);
228             glClipPlane(GL_CLIP_PLANE2, eqn_right);
229             glEnable(GL_CLIP_PLANE2);
230             // glScissor(-100,-240, 200, 240);
231             // glEnable(GL_SCISSOR_TEST);
232         }
233
234         //****************************************************************
235         // OBJECT MOVING RETICLE
236         // TYPE VELOCITY VECTOR
237         // ATTRIB - ALWAYS
238         // velocity vector
239         glBegin(GL_LINE_LOOP);  // Use polygon to approximate a circle
240         for (count = 0; count < 50; count++) {
241             cosine = 6 * cos(count * SGD_2PI / 50.0);
242             sine =   6 * sin(count * SGD_2PI / 50.0);
243             glVertex2f(cosine + vel_x, sine + vel_y);
244         }
245         glEnd();
246
247         //velocity vector reticle orientation lines
248         glBegin(GL_LINE_STRIP);
249         glVertex2f(vel_x - 12, vel_y);
250         glVertex2f(vel_x - 6, vel_y);
251         glEnd();
252         glBegin(GL_LINE_STRIP);
253         glVertex2f(vel_x + 12, vel_y);
254         glVertex2f(vel_x + 6, vel_y);
255         glEnd();
256         glBegin(GL_LINE_STRIP);
257         glVertex2f(vel_x, vel_y + 12);
258         glVertex2f(vel_x, vel_y + 6);
259         glEnd();
260
261 #ifdef ENABLE_SP_FMDS
262         // OBJECT MOVING RETICLE
263         // TYPE LINE
264         // ATTRIB - ON CONDITION
265         if (lgear == 1) {
266             // undercarriage status
267             glBegin(GL_LINE_STRIP);
268             glVertex2f(vel_x + 8, vel_y);
269             glVertex2f(vel_x + 8, vel_y - 4);
270             glEnd();
271
272             // OBJECT MOVING RETICLE
273             // TYPE LINE
274             // ATTRIB - ON CONDITION
275             glBegin(GL_LINE_STRIP);
276             glVertex2f(vel_x - 8, vel_y);
277             glVertex2f(vel_x - 8, vel_y - 4);
278             glEnd();
279
280             // OBJECT MOVING RETICLE
281             // TYPE LINE
282             // ATTRIB - ON CONDITION
283             glBegin(GL_LINE_STRIP);
284             glVertex2f(vel_x, vel_y - 6);
285             glVertex2f(vel_x, vel_y - 10);
286             glEnd();
287         }
288
289         // OBJECT MOVING RETICLE
290         // TYPE V
291         // ATTRIB - ON CONDITION
292         if (ihook == 1) {
293             // arrestor hook status
294             glBegin(GL_LINE_STRIP);
295             glVertex2f(vel_x - 4, vel_y - 8);
296             glVertex2f(vel_x, vel_y - 10);
297             glVertex2f(vel_x + 4, vel_y - 8);
298             glEnd();
299         }
300 #endif
301     } // if _velocity_vector
302
303
304     //***************************************************************
305     // OBJECT MOVING RETICLE
306     // TYPE - SQUARE_BRACKET
307     // ATTRIB - ON CONDITION
308     // alpha bracket
309 #ifdef ENABLE_SP_FMDS
310     if (_alpha_bracket && ihook == 1) {
311         glBegin(GL_LINE_STRIP);
312         glVertex2f(vel_x - 20 , vel_y - (16 - alpha) * _compression);
313         glVertex2f(vel_x - 17, vel_y - (16 - alpha) * _compression);
314         glVertex2f(vel_x - 17, vel_y - (14 - alpha) * _compression);
315         glVertex2f(vel_x - 20, vel_y - (14 - alpha) * _compression);
316         glEnd();
317
318         glBegin(GL_LINE_STRIP);
319         glVertex2f(vel_x + 20 , vel_y - (16 - alpha) * _compression);
320         glVertex2f(vel_x + 17, vel_y - (16 - alpha) * _compression);
321         glVertex2f(vel_x + 17, vel_y - (14 - alpha) * _compression);
322         glVertex2f(vel_x + 20, vel_y - (14 - alpha) * _compression);
323         glEnd();
324     }
325 #endif
326     //printf("xvr=%f, yvr=%f, Vx=%f, Vy=%f, Vz=%f\n",xvvr, yvvr, Vx, Vy, Vz);
327     //printf("Ax=%f, Ay=%f, Az=%f\n",Ax, Ay, Az);
328
329     //****************************************************************
330     // OBJECT MOVING RETICLE
331     // TYPE ENERGY_MARKERS
332     // ATTRIB - ALWAYS
333     //energy markers - compute potential slope
334     if (_energy_marker) {
335         if (total_vel < 5.0) {
336             t1 = 0;
337             t2 = 0;
338         } else {
339             t1 = up_vel / total_vel;
340             t2 = asin((Vxx * Axx + Vyy * Ayy + Vzz * Azz) / (9.81 * total_vel));
341         }
342         pot_slope = ((t2 / 3) * SGD_RADIANS_TO_DEGREES) * _compression + vel_y;
343         // if (pot_slope < (vel_y - 45)) pot_slope = vel_y - 45;
344         // if (pot_slope > (vel_y + 45)) pot_slope = vel_y + 45;
345
346         //energy markers
347         glBegin(GL_LINE_STRIP);
348         glVertex2f(vel_x - 20, pot_slope - 5);
349         glVertex2f(vel_x - 15, pot_slope);
350         glVertex2f(vel_x - 20, pot_slope + 5);
351         glEnd();
352
353         glBegin(GL_LINE_STRIP);
354         glVertex2f(vel_x + 20, pot_slope - 5);
355         glVertex2f(vel_x + 15, pot_slope);
356         glVertex2f(vel_x + 20, pot_slope + 5);
357         glEnd();
358
359         if (pla > (105.0 / 131.0)) {
360             glBegin(GL_LINE_STRIP);
361             glVertex2f(vel_x - 24, pot_slope - 5);
362             glVertex2f(vel_x - 19, pot_slope);
363             glVertex2f(vel_x - 24, pot_slope + 5);
364             glEnd();
365
366             glBegin(GL_LINE_STRIP);
367             glVertex2f(vel_x + 24, pot_slope - 5);
368             glVertex2f(vel_x + 19, pot_slope);
369             glVertex2f(vel_x + 24, pot_slope + 5);
370             glEnd();
371         }
372     }
373
374     //**********************************************************
375     // ramp reticle
376     // OBJECT STATIC RETICLE
377     // TYPE LINE
378     // ATTRIB - ON CONDITION
379 #ifdef ENABLE_SP_FMDS
380     if (_energy_worm && ilcanclaw == 1) {
381         glBegin(GL_LINE_STRIP);
382         glVertex2f(-15, -134);
383         glVertex2f(15, -134);
384         glEnd();
385
386         // OBJECT MOVING RETICLE
387         // TYPE BOX
388         // ATTRIB - ON CONDITION
389         glBegin(GL_LINE_STRIP);
390         glVertex2f(-6, -134);
391         glVertex2f(-6, t2 * SGD_RADIANS_TO_DEGREES * 4.0 - 134);
392         glVertex2f(+6, t2 * SGD_RADIANS_TO_DEGREES * 4.0 - 134);
393         glVertex2f(6, -134);
394         glEnd();
395
396         // OBJECT MOVING RETICLE
397         // TYPE DIAMOND
398         // ATTRIB - ON CONDITION
399         glBegin(GL_LINE_LOOP);
400         glVertex2f(-6, actslope * 4.0 - 134);
401         glVertex2f(0, actslope * 4.0 -134 + 3);
402         glVertex2f(6, actslope * 4.0 - 134);
403         glVertex2f(0, actslope * 4.0 -134 -3);
404         glEnd();
405     }
406 #endif
407
408     //*************************************************************
409     // OBJECT MOVING RETICLE
410     // TYPE DIAMOND
411     // ATTRIB - ALWAYS
412     // Draw the locked velocity vector.
413     if (_climb_dive_marker) {
414         glBegin(GL_LINE_LOOP);
415         glVertex2f(-3.0, 0.0 + vel_y);
416         glVertex2f(0.0, 6.0 + vel_y);
417         glVertex2f(3.0, 0.0 + vel_y);
418         glVertex2f(0.0, -6.0 + vel_y);
419         glEnd();
420     }
421
422     //****************************************************************
423
424     if (climb_dive_ladder) { // CONFORMAL_HUD
425         _vmin = pitch_value - _width_units;
426         _vmax = pitch_value + _width_units;
427         glTranslatef(vel_x, vel_y, 0);
428
429     } else { // pitch_ladder - Default Hud
430         _vmin = pitch_value - _width_units * 0.5f;
431         _vmax = pitch_value + _width_units * 0.5f;
432     }
433
434     glRotatef(roll_value * SGD_RADIANS_TO_DEGREES, 0.0, 0.0, 1.0);
435     // FRL marker not rotated - this line shifted below
436
437     if (div_units) {
438         const int BUFSIZE = 8;
439         char buf[BUFSIZE];
440         float label_length;
441         float label_height;
442         float left;
443         float right;
444         float bot;
445         float top;
446         float text_offset = 4.0f;
447         float zero_offset = 0.0;
448
449         if (climb_dive_ladder)
450             zero_offset = 50.0f; // horizon line is wider by this much (hard coded ??)
451         else
452             zero_offset = 10.0f;
453
454         fntFont *font = _hud->_font_renderer->getFont();                        // FIXME
455         float pointsize = _hud->_font_renderer->getPointSize();
456         float italic = _hud->_font_renderer->getSlant();
457
458         _locTextList.setFont(_hud->_font_renderer);
459         _locTextList.erase();
460         _locLineList.erase();
461         _locStippleLineList.erase();
462
463         int last = int(_vmax) + 1;
464         int i = int(_vmin);
465
466         if (!_scr_hole) {
467             x_end = half_span;
468
469             for (; i < last; i++) {
470                 y = (i - pitch_value) * _compression + .5f;
471
472                 if (!(i % div_units)) {           //  At integral multiple of div
473                     snprintf(buf, BUFSIZE, "%d", i);
474                     font->getBBox(buf, pointsize, italic, &left, &right, &bot, &top);
475                     label_length = right - left;
476                     label_length += text_offset;
477                     label_height = (top - bot) / 2.0f;
478
479                     x_ini = -half_span;
480
481                     if (i >= 0) {
482                         // Make zero point wider on left
483                         if (i == 0)
484                             x_ini -= zero_offset;
485
486                         // Zero or above draw solid lines
487                         draw_line(x_ini, y, x_end, y);
488
489                         if (i == 90 && _zenith == 1)
490                             draw_zenith(x_ini, x_end, y);
491                     } else {
492                         // Below zero draw dashed lines.
493                         draw_stipple_line(x_ini, y, x_end, y);
494
495                         if (i == -90 && _nadir ==1)
496                             draw_nadir(x_ini, x_end, y);
497                     }
498
499                     // Calculate the position of the left text and write it.
500                     draw_text(x_ini - label_length, y - label_height, buf);
501                     draw_text(x_end + text_offset, y - label_height, buf);
502                 }
503             }
504
505         } else { // if (_scr_hole)
506             // Draw ladder with space in the middle of the lines
507             float hole = _scr_hole / 2.0f;
508
509             x_end = -half_span + hole;
510             x_ini2 = half_span - hole;
511
512             for (; i < last; i++) {
513                 if (_type == PITCH)
514                     y = float(i - pitch_value) * _compression + .5;
515                 else // _type == CLIMB_DIVE
516                     y = float(i - actslope) * _compression + .5;
517
518                 if (!(i % div_units)) {  //  At integral multiple of div
519                     snprintf(buf, BUFSIZE, "%d", i);
520                     font->getBBox(buf, pointsize, italic, &left, &right, &bot, &top);
521                     label_length = right - left;
522                     label_length += text_offset;
523                     label_height = (top - bot) / 2.0f;
524                     // printf("l %f r %f b %f t %f\n",left, right, bot, top);
525
526                     // Start by calculating the points and drawing the
527                     // left side lines.
528                     x_ini = -half_span;
529                     x_end2 = half_span;
530
531                     if (i >= 0) {
532                         // Make zero point wider on left
533                         if (i == 0) {
534                             x_ini -= zero_offset;
535                             x_end2 += zero_offset;
536                         }
537                         //draw climb bar vertical lines
538                         if (climb_dive_ladder) {
539                             // Zero or above draw solid lines
540                             draw_line(x_end, y - 5.0, x_end, y);
541                             draw_line(x_ini2, y - 5.0, x_ini2, y);
542                         }
543                         // draw pitch / climb bar
544                         draw_line(x_ini, y, x_end, y);
545                         draw_line(x_ini2, y, x_end2, y);
546
547                         if (i == 90 && _zenith == 1)
548                             draw_zenith(x_ini2, x_end, y);
549
550                     } else { // i < 0
551                         // draw dive bar vertical lines
552                         if (climb_dive_ladder) {
553                             draw_line(x_end, y + 5.0, x_end, y);
554                             draw_line(x_ini2, y + 5.0, x_ini2, y);
555                         }
556
557                         // draw pitch / dive bars
558                         draw_stipple_line(x_ini, y, x_end, y);
559                         draw_stipple_line(x_ini2, y, x_end2, y);
560
561                         if (i == -90 && _nadir == 1)
562                             draw_nadir(x_ini2, x_end, y);
563                     }
564
565                     // Now calculate the location of the left side label using
566                     draw_text(x_ini - label_length, y - label_height, buf);
567                     draw_text(x_end2 + text_offset, y - label_height, buf);
568                 }
569             }
570
571             // OBJECT LADDER MARK
572             // TYPE LINE
573             // ATTRIB - ON CONDITION
574             // draw appraoch glide slope marker
575 #ifdef ENABLE_SP_FMDS
576             if (_glide_slope_marker && ihook) {
577                 draw_line(-half_span + 15, (_glide_slope - actslope) * _compression,
578                         -half_span + hole, (_glide_slope - actslope) * _compression);
579                 draw_line(half_span - 15, (_glide_slope - actslope) * _compression,
580                         half_span - hole, (_glide_slope - actslope) * _compression);
581             }
582 #endif
583         }
584         _locTextList.draw();
585
586         glLineWidth(0.2);
587
588         _locLineList.draw();
589
590         glEnable(GL_LINE_STIPPLE);
591         glLineStipple(1, 0x00FF);
592         _locStippleLineList.draw();
593         glDisable(GL_LINE_STIPPLE);
594     }
595     glDisable(GL_CLIP_PLANE0);
596     glDisable(GL_CLIP_PLANE1);
597     glDisable(GL_CLIP_PLANE2);
598     //  glDisable(GL_SCISSOR_TEST);
599     glPopMatrix();
600     //*************************************************************
601
602     //*************************************************************
603 #ifdef ENABLE_SP_FMDS
604     if (_waypoint_marker) {
605         //waypoint marker computation
606         float fromwp_lat, towp_lat, fromwp_lon, towp_lon, dist, delx, dely, hyp, theta, brg;
607
608         fromwp_lon = get__longitude() * SGD_DEGREES_TO_RADIANS;
609         fromwp_lat = get__latitude() * SGD_DEGREES_TO_RADIANS;
610         towp_lon = get__aux2() * SGD_DEGREES_TO_RADIANS;
611         towp_lat = get__aux1() * SGD_DEGREES_TO_RADIANS;
612
613         dist = acos(sin(fromwp_lat) * sin(towp_lat) + cos(fromwp_lat)
614                 * cos(towp_lat) * cos(fabs(fromwp_lon - towp_lon)));
615         delx= towp_lat - fromwp_lat;
616         dely = towp_lon - fromwp_lon;
617         hyp = sqrt(pow(delx, 2) + pow(dely, 2));
618
619         if (hyp != 0)
620             theta = asin(dely / hyp);
621         else
622             theta = 0.0;
623
624         brg = theta * SGD_RADIANS_TO_DEGREES;
625         if (brg > 360.0)
626             brg = 0.0;
627         if (delx < 0)
628             brg = 180 - brg;
629
630         // {Brg  = asin(cos(towp_lat)*sin(fabs(fromwp_lon-towp_lon))/ sin(dist));
631         // Brg = Brg * SGD_RADIANS_TO_DEGREES; }
632
633         dist *= SGD_RADIANS_TO_DEGREES * 60.0 * 1852.0; //rad->deg->nm->m
634         // end waypoint marker computation
635
636         //*********************************************************
637         // OBJECT MOVING RETICLE
638         // TYPE ARROW
639         // waypoint marker
640         if (fabs(brg-psi) > 10.0) {
641             glPushMatrix();
642             glTranslatef(centroid.x, centroid.y, 0);
643             glTranslatef(vel_x, vel_y, 0);
644             glRotatef(brg - psi, 0.0, 0.0, -1.0);
645             glBegin(GL_LINE_LOOP);
646             glVertex2f(-2.5, 20.0);
647             glVertex2f(-2.5, 30.0);
648             glVertex2f(-5.0, 30.0);
649             glVertex2f(0.0, 35.0);
650             glVertex2f(5.0, 30.0);
651             glVertex2f(2.5, 30.0);
652             glVertex2f(2.5, 20.0);
653             glEnd();
654             glPopMatrix();
655         }
656
657         // waypoint marker on heading scale
658         if (fabs(brg-psi) < 12.0) {
659             if (_hat == 0) {
660                 glBegin(GL_LINE_LOOP);
661                 glVertex2f(((brg - psi) * 60 / 25) + 320, 240.0);
662                 glVertex2f(((brg - psi) * 60 / 25) + 326, 240.0 - 4);
663                 glVertex2f(((brg - psi) * 60 / 25) + 323, 240.0 - 4);
664                 glVertex2f(((brg - psi) * 60 / 25) + 323, 240.0 - 8);
665                 glVertex2f(((brg - psi) * 60 / 25) + 317, 240.0 - 8);
666                 glVertex2f(((brg - psi) * 60 / 25) + 317, 240.0 - 4);
667                 glVertex2f(((brg - psi) * 60 / 25) + 314, 240.0 - 4);
668                 glEnd();
669
670             } else { //if _hat=0
671                 float x = (brg - psi) * 60 / 25 + 320, y = 240.0, r = 5.0;
672                 float x1, y1;
673
674                 glEnable(GL_POINT_SMOOTH);
675                 glBegin(GL_POINTS);
676
677                 for (int count = 0; count <= 200; count++) {
678                     float temp = count * SG_PI * 3 / (200.0 * 2.0);
679                     float temp1 = temp - (45.0 * SGD_DEGREES_TO_RADIANS);
680                     x1 = x + r * cos(temp1);
681                     y1 = y + r * sin(temp1);
682                     glVertex2f(x1, y1);
683                 }
684
685                 glEnd();
686                 glDisable(GL_POINT_SMOOTH);
687             } //_hat=0
688
689          } //brg<12
690      } // if _waypoint_marker
691 #endif
692 }//draw
693
694
695 /******************************************************************/
696 //  draws the zenith symbol  for highest possible climb angle (i.e. 90 degree climb angle)
697 //
698 void HUD::Ladder::draw_zenith(float xfirst, float xlast, float yvalue)
699 {
700     float xcentre = (xfirst + xlast) / 2.0;
701     float ycentre = yvalue;
702
703     draw_line(xcentre - 9.0, ycentre, xcentre - 3.0, ycentre + 1.3);
704     draw_line(xcentre - 9.0, ycentre, xcentre - 3.0, ycentre - 1.3);
705
706     draw_line(xcentre + 9.0, ycentre, xcentre + 3.0, ycentre + 1.3);
707     draw_line(xcentre + 9.0, ycentre, xcentre + 3.0, ycentre - 1.3);
708
709     draw_line(xcentre, ycentre + 9.0, xcentre - 1.3, ycentre + 3.0);
710     draw_line(xcentre, ycentre + 9.0, xcentre + 1.3, ycentre + 3.0);
711
712     draw_line(xcentre - 3.9, ycentre + 3.9, xcentre - 3.0, ycentre + 1.3);
713     draw_line(xcentre - 3.9, ycentre + 3.9, xcentre - 1.3, ycentre + 3.0);
714
715     draw_line(xcentre + 3.9, ycentre + 3.9, xcentre + 1.3, ycentre+3.0);
716     draw_line(xcentre + 3.9, ycentre + 3.9, xcentre + 3.0, ycentre+1.3);
717
718     draw_line(xcentre - 3.9, ycentre - 3.9, xcentre - 3.0, ycentre-1.3);
719     draw_line(xcentre - 3.9, ycentre - 3.9, xcentre - 1.3, ycentre-2.6);
720
721     draw_line(xcentre + 3.9, ycentre - 3.9, xcentre + 3.0, ycentre-1.3);
722     draw_line(xcentre + 3.9, ycentre - 3.9, xcentre + 1.3, ycentre-2.6);
723
724     draw_line(xcentre - 1.3, ycentre - 2.6, xcentre, ycentre - 27.0);
725     draw_line(xcentre + 1.3, ycentre - 2.6, xcentre, ycentre - 27.0);
726 }
727
728
729 //  draws the nadir symbol  for lowest possible dive angle (i.e. 90 degree dive angle)
730 //
731 void HUD::Ladder::draw_nadir(float xfirst, float xlast, float yvalue)
732 {
733     float xcentre = (xfirst + xlast) / 2.0;
734     float ycentre = yvalue;
735
736     float r = 7.5;
737     float x1, y1, x2, y2;
738
739     // to draw a circle
740     float xcent1, xcent2, ycent1, ycent2;
741     xcent1 = xcentre + r;
742     ycent1 = ycentre;
743
744     for (int count = 1; count <= 400; count++) {
745         float temp = count * 2 * SG_PI / 400.0;
746         xcent2 = xcentre + r * cos(temp);
747         ycent2 = ycentre + r * sin(temp);
748
749         draw_line(xcent1, ycent1, xcent2, ycent2);
750
751         xcent1 = xcent2;
752         ycent1 = ycent2;
753     }
754
755     xcent2 = xcentre + r;
756     ycent2 = ycentre;
757
758     Item::draw_line(xcent1, ycent1, xcent2, ycent2); //to connect last point to first point
759     //end circle
760
761     //to draw a line above the circle
762     draw_line(xcentre, ycentre + 7.5, xcentre, ycentre + 22.5);
763
764     //line in the middle of circle
765     draw_line(xcentre - 7.5, ycentre, xcentre + 7.5, ycentre);
766
767     float theta = asin(2.5 / 7.5);
768     float theta1 = asin(5.0 / 7.5);
769
770     x1 = xcentre + r * cos(theta);
771     y1 = ycentre + 2.5;
772     x2 = xcentre + r * cos((180.0 * SGD_DEGREES_TO_RADIANS) - theta);
773     y2 = ycentre + 2.5;
774     draw_line(x1, y1, x2, y2);
775
776     x1 = xcentre + r * cos(theta1);
777     y1 = ycentre + 5.0;
778     x2 = xcentre + r * cos((180.0 * SGD_DEGREES_TO_RADIANS) - theta1);
779     y2 = ycentre + 5.0;
780     draw_line(x1, y1, x2, y2);
781
782     x1 = xcentre + r * cos((180.0 * SGD_DEGREES_TO_RADIANS) + theta);
783     y1 = ycentre - 2.5;
784     x2 = xcentre + r * cos((360.0 * SGD_DEGREES_TO_RADIANS) - theta);
785     y2 = ycentre - 2.5;
786     draw_line(x1, y1, x2, y2);
787
788     x1 = xcentre + r * cos((180.0 * SGD_DEGREES_TO_RADIANS) + theta1);
789     y1 = ycentre - 5.0;
790     x2 = xcentre + r * cos((360.0 * SGD_DEGREES_TO_RADIANS) - theta1);
791     y2 = ycentre - 5.0;
792     draw_line(x1, y1, x2, y2);
793 }
794
795