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