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