]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD_ladder.cxx
- read x/y/width/height as floats
[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 <sstream>
27 #include <simgear/math/vector.hxx>
28 #include <Main/viewer.hxx>
29 #include "HUD.hxx"
30
31
32 // FIXME
33 float get__heading() { return fgGetFloat("/orientation/heading-deg") * M_PI / 180.0; }
34 float get__throttleval() { return fgGetFloat("/controls/engines/engine/throttle"); }
35 float get__Vx() { return fgGetFloat("/velocities/uBody-fps"); }
36 float get__Vy() { return fgGetFloat("/velocities/vBody-fps"); }
37 float get__Vz() { return fgGetFloat("/velocities/wBody-fps"); }
38 float get__Ax() { return fgGetFloat("/acclerations/pilot/x-accel-fps_sec"); }
39 float get__Ay() { return fgGetFloat("/acclerations/pilot/y-accel-fps_sec"); }
40 float get__Az() { return fgGetFloat("/acclerations/pilot/z-accel-fps_sec"); }
41 float get__alpha() { return fgGetFloat("/orientation/alpha-deg"); }
42 float get__beta() { return fgGetFloat("/orientation/side-slip-deg"); }
43 #undef ENABLE_SP_FDM
44
45
46 HUD::Ladder::Ladder(HUD *hud, const SGPropertyNode *n, float x, float y) :
47     Item(hud, n, x, y),
48     _pitch(n->getNode("pitch-input", false)),
49     _roll(n->getNode("roll-input", false)),
50     _width_units(int(n->getFloatValue("display-span"))),
51     _div_units(int(fabs(n->getFloatValue("divisions")))),
52     _scr_hole(fabsf(n->getFloatValue("screen-hole")) * 0.5f),
53     _zero_bar_overlength(n->getFloatValue("zero-bar-overlength", 10)),
54     _dive_bar_angle(n->getBoolValue("enable-dive-bar-angle")),
55     _tick_length(n->getFloatValue("tick-length")),
56     _compression(n->getFloatValue("compression-factor")),
57     _dynamic_origin(n->getBoolValue("enable-dynamic-origin")),
58     _clip_plane(n->getBoolValue("enable-clip-plane")),
59     _frl(n->getBoolValue("enable-fuselage-ref-line")),
60     _target_spot(n->getBoolValue("enable-target-spot")),
61     _target_markers(n->getBoolValue("enable-target-markers")),
62     _velocity_vector(n->getBoolValue("enable-velocity-vector")),
63     _drift_marker(n->getBoolValue("enable-drift-marker")),
64     _alpha_bracket(n->getBoolValue("enable-alpha-bracket")),
65     _energy_marker(n->getBoolValue("enable-energy-marker")),
66     _climb_dive_marker(n->getBoolValue("enable-climb-dive-marker")),
67     _glide_slope_marker(n->getBoolValue("enable-glide-slope-marker")),
68     _glide_slope(n->getFloatValue("glide-slope", -4.0)),
69     _energy_worm(n->getBoolValue("enable-energy-marker")),
70     _waypoint_marker(n->getBoolValue("enable-waypoint-marker")),
71     _zenith(n->getBoolValue("enable-zenith")),
72     _nadir(n->getBoolValue("enable-nadir")),
73     _hat(n->getBoolValue("enable-hat"))
74 {
75     const char *t = n->getStringValue("type");
76     _type = strcmp(t, "climb-dive") ? PITCH : CLIMB_DIVE;
77
78     if (!_width_units)
79         _width_units = 45;
80
81     _vmax = _width_units / 2;
82     _vmin = -_vmax;
83 }
84
85
86 void HUD::Ladder::draw(void)
87 {
88     if (!_pitch.isValid() || !_roll.isValid())
89         return;
90
91     float roll_value = _roll.getFloatValue() * SGD_DEGREES_TO_RADIANS;
92     float pitch_value = _pitch.getFloatValue();
93
94     //**************************************************************
95     glPushMatrix();
96     glTranslatef(_center_x, _center_y, 0);
97
98     // OBJECT STATIC RETICLE
99     // TYPE FRL (FUSELAGE REFERENCE LINE)
100     // ATTRIB - ALWAYS
101     // Draw the FRL spot and line
102     if (_frl) {
103 #define FRL_DIAMOND_SIZE 2.0
104         glBegin(GL_LINE_LOOP);
105         glVertex2f(-FRL_DIAMOND_SIZE, 0.0);
106         glVertex2f(0.0, FRL_DIAMOND_SIZE);
107         glVertex2f(FRL_DIAMOND_SIZE, 0.0);
108         glVertex2f(0.0, -FRL_DIAMOND_SIZE);
109         glEnd();
110
111         glBegin(GL_LINE_STRIP);
112         glVertex2f(0, FRL_DIAMOND_SIZE);
113         glVertex2f(0, 8.0);
114         glEnd();
115 #undef FRL_DIAMOND_SIZE
116     }
117     // TYPE WATERLINE_MARK (W shaped _    _ )           // TODO (-> HUD_misc.cxx)
118     //                                \/\/
119
120     //****************************************************************
121     // TYPE TARGET_SPOT
122     // Draw the target spot.
123     if (_target_spot) {
124 #define CENTER_DIAMOND_SIZE 6.0
125         glBegin(GL_LINE_LOOP);
126         glVertex2f(-CENTER_DIAMOND_SIZE, 0.0);
127         glVertex2f(0.0, CENTER_DIAMOND_SIZE);
128         glVertex2f(CENTER_DIAMOND_SIZE, 0.0);
129         glVertex2f(0.0, -CENTER_DIAMOND_SIZE);
130         glEnd();
131 #undef CENTER_DIAMOND_SIZE
132     }
133
134     //****************************************************************
135     //velocity vector reticle - computations
136     float xvvr, /* yvvr, */ Vxx = 0.0, Vyy = 0.0, Vzz = 0.0;
137     float Axx = 0.0, Ayy = 0.0, Azz = 0.0, total_vel = 0.0, pot_slope, t1;
138     float up_vel, ground_vel, actslope = 0.0, psi = 0.0;
139     float vel_x = 0.0, vel_y = 0.0, drift;
140     float alpha;
141
142     if (_velocity_vector) {
143         drift = get__beta();
144         alpha = get__alpha();
145
146         Vxx = get__Vx();
147         Vyy = get__Vy();
148         Vzz = get__Vz();
149         Axx = get__Ax();
150         Ayy = get__Ay();
151         Azz = get__Az();
152         psi = get__heading();
153
154         if (psi > 180.0)
155             psi = psi - 360;
156
157         total_vel = sqrt(Vxx * Vxx + Vyy * Vyy + Vzz * Vzz);
158         ground_vel = sqrt(Vxx * Vxx + Vyy * Vyy);
159         up_vel = Vzz;
160
161         if (ground_vel < 2.0) {
162             if (fabs(up_vel) < 2.0)
163                 actslope = 0.0;
164             else
165                 actslope = (up_vel / fabs(up_vel)) * 90.0;
166
167         } else {
168             actslope = atan(up_vel / ground_vel) * SGD_RADIANS_TO_DEGREES;
169         }
170
171         xvvr = (-drift * (_compression / globals->get_current_view()->get_aspect_ratio()));
172         // drift = ((atan2(Vyy, Vxx) * SGD_RADIANS_TO_DEGREES) - psi);
173         // yvvr = (-alpha * _compression);
174         // vel_y = (-alpha * cos(roll_value) + drift * sin(roll_value)) * _compression;
175         // vel_x = (alpha * sin(roll_value) + drift * cos(roll_value))
176         //         * (_compression / globals->get_current_view()->get_aspect_ratio());
177         vel_y = -alpha * _compression;
178         vel_x = -drift * (_compression / globals->get_current_view()->get_aspect_ratio());
179         //  printf("%f %f %f %f\n",vel_x, vel_y, drift, psi);
180
181         //****************************************************************
182         // OBJECT MOVING RETICLE
183         // TYPE - DRIFT MARKER
184         // ATTRIB - ALWAYS
185         // drift marker
186         if (_drift_marker) {
187             glBegin(GL_LINE_STRIP);
188             glVertex2f((xvvr * 25 / 120) - 6, -4);
189             glVertex2f(xvvr * 25 / 120, 8);
190             glVertex2f((xvvr * 25 / 120) + 6, -4);
191             glEnd();
192         }
193
194         //****************************************************************
195         // Clipping coordinates for ladder to be input from xml file
196         // Clip hud ladder.  FIXME, these should be configurable, but they
197         // have always been hardcoded here.
198         if (_clip_plane) {
199             GLdouble eqn_top[4] = {0.0, -1.0, 0.0, 0.0};
200             GLdouble eqn_left[4] = {-1.0, 0.0, 0.0, 100.0};
201             GLdouble eqn_right[4] = {1.0, 0.0, 0.0, 100.0};
202
203             glClipPlane(GL_CLIP_PLANE0, eqn_top);
204             glEnable(GL_CLIP_PLANE0);
205             glClipPlane(GL_CLIP_PLANE1, eqn_left);
206             glEnable(GL_CLIP_PLANE1);
207             glClipPlane(GL_CLIP_PLANE2, eqn_right);
208             glEnable(GL_CLIP_PLANE2);
209         }
210
211         //****************************************************************
212         // OBJECT MOVING RETICLE
213         // TYPE VELOCITY VECTOR
214         // ATTRIB - ALWAYS
215         // velocity vector
216         draw_circle(vel_x, vel_y, 6);
217
218         //velocity vector reticle orientation lines
219         glBegin(GL_LINE_STRIP);
220         glVertex2f(vel_x - 12, vel_y);
221         glVertex2f(vel_x - 6, vel_y);
222         glEnd();
223         glBegin(GL_LINE_STRIP);
224         glVertex2f(vel_x + 12, vel_y);
225         glVertex2f(vel_x + 6, vel_y);
226         glEnd();
227         glBegin(GL_LINE_STRIP);
228         glVertex2f(vel_x, vel_y + 12);
229         glVertex2f(vel_x, vel_y + 6);
230         glEnd();
231
232 #ifdef ENABLE_SP_FDM
233         int lgear = get__iaux3();
234         int ihook = get__iaux6();
235
236         // OBJECT MOVING RETICLE
237         // TYPE LINE
238         // ATTRIB - ON CONDITION
239         if (lgear == 1) {
240             // undercarriage status
241             glBegin(GL_LINE_STRIP);
242             glVertex2f(vel_x + 8, vel_y);
243             glVertex2f(vel_x + 8, vel_y - 4);
244             glEnd();
245
246             // OBJECT MOVING RETICLE
247             // TYPE LINE
248             // ATTRIB - ON CONDITION
249             glBegin(GL_LINE_STRIP);
250             glVertex2f(vel_x - 8, vel_y);
251             glVertex2f(vel_x - 8, vel_y - 4);
252             glEnd();
253
254             // OBJECT MOVING RETICLE
255             // TYPE LINE
256             // ATTRIB - ON CONDITION
257             glBegin(GL_LINE_STRIP);
258             glVertex2f(vel_x, vel_y - 6);
259             glVertex2f(vel_x, vel_y - 10);
260             glEnd();
261         }
262
263         // OBJECT MOVING RETICLE
264         // TYPE V
265         // ATTRIB - ON CONDITION
266         if (ihook == 1) {
267             // arrestor hook status
268             glBegin(GL_LINE_STRIP);
269             glVertex2f(vel_x - 4, vel_y - 8);
270             glVertex2f(vel_x, vel_y - 10);
271             glVertex2f(vel_x + 4, vel_y - 8);
272             glEnd();
273         }
274 #endif
275     } // if _velocity_vector
276
277     // draw hud markers on top of each AI/MP target
278     if (_target_markers) {
279         SGPropertyNode *models = globals->get_props()->getNode("/ai/models", true);
280         for (int i = 0; i < models->nChildren(); i++) {
281             SGPropertyNode *chld = models->getChild(i);
282             string name;
283             name = chld->getName();
284             if (name == "aircraft" || name == "multiplayer") {
285                 string callsign = chld->getStringValue("callsign");
286                 if (callsign != "") {
287                     float h_deg = chld->getFloatValue("radar/h-offset");
288                     float v_deg = chld->getFloatValue("radar/v-offset");
289                     float pos_x = (h_deg * cos(roll_value) -
290                                    v_deg * sin(roll_value)) * _compression;
291                     float pos_y = (v_deg * cos(roll_value) +
292                                    h_deg * sin(roll_value)) * _compression;
293                     draw_circle(pos_x, pos_y, 8);
294                 }
295             }
296         }
297     }
298
299     //***************************************************************
300     // OBJECT MOVING RETICLE
301     // TYPE - SQUARE_BRACKET
302     // ATTRIB - ON CONDITION
303     // alpha bracket
304 #ifdef ENABLE_SP_FDM
305     alpha = get__alpha();
306
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     float pla = get__throttleval();
332     float t2 = 0.0;
333
334     if (_energy_marker) {
335         if (total_vel < 5.0) {
336             t1 = 0;
337             t2 = 0;
338         } else {
339             t1 = up_vel / total_vel;
340             t2 = asin((Vxx * Axx + Vyy * Ayy + Vzz * Azz) / (9.81 * total_vel));
341         }
342         pot_slope = ((t2 / 3) * SGD_RADIANS_TO_DEGREES) * _compression + vel_y;
343         // if (pot_slope < (vel_y - 45)) pot_slope = vel_y - 45;
344         // if (pot_slope > (vel_y + 45)) pot_slope = vel_y + 45;
345
346         //energy markers
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         glBegin(GL_LINE_STRIP);
354         glVertex2f(vel_x + 20, pot_slope - 5);
355         glVertex2f(vel_x + 15, pot_slope);
356         glVertex2f(vel_x + 20, pot_slope + 5);
357         glEnd();
358
359         if (pla > (105.0 / 131.0)) {
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             glBegin(GL_LINE_STRIP);
367             glVertex2f(vel_x + 24, pot_slope - 5);
368             glVertex2f(vel_x + 19, pot_slope);
369             glVertex2f(vel_x + 24, pot_slope + 5);
370             glEnd();
371         }
372     }
373
374     //**********************************************************
375     // ramp reticle
376     // OBJECT STATIC RETICLE
377     // TYPE LINE
378     // ATTRIB - ON CONDITION
379 #ifdef ENABLE_SP_FDM
380     int ilcanclaw = get__iaux2();
381
382     if (_energy_worm && ilcanclaw == 1) {
383         glBegin(GL_LINE_STRIP);
384         glVertex2f(-15, -134);
385         glVertex2f(15, -134);
386         glEnd();
387
388         // OBJECT MOVING RETICLE
389         // TYPE BOX
390         // ATTRIB - ON CONDITION
391         glBegin(GL_LINE_STRIP);
392         glVertex2f(-6, -134);
393         glVertex2f(-6, t2 * SGD_RADIANS_TO_DEGREES * 4.0 - 134);
394         glVertex2f(+6, t2 * SGD_RADIANS_TO_DEGREES * 4.0 - 134);
395         glVertex2f(6, -134);
396         glEnd();
397
398         // OBJECT MOVING RETICLE
399         // TYPE DIAMOND
400         // ATTRIB - ON CONDITION
401         glBegin(GL_LINE_LOOP);
402         glVertex2f(-6, actslope * 4.0 - 134);
403         glVertex2f(0, actslope * 4.0 -134 + 3);
404         glVertex2f(6, actslope * 4.0 - 134);
405         glVertex2f(0, actslope * 4.0 -134 -3);
406         glEnd();
407     }
408 #endif
409
410     //*************************************************************
411     // OBJECT MOVING RETICLE
412     // TYPE DIAMOND
413     // ATTRIB - ALWAYS
414     // Draw the locked velocity vector.
415     if (_climb_dive_marker) {
416         glBegin(GL_LINE_LOOP);
417         glVertex2f(-3.0, 0.0 + vel_y);
418         glVertex2f(0.0, 6.0 + vel_y);
419         glVertex2f(3.0, 0.0 + vel_y);
420         glVertex2f(0.0, -6.0 + vel_y);
421         glEnd();
422     }
423
424     //****************************************************************
425
426     if (_dynamic_origin) {
427         // ladder moves with alpha/beta offset projected onto horizon
428         // line (so that the horizon line always aligns with the
429         // actual horizon.
430         _vmin = pitch_value - _width_units * 0.5f;
431         _vmax = pitch_value + _width_units * 0.5f;
432         {
433             // the hud ladder center point should move relative to alpha/beta
434             // however the horizon line should always stay on the horizon.  We
435             // project the alpha/beta offset onto the horizon line to get the
436             // result we want.
437             sgdVec3 p1; // result
438             sgdVec3 p; sgdSetVec3(p, vel_x, vel_y, 0.0);
439             sgdVec3 p0; sgdSetVec3(p0, 0.0, 0.0, 0.0);
440             sgdVec3 d; sgdSetVec3(d, cos(roll_value), sin(roll_value), 0.0);
441             sgdClosestPointToLine(p1, p, p0, d);
442             glTranslatef(p1[0], p1[1], 0);
443         }
444     } else {
445         // ladder position is fixed relative to the center of the screen.
446         _vmin = pitch_value - _width_units * 0.5f;
447         _vmax = pitch_value + _width_units * 0.5f;
448     }
449
450     glRotatef(roll_value * SGD_RADIANS_TO_DEGREES, 0.0, 0.0, 1.0);
451
452     // FRL marker not rotated - this line shifted below
453     float half_span = _w * 0.5f;
454     float y = 0;
455     struct { float x, y; } lo, li, ri, ro, numoffs;  // left/right inner/outer
456
457     if (_div_units) {
458         _locTextList.setFont(_hud->_font_renderer);
459         _locTextList.erase();
460         _locLineList.erase();
461         _locStippleLineList.erase();
462
463         for (int i = int(_vmin); i < int(_vmax) + 1; i++) {
464             if (i % _div_units)
465                 continue;
466
467             if (_type == PITCH)
468                 y = float(i - pitch_value) * _compression + .5;
469             else  // _type == CLIMB_DIVE
470                 y = float(i - actslope) * _compression + .5;
471
472             // draw symbols
473             if (i == 90 && _zenith)
474                 draw_zenith(0.0, y);
475
476             if (i == -90 && _nadir)
477                 draw_nadir(0.0, y);
478
479             // OBJECT LADDER MARK
480             // TYPE LINE
481             // ATTRIB - ON CONDITION
482             // draw appraoch glide slope marker
483 #ifdef ENABLE_SP_FDM
484             if (_glide_slope_marker && ihook) {
485                 draw_line(-half_span + 15, (_glide_slope - actslope) * _compression,
486                         -half_span + hole, (_glide_slope - actslope) * _compression);
487                 draw_line(half_span - 15, (_glide_slope - actslope) * _compression,
488                         half_span - hole, (_glide_slope - actslope) * _compression);
489             }
490 #endif
491
492             if (i > 85 || i < -85)
493                 continue;
494
495             lo.x = -half_span;
496             ro.x = half_span;
497             li.x = ri.x = 0;
498             lo.y = ro.y = li.y = ri.y = y;
499             numoffs.x = 4;
500             numoffs.y = 0;
501
502             if (i == 0) {
503                 lo.x -= _zero_bar_overlength;
504                 ro.x += _zero_bar_overlength;
505             }
506
507             if (_scr_hole > 0.0f) {
508                 li.x = -_scr_hole;
509                 ri.x = _scr_hole;
510
511                 if (_dive_bar_angle && i < 0) {
512                     float alpha = i * SG_DEGREES_TO_RADIANS * 0.5;
513                     float xoffs = (ro.x - ri.x) * cos(alpha);
514                     float yoffs = (ro.x - ri.x) * sin(alpha);
515                     lo.x = li.x - xoffs;
516                     ro.x = ri.x + xoffs;
517                     lo.y = ro.y = li.y + yoffs;
518                     numoffs.x = 0;
519                     numoffs.y = 4 - yoffs * 0.3;
520                 }
521             }
522
523             // draw bars
524             if (_scr_hole) {
525                 draw_line(li.x, li.y, lo.x, lo.y, i < 0);
526                 draw_line(ri.x, ri.y, ro.x, ro.y, i < 0);
527             } else {
528                 draw_line(lo.x, lo.y, ro.x, ro.y, i < 0);
529             }
530
531             // draw ticks
532             if (_tick_length) {
533                 if (i < 0) {
534                     draw_line(li.x, li.y, li.x, li.y + _tick_length);
535                     draw_line(ri.x, ri.y, ri.x, ri.y + _tick_length);
536                 } else if (i > 0 || _zero_bar_overlength == 0) {
537                     if (_tick_length > 0) {
538                         numoffs.x = -0.3;
539                         numoffs.y = -0.3;
540                         draw_line(lo.x, lo.y, lo.x, lo.y - _tick_length);
541                         draw_line(ro.x, ro.y, ro.x, ro.y - _tick_length);
542                     } else {
543                         draw_line(li.x, li.y, li.x, li.y - _tick_length);
544                         draw_line(ri.x, ri.y, ri.x, ri.y - _tick_length);
545                     }
546                 }
547             }
548
549             // draw numbers
550             std::ostringstream str;
551             str << i;
552             const char *num = str.str().c_str();
553             int valign = numoffs.y > 0 ? BOTTOM : numoffs.y < 0 ? TOP : VCENTER;
554             draw_text(lo.x - numoffs.x, lo.y + numoffs.y, num,
555                     valign | (numoffs.x == 0 ? CENTER : numoffs.x > 0 ? RIGHT : LEFT));
556             draw_text(ro.x + numoffs.x, lo.y + numoffs.y, num,
557                     valign | (numoffs.x == 0 ? CENTER : numoffs.x > 0 ? LEFT : RIGHT));
558
559         }
560         _locTextList.draw();
561
562         glLineWidth(0.2);
563
564         _locLineList.draw();
565
566         glEnable(GL_LINE_STIPPLE);
567         glLineStipple(1, 0x00FF);
568         _locStippleLineList.draw();
569         glDisable(GL_LINE_STIPPLE);
570     }
571     glDisable(GL_CLIP_PLANE0);
572     glDisable(GL_CLIP_PLANE1);
573     glDisable(GL_CLIP_PLANE2);
574     glPopMatrix();
575     //*************************************************************
576
577     //*************************************************************
578 #ifdef ENABLE_SP_FDM
579     if (_waypoint_marker) {
580         //waypoint marker computation
581         float fromwp_lat, towp_lat, fromwp_lon, towp_lon, dist, delx, dely, hyp, theta, brg;
582
583         fromwp_lon = get__longitude() * SGD_DEGREES_TO_RADIANS;
584         fromwp_lat = get__latitude() * SGD_DEGREES_TO_RADIANS;
585         towp_lon = get__aux2() * SGD_DEGREES_TO_RADIANS;
586         towp_lat = get__aux1() * SGD_DEGREES_TO_RADIANS;
587
588         dist = acos(sin(fromwp_lat) * sin(towp_lat) + cos(fromwp_lat)
589                 * cos(towp_lat) * cos(fabs(fromwp_lon - towp_lon)));
590         delx= towp_lat - fromwp_lat;
591         dely = towp_lon - fromwp_lon;
592         hyp = sqrt(pow(delx, 2) + pow(dely, 2));
593
594         if (hyp != 0)
595             theta = asin(dely / hyp);
596         else
597             theta = 0.0;
598
599         brg = theta * SGD_RADIANS_TO_DEGREES;
600         if (brg > 360.0)
601             brg = 0.0;
602         if (delx < 0)
603             brg = 180 - brg;
604
605         // {Brg  = asin(cos(towp_lat)*sin(fabs(fromwp_lon-towp_lon))/ sin(dist));
606         // Brg = Brg * SGD_RADIANS_TO_DEGREES; }
607
608         dist *= SGD_RADIANS_TO_DEGREES * 60.0 * 1852.0; //rad->deg->nm->m
609         // end waypoint marker computation
610
611         //*********************************************************
612         // OBJECT MOVING RETICLE
613         // TYPE ARROW
614         // waypoint marker
615         if (fabs(brg - psi) > 10.0) {
616             glPushMatrix();
617             glTranslatef(_center_x, _center_y, 0);
618             glTranslatef(vel_x, vel_y, 0);
619             glRotatef(brg - psi, 0.0, 0.0, -1.0);
620             glBegin(GL_LINE_LOOP);
621             glVertex2f(-2.5, 20.0);
622             glVertex2f(-2.5, 30.0);
623             glVertex2f(-5.0, 30.0);
624             glVertex2f(0.0, 35.0);
625             glVertex2f(5.0, 30.0);
626             glVertex2f(2.5, 30.0);
627             glVertex2f(2.5, 20.0);
628             glEnd();
629             glPopMatrix();
630         }
631
632         // waypoint marker on heading scale
633         if (fabs(brg - psi) < 12.0) {
634             if (!_hat) {
635                 glBegin(GL_LINE_LOOP);
636                 GLfloat x = (brg - psi) * 60 / 25;
637                 glVertex2f(x + 320, 240.0);
638                 glVertex2f(x + 326, 240.0 - 4);
639                 glVertex2f(x + 323, 240.0 - 4);
640                 glVertex2f(x + 323, 240.0 - 8);
641                 glVertex2f(x + 317, 240.0 - 8);
642                 glVertex2f(x + 317, 240.0 - 4);
643                 glVertex2f(x + 314, 240.0 - 4);
644                 glEnd();
645
646             } else { // if (_hat)
647                 float x = (brg - psi) * 60 / 25 + 320, y = 240.0, r = 5.0;
648                 float x1, y1;
649
650                 glEnable(GL_POINT_SMOOTH);
651                 glBegin(GL_POINTS);
652
653                 for (int count = 0; count <= 200; count++) {
654                     float temp = count * SG_PI * 3 / (200.0 * 2.0);
655                     float temp1 = temp - (45.0 * SGD_DEGREES_TO_RADIANS);
656                     x1 = x + r * cos(temp1);
657                     y1 = y + r * sin(temp1);
658                     glVertex2f(x1, y1);
659                 }
660
661                 glEnd();
662                 glDisable(GL_POINT_SMOOTH);
663             }
664
665          } //brg<12
666      } // if _waypoint_marker
667 #endif
668 }//draw
669
670
671 /******************************************************************/
672 //  draws the zenith symbol (highest possible climb angle i.e. 90 degree climb angle)
673 //
674 void HUD::Ladder::draw_zenith(float x, float y)
675 {
676     draw_line(x - 9.0, y, x - 3.0, y + 1.3);
677     draw_line(x - 9.0, y, x - 3.0, y - 1.3);
678
679     draw_line(x + 9.0, y, x + 3.0, y + 1.3);
680     draw_line(x + 9.0, y, x + 3.0, y - 1.3);
681
682     draw_line(x, y + 9.0, x - 1.3, y + 3.0);
683     draw_line(x, y + 9.0, x + 1.3, y + 3.0);
684
685     draw_line(x - 3.9, y + 3.9, x - 3.0, y + 1.3);
686     draw_line(x - 3.9, y + 3.9, x - 1.3, y + 3.0);
687
688     draw_line(x + 3.9, y + 3.9, x + 1.3, y + 3.0);
689     draw_line(x + 3.9, y + 3.9, x + 3.0, y + 1.3);
690
691     draw_line(x - 3.9, y - 3.9, x - 3.0, y - 1.3);
692     draw_line(x - 3.9, y - 3.9, x - 1.3, y - 2.6);
693
694     draw_line(x + 3.9, y - 3.9, x + 3.0, y - 1.3);
695     draw_line(x + 3.9, y - 3.9, x + 1.3, y - 2.6);
696
697     draw_line(x - 1.3, y - 2.6, x, y - 27.0);
698     draw_line(x + 1.3, y - 2.6, x, y - 27.0);
699 }
700
701
702 //  draws the nadir symbol (lowest possible dive angle i.e. 90 degree dive angle))
703 //
704 void HUD::Ladder::draw_nadir(float x, float y)
705 {
706     const float R = 7.5;
707
708     draw_circle(x, y, R);
709     draw_line(x, y + R, x, y + 22.5); // line above the circle
710     draw_line(x - R, y, x + R, y);    // line at middle of circle
711
712     float theta = asin(2.5 / R);
713     float theta1 = asin(5.0 / R);
714     float x1, y1, x2, y2;
715
716     x1 = x + R * cos(theta);
717     y1 = y + 2.5;
718     x2 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) - theta);
719     y2 = y + 2.5;
720     draw_line(x1, y1, x2, y2);
721
722     x1 = x + R * cos(theta1);
723     y1 = y + 5.0;
724     x2 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) - theta1);
725     y2 = y + 5.0;
726     draw_line(x1, y1, x2, y2);
727
728     x1 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) + theta);
729     y1 = y - 2.5;
730     x2 = x + R * cos((360.0 * SGD_DEGREES_TO_RADIANS) - theta);
731     y2 = y - 2.5;
732     draw_line(x1, y1, x2, y2);
733
734     x1 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) + theta1);
735     y1 = y - 5.0;
736     x2 = x + R * cos((360.0 * SGD_DEGREES_TO_RADIANS) - theta1);
737     y2 = y - 5.0;
738     draw_line(x1, y1, x2, y2);
739 }
740
741