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