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