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