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