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