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