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