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