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