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