]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD_ladder.cxx
Make HUD items private to the subsystem.
[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 / globals->get_current_view()->get_aspect_ratio()));
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 / globals->get_current_view()->get_aspect_ratio());
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 == "aircraft" || name == "multiplayer") {
278                 string callsign = chld->getStringValue("callsign");
279                 if (callsign != "") {
280                     float h_deg = chld->getFloatValue("radar/h-offset");
281                     float v_deg = chld->getFloatValue("radar/v-offset");
282                     float pos_x = (h_deg * cos(roll_value) -
283                                    v_deg * sin(roll_value)) * _compression;
284                     float pos_y = (v_deg * cos(roll_value) +
285                                    h_deg * sin(roll_value)) * _compression;
286                     draw_circle(pos_x, pos_y, 8);
287                 }
288             }
289         }
290     }
291
292     //***************************************************************
293     // OBJECT MOVING RETICLE
294     // TYPE - SQUARE_BRACKET
295     // ATTRIB - ON CONDITION
296     // alpha bracket
297 #ifdef ENABLE_SP_FDM
298     alpha = get__alpha();
299
300     if (_alpha_bracket && ihook == 1) {
301         glBegin(GL_LINE_STRIP);
302         glVertex2f(vel_x - 20, vel_y - (16 - alpha) * _compression);
303         glVertex2f(vel_x - 17, vel_y - (16 - alpha) * _compression);
304         glVertex2f(vel_x - 17, vel_y - (14 - alpha) * _compression);
305         glVertex2f(vel_x - 20, vel_y - (14 - alpha) * _compression);
306         glEnd();
307
308         glBegin(GL_LINE_STRIP);
309         glVertex2f(vel_x + 20, vel_y - (16 - alpha) * _compression);
310         glVertex2f(vel_x + 17, vel_y - (16 - alpha) * _compression);
311         glVertex2f(vel_x + 17, vel_y - (14 - alpha) * _compression);
312         glVertex2f(vel_x + 20, vel_y - (14 - alpha) * _compression);
313         glEnd();
314     }
315 #endif
316     //printf("xvr=%f, yvr=%f, Vx=%f, Vy=%f, Vz=%f\n",xvvr, yvvr, Vx, Vy, Vz);
317     //printf("Ax=%f, Ay=%f, Az=%f\n",Ax, Ay, Az);
318
319     //****************************************************************
320     // OBJECT MOVING RETICLE
321     // TYPE ENERGY_MARKERS
322     // ATTRIB - ALWAYS
323     //energy markers - compute potential slope
324     float pla = get__throttleval();
325     float t2 = 0.0;
326
327     if (_energy_marker) {
328         if (total_vel < 5.0) {
329 //            t1 = 0;
330             t2 = 0;
331         } else {
332 //            t1 = up_vel / total_vel;
333             t2 = asin((Vxx * Axx + Vyy * Ayy + Vzz * Azz) / (9.81 * total_vel));
334         }
335         pot_slope = ((t2 / 3) * SGD_RADIANS_TO_DEGREES) * _compression + vel_y;
336         // if (pot_slope < (vel_y - 45)) pot_slope = vel_y - 45;
337         // if (pot_slope > (vel_y + 45)) pot_slope = vel_y + 45;
338
339         //energy markers
340         glBegin(GL_LINE_STRIP);
341         glVertex2f(vel_x - 20, pot_slope - 5);
342         glVertex2f(vel_x - 15, pot_slope);
343         glVertex2f(vel_x - 20, pot_slope + 5);
344         glEnd();
345
346         glBegin(GL_LINE_STRIP);
347         glVertex2f(vel_x + 20, pot_slope - 5);
348         glVertex2f(vel_x + 15, pot_slope);
349         glVertex2f(vel_x + 20, pot_slope + 5);
350         glEnd();
351
352         if (pla > (105.0 / 131.0)) {
353             glBegin(GL_LINE_STRIP);
354             glVertex2f(vel_x - 24, pot_slope - 5);
355             glVertex2f(vel_x - 19, pot_slope);
356             glVertex2f(vel_x - 24, pot_slope + 5);
357             glEnd();
358
359             glBegin(GL_LINE_STRIP);
360             glVertex2f(vel_x + 24, pot_slope - 5);
361             glVertex2f(vel_x + 19, pot_slope);
362             glVertex2f(vel_x + 24, pot_slope + 5);
363             glEnd();
364         }
365     }
366
367     //**********************************************************
368     // ramp reticle
369     // OBJECT STATIC RETICLE
370     // TYPE LINE
371     // ATTRIB - ON CONDITION
372 #ifdef ENABLE_SP_FDM
373     int ilcanclaw = get__iaux2();
374
375     if (_energy_worm && ilcanclaw == 1) {
376         glBegin(GL_LINE_STRIP);
377         glVertex2f(-15, -134);
378         glVertex2f(15, -134);
379         glEnd();
380
381         // OBJECT MOVING RETICLE
382         // TYPE BOX
383         // ATTRIB - ON CONDITION
384         glBegin(GL_LINE_STRIP);
385         glVertex2f(-6, -134);
386         glVertex2f(-6, t2 * SGD_RADIANS_TO_DEGREES * 4.0 - 134);
387         glVertex2f(+6, t2 * SGD_RADIANS_TO_DEGREES * 4.0 - 134);
388         glVertex2f(6, -134);
389         glEnd();
390
391         // OBJECT MOVING RETICLE
392         // TYPE DIAMOND
393         // ATTRIB - ON CONDITION
394         glBegin(GL_LINE_LOOP);
395         glVertex2f(-6, actslope * 4.0 - 134);
396         glVertex2f(0, actslope * 4.0 -134 + 3);
397         glVertex2f(6, actslope * 4.0 - 134);
398         glVertex2f(0, actslope * 4.0 -134 -3);
399         glEnd();
400     }
401 #endif
402
403     //*************************************************************
404     // OBJECT MOVING RETICLE
405     // TYPE DIAMOND
406     // ATTRIB - ALWAYS
407     // Draw the locked velocity vector.
408     if (_climb_dive_marker) {
409         glBegin(GL_LINE_LOOP);
410         glVertex2f(-3.0, 0.0 + vel_y);
411         glVertex2f(0.0, 6.0 + vel_y);
412         glVertex2f(3.0, 0.0 + vel_y);
413         glVertex2f(0.0, -6.0 + vel_y);
414         glEnd();
415     }
416
417     //****************************************************************
418
419     _clip_box->set();
420
421     if (_dynamic_origin) {
422         // ladder moves with alpha/beta offset projected onto horizon
423         // line (so that the horizon line always aligns with the
424         // actual horizon.
425         _vmin = pitch_value - _width_units * 0.5f;
426         _vmax = pitch_value + _width_units * 0.5f;
427         {
428             // the hud ladder center point should move relative to alpha/beta
429             // however the horizon line should always stay on the horizon.  We
430             // project the alpha/beta offset onto the horizon line to get the
431             // result we want.
432             
433             SGVec3d d(cos(roll_value), sin(roll_value), 0.0);
434             SGRayd r(SGVec3d::zeros(), d);
435             SGVec3d p = r.getClosestPointTo(SGVec3d(vel_x, vel_y, 0.0));
436             glTranslatef(p[0], p[1], 0);
437         }
438     } else {
439         // ladder position is fixed relative to the center of the screen.
440         _vmin = pitch_value - _width_units * 0.5f;
441         _vmax = pitch_value + _width_units * 0.5f;
442     }
443
444     glRotatef(roll_value * SGD_RADIANS_TO_DEGREES, 0.0, 0.0, 1.0);
445
446     // FRL marker not rotated - this line shifted below
447     float half_span = _w * 0.5f;
448     float y = 0;
449     struct { float x, y; } lo, li, ri, ro, numoffs;  // left/right inner/outer
450
451     if (_div_units) {
452         _locTextList.setFont(_hud->_font_renderer);
453         _locTextList.erase();
454         _locLineList.erase();
455         _locStippleLineList.erase();
456
457         for (int i = int(_vmin); i < int(_vmax) + 1; i++) {
458             if (i % _div_units)
459                 continue;
460
461             if (_type == PITCH)
462                 y = float(i - pitch_value) * _compression + .5;
463             else  // _type == CLIMB_DIVE
464                 y = float(i - actslope) * _compression + .5;
465
466             // OBJECT LADDER MARK
467             // TYPE LINE
468             // ATTRIB - ON CONDITION
469             // draw approach glide slope marker
470 #ifdef ENABLE_SP_FDM
471             if (_glide_slope_marker && ihook) {
472                 draw_line(-half_span + 15, (_glide_slope - actslope) * _compression,
473                         -half_span + hole, (_glide_slope - actslope) * _compression);
474                 draw_line(half_span - 15, (_glide_slope - actslope) * _compression,
475                         half_span - hole, (_glide_slope - actslope) * _compression);
476             }
477 #endif
478
479             // draw symbols
480             if (i == 90 && _zenith)
481                 draw_zenith(0.0, y);
482             else if (i == -90 && _nadir)
483                 draw_nadir(0.0, y);
484
485             if ((_zenith && i > 85) || i > 90)
486                 continue;
487             if ((_nadir && i < -85) || i < -90)
488                 continue;
489
490             lo.x = -half_span;
491             ro.x = half_span;
492             li.x = ri.x = 0;
493             lo.y = ro.y = li.y = ri.y = y;
494             numoffs.x = 4;
495             numoffs.y = 0;
496
497             if (i == 0) {
498                 lo.x -= _zero_bar_overlength;
499                 ro.x += _zero_bar_overlength;
500             }
501
502             if (_scr_hole > 0.0f) {
503                 li.x = -_scr_hole;
504                 ri.x = _scr_hole;
505
506                 if (_dive_bar_angle && i < 0) {
507                     float alpha = i * SG_DEGREES_TO_RADIANS * 0.5;
508                     float xoffs = (ro.x - ri.x) * cos(alpha);
509                     float yoffs = (ro.x - ri.x) * sin(alpha);
510                     lo.x = li.x - xoffs;
511                     ro.x = ri.x + xoffs;
512                     lo.y = ro.y = li.y + yoffs;
513                     numoffs.x = 0;
514                     numoffs.y = 4 - yoffs * 0.3;
515                 }
516             }
517
518             // draw bars
519             if (_scr_hole) {
520                 draw_line(li.x, li.y, lo.x, lo.y, i < 0);
521                 draw_line(ri.x, ri.y, ro.x, ro.y, i < 0);
522             } else {
523                 draw_line(lo.x, lo.y, ro.x, ro.y, i < 0);
524             }
525
526             // draw ticks
527             if (_tick_length) {
528                 if (i < 0) {
529                     draw_line(li.x, li.y, li.x, li.y + _tick_length);
530                     draw_line(ri.x, ri.y, ri.x, ri.y + _tick_length);
531                 } else if (i > 0 || _zero_bar_overlength == 0) {
532                     if (_tick_length > 0) {
533                         numoffs.x = -0.3;
534                         numoffs.y = -0.3;
535                         draw_line(lo.x, lo.y, lo.x, lo.y - _tick_length);
536                         draw_line(ro.x, ro.y, ro.x, ro.y - _tick_length);
537                     } else {
538                         draw_line(li.x, li.y, li.x, li.y - _tick_length);
539                         draw_line(ri.x, ri.y, ri.x, ri.y - _tick_length);
540                     }
541                 }
542             }
543
544             // draw numbers
545             std::ostringstream str;
546             str << i;
547             // must keep this string, otherwise it will free the c_str!
548             string num_str = str.str();
549             const char *num = num_str.c_str();
550             int valign = numoffs.y > 0 ? BOTTOM : numoffs.y < 0 ? TOP : VCENTER;
551             draw_text(lo.x - numoffs.x, lo.y + numoffs.y, num,
552                     valign | (numoffs.x == 0 ? CENTER : numoffs.x > 0 ? RIGHT : LEFT));
553             draw_text(ro.x + numoffs.x, lo.y + numoffs.y, num,
554                     valign | (numoffs.x == 0 ? CENTER : numoffs.x > 0 ? LEFT : RIGHT));
555
556         }
557         _locTextList.draw();
558
559         glLineWidth(0.2);
560
561         _locLineList.draw();
562
563         glEnable(GL_LINE_STIPPLE);
564         glLineStipple(1, 0x00FF);
565         _locStippleLineList.draw();
566         glDisable(GL_LINE_STIPPLE);
567     }
568     _clip_box->unset();
569     glPopMatrix();
570     //*************************************************************
571
572     //*************************************************************
573 #ifdef ENABLE_SP_FDM
574     if (_waypoint_marker) {
575         //waypoint marker computation
576         float fromwp_lat, towp_lat, fromwp_lon, towp_lon, dist, delx, dely, hyp, theta, brg;
577
578         fromwp_lon = get__longitude() * SGD_DEGREES_TO_RADIANS;
579         fromwp_lat = get__latitude() * SGD_DEGREES_TO_RADIANS;
580         towp_lon = get__aux2() * SGD_DEGREES_TO_RADIANS;
581         towp_lat = get__aux1() * SGD_DEGREES_TO_RADIANS;
582
583         dist = acos(sin(fromwp_lat) * sin(towp_lat) + cos(fromwp_lat)
584                 * cos(towp_lat) * cos(fabs(fromwp_lon - towp_lon)));
585         delx= towp_lat - fromwp_lat;
586         dely = towp_lon - fromwp_lon;
587         hyp = sqrt(pow(delx, 2) + pow(dely, 2));
588
589         if (hyp != 0)
590             theta = asin(dely / hyp);
591         else
592             theta = 0.0;
593
594         brg = theta * SGD_RADIANS_TO_DEGREES;
595         if (brg > 360.0)
596             brg = 0.0;
597         if (delx < 0)
598             brg = 180 - brg;
599
600         // {Brg  = asin(cos(towp_lat)*sin(fabs(fromwp_lon-towp_lon))/ sin(dist));
601         // Brg = Brg * SGD_RADIANS_TO_DEGREES; }
602
603         dist *= SGD_RADIANS_TO_DEGREES * 60.0 * 1852.0; //rad->deg->nm->m
604         // end waypoint marker computation
605
606         //*********************************************************
607         // OBJECT MOVING RETICLE
608         // TYPE ARROW
609         // waypoint marker
610         if (fabs(brg - psi) > 10.0) {
611             glPushMatrix();
612             glTranslatef(_center_x, _center_y, 0);
613             glTranslatef(vel_x, vel_y, 0);
614             glRotatef(brg - psi, 0.0, 0.0, -1.0);
615             glBegin(GL_LINE_LOOP);
616             glVertex2f(-2.5, 20.0);
617             glVertex2f(-2.5, 30.0);
618             glVertex2f(-5.0, 30.0);
619             glVertex2f(0.0, 35.0);
620             glVertex2f(5.0, 30.0);
621             glVertex2f(2.5, 30.0);
622             glVertex2f(2.5, 20.0);
623             glEnd();
624             glPopMatrix();
625         }
626
627         // waypoint marker on heading scale
628         if (fabs(brg - psi) < 12.0) {
629             if (!_hat) {
630                 glBegin(GL_LINE_LOOP);
631                 GLfloat x = (brg - psi) * 60 / 25;
632                 glVertex2f(x + 320, 240.0);
633                 glVertex2f(x + 326, 240.0 - 4);
634                 glVertex2f(x + 323, 240.0 - 4);
635                 glVertex2f(x + 323, 240.0 - 8);
636                 glVertex2f(x + 317, 240.0 - 8);
637                 glVertex2f(x + 317, 240.0 - 4);
638                 glVertex2f(x + 314, 240.0 - 4);
639                 glEnd();
640
641             } else { // if (_hat)
642                 float x = (brg - psi) * 60 / 25 + 320, y = 240.0, r = 5.0;
643                 float x1, y1;
644
645                 glEnable(GL_POINT_SMOOTH);
646                 glBegin(GL_POINTS);
647
648                 for (int count = 0; count <= 200; count++) {
649                     float temp = count * SG_PI * 3 / (200.0 * 2.0);
650                     float temp1 = temp - (45.0 * SGD_DEGREES_TO_RADIANS);
651                     x1 = x + r * cos(temp1);
652                     y1 = y + r * sin(temp1);
653                     glVertex2f(x1, y1);
654                 }
655
656                 glEnd();
657                 glDisable(GL_POINT_SMOOTH);
658             }
659
660          } //brg<12
661      } // if _waypoint_marker
662 #endif
663 }//draw
664
665
666 /******************************************************************/
667 //  draws the zenith symbol (highest possible climb angle i.e. 90 degree climb angle)
668 //
669 void HUD::Ladder::draw_zenith(float x, float y)
670 {
671     draw_line(x - 9.0, y, x - 3.0, y + 1.3);
672     draw_line(x - 9.0, y, x - 3.0, y - 1.3);
673
674     draw_line(x + 9.0, y, x + 3.0, y + 1.3);
675     draw_line(x + 9.0, y, x + 3.0, y - 1.3);
676
677     draw_line(x, y + 9.0, x - 1.3, y + 3.0);
678     draw_line(x, y + 9.0, x + 1.3, y + 3.0);
679
680     draw_line(x - 3.9, y + 3.9, x - 3.0, y + 1.3);
681     draw_line(x - 3.9, y + 3.9, x - 1.3, y + 3.0);
682
683     draw_line(x + 3.9, y + 3.9, x + 1.3, y + 3.0);
684     draw_line(x + 3.9, y + 3.9, x + 3.0, y + 1.3);
685
686     draw_line(x - 3.9, y - 3.9, x - 3.0, y - 1.3);
687     draw_line(x - 3.9, y - 3.9, x - 1.3, y - 2.6);
688
689     draw_line(x + 3.9, y - 3.9, x + 3.0, y - 1.3);
690     draw_line(x + 3.9, y - 3.9, x + 1.3, y - 2.6);
691
692     draw_line(x - 1.3, y - 2.6, x, y - 27.0);
693     draw_line(x + 1.3, y - 2.6, x, y - 27.0);
694 }
695
696
697 //  draws the nadir symbol (lowest possible dive angle i.e. 90 degree dive angle))
698 //
699 void HUD::Ladder::draw_nadir(float x, float y)
700 {
701     const float R = 7.5;
702
703     draw_circle(x, y, R);
704     draw_line(x, y + R, x, y + 22.5); // line above the circle
705     draw_line(x - R, y, x + R, y);    // line at middle of circle
706
707     float theta = asin(2.5 / R);
708     float theta1 = asin(5.0 / R);
709     float x1, y1, x2, y2;
710
711     x1 = x + R * cos(theta);
712     y1 = y + 2.5;
713     x2 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) - theta);
714     y2 = y + 2.5;
715     draw_line(x1, y1, x2, y2);
716
717     x1 = x + R * cos(theta1);
718     y1 = y + 5.0;
719     x2 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) - theta1);
720     y2 = y + 5.0;
721     draw_line(x1, y1, x2, y2);
722
723     x1 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) + theta);
724     y1 = y - 2.5;
725     x2 = x + R * cos((360.0 * SGD_DEGREES_TO_RADIANS) - theta);
726     y2 = y - 2.5;
727     draw_line(x1, y1, x2, y2);
728
729     x1 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) + theta1);
730     y1 = y - 5.0;
731     x2 = x + R * cos((360.0 * SGD_DEGREES_TO_RADIANS) - theta1);
732     y2 = y - 5.0;
733     draw_line(x1, y1, x2, y2);
734 }
735
736