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