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