1 // hud.cxx -- hud defines and prototypes
3 // Written by Michele America, started September 1997.
5 // Copyright (C) 1997 Michele F. America - micheleamerica@geocities.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <simgear/compiler.h>
24 #include <simgear/structure/exception.hxx>
38 # define exception c_exception
44 #include <stdio.h> // char related functions
45 #include <string.h> // strcmp()
49 #include <simgear/constants.h>
50 #include <simgear/debug/logstream.hxx>
51 #include <simgear/props/props.hxx>
52 #include <simgear/misc/sg_path.hxx>
54 #include <Aircraft/aircraft.hxx>
55 #include <Autopilot/xmlauto.hxx>
56 #include <GUI/new_gui.hxx>
57 #include <Main/globals.hxx>
58 #include <Main/fg_props.hxx>
59 #include <Scenery/scenery.hxx>
61 #if defined (__sun) || defined ( __sgi )
63 extern void *memmove(void *, const void *, size_t);
70 static HUD_Properties *HUD;
74 // The following routines obtain information concerning the aircraft's
75 // current state and return it to calling instrument display routines.
76 // They should eventually be member functions of the aircraft.
79 deque< instr_item * > HUD_deque;
81 fgTextList HUD_TextList;
82 fgLineList HUD_LineList;
83 fgLineList HUD_StippleLineList;
85 fntRenderer *HUDtext = 0;
86 fntTexFont *HUD_Font = 0;
87 float HUD_TextSize = 0;
93 //$$$ begin - added, Neetha, 28 Nov 2k
101 static float span_units;
102 static float division_units;
103 static float minor_division = 0;
104 static UINT screen_hole;
107 static string loadfn;
109 static float maxValue;
110 static float minValue;
111 static float scaling;
112 static UINT major_divs;
113 static UINT minor_divs;
114 static UINT modulator;
115 static int dp_showing = 0;
116 static string label_format;
117 static string prelabel;
118 static string postlabel;
121 static float maxBankAngle;
122 static float maxSlipAngle;
123 static UINT gap_width;
124 static bool latitude;
125 static bool longitude;
126 static bool tick_bottom;
127 static bool tick_top;
128 static bool tick_right;
129 static bool tick_left;
130 static bool cap_bottom;
132 static bool cap_right;
133 static bool cap_left;
134 static float marker_off;
136 static bool enable_pointer;
137 static string type_pointer;
138 static bool frl_spot;
140 static bool vel_vector;
144 static bool climb_dive;
146 static float glide_slope_val;
147 static bool worm_energy;
148 static bool waypoint;
149 static string type_tick;//hud
150 static string length_tick;//hud
151 static bool label_box;//hud
152 static int digits; //suma
153 static float radius; //suma
154 static int divisions; //suma
155 static int zoom; //suma
156 static int zenith; //suma
157 static int nadir ; //suma
158 static int hat; //suma
159 static bool tsi; //suma
160 static float rad; //suma
163 static FLTFNPTR load_fn;
164 static fgLabelJust justification;
165 static const char *pre_label_string = 0;
166 static const char *post_label_string = 0;
168 int readHud( istream &input );
169 int readInstrument ( const SGPropertyNode * node);
170 static instr_item * readLadder ( const SGPropertyNode * node);
171 static instr_item * readCard ( const SGPropertyNode * node);
172 static instr_item * readLabel( const SGPropertyNode * node);
173 static instr_item * readTBI( const SGPropertyNode * node);
174 //$$$ end - added, Neetha, 28 Nov 2k
176 static void drawHUD();
177 static void fgUpdateHUDVirtual();
183 locRECT( UINT left, UINT top, UINT right, UINT bottom);
184 RECT get_rect(void) { return rect;}
187 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
192 rect.bottom = bottom;
197 //========================= End of Class Implementations===================
200 // Constructs a HUD object and then adds in instruments. At the present
201 // the instruments are hard coded into the routine. Ultimately these need
202 // to be defined by the aircraft's instrumentation records so that the
203 // display for a Piper Cub doesn't show the speed range of a North American
204 // mustange and the engine readouts of a B36!
209 //$$$ begin - added, Neetha, 28 Nov 2k
211 readLadder(const SGPropertyNode * node)
216 name = node->getStringValue("name");
217 x = node->getIntValue("x");
218 y = node->getIntValue("y");
219 width = node->getIntValue("width");
220 height = node->getIntValue("height");
221 factor = node->getFloatValue("compression_factor");
222 span_units = node->getFloatValue("span_units");
223 division_units = node->getFloatValue("division_units");
224 screen_hole = node->getIntValue("screen_hole");
225 lbl_pos = node->getIntValue("lbl_pos");
226 frl_spot = node->getBoolValue("enable_frl",false);
227 target = node->getBoolValue("enable_target_spot",false);
228 vel_vector = node->getBoolValue("enable_velocity_vector",false);
229 drift = node->getBoolValue("enable_drift_marker",false);
230 alpha = node->getBoolValue("enable_alpha_bracket",false);
231 energy = node->getBoolValue("enable_energy_marker",false);
232 climb_dive = node->getBoolValue("enable_climb_dive_marker",false);
233 glide = node->getBoolValue("enable_glide_slope_marker",false);
234 glide_slope_val = node->getFloatValue("glide_slope",-4.0);
235 worm_energy = node->getBoolValue("enable_energy_marker",false);
236 waypoint = node->getBoolValue("enable_waypoint_marker",false);
237 working = node->getBoolValue("working");
238 zenith = node->getIntValue("zenith"); //suma
239 nadir = node->getIntValue("nadir"); //suma
240 hat = node->getIntValue("hat");
241 // The factor assumes a base of 55 degrees per 640 pixels.
242 // Invert to convert the "compression" factor to a
243 // pixels-per-degree number.
244 if(fgGetBool("/sim/hud/enable3d", true))
249 factor = (640./55.) / factor;
253 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
255 p = (instr_item *) new HudLadder( name, x, y,
256 width, height, factor,
258 span_units, division_units, minor_division,
259 screen_hole, lbl_pos, frl_spot, target, vel_vector,
260 drift, alpha, energy, climb_dive,
261 glide, glide_slope_val, worm_energy,
262 waypoint, working, zenith, nadir, hat);
269 readCard(const SGPropertyNode * node)
274 name = node->getStringValue("name");
275 x = node->getIntValue("x");
276 y = node->getIntValue("y");
277 width = node->getIntValue("width");
278 height = node->getIntValue("height");
279 loadfn = node->getStringValue("loadfn");
280 options = node->getIntValue("options");
281 maxValue = node->getFloatValue("maxValue");
282 minValue = node->getFloatValue("minValue");
283 scaling = node->getFloatValue("disp_scaling");
284 major_divs = node->getIntValue("major_divs");
285 minor_divs = node->getIntValue("minor_divs");
286 modulator = node->getIntValue("modulator");
287 span_units = node->getFloatValue("value_span");
288 type = node->getStringValue("type");
289 tick_bottom = node->getBoolValue("tick_bottom",false);
290 tick_top = node->getBoolValue("tick_top",false);
291 tick_right = node->getBoolValue("tick_right",false);
292 tick_left = node->getBoolValue("tick_left",false);
293 cap_bottom = node->getBoolValue("cap_bottom",false);
294 cap_top = node->getBoolValue("cap_top",false);
295 cap_right = node->getBoolValue("cap_right",false);
296 cap_left = node->getBoolValue("cap_left",false);
297 marker_off = node->getFloatValue("marker_offset",0.0);
298 enable_pointer = node->getBoolValue("enable_pointer",true);
299 type_pointer = node->getStringValue("pointer_type");
300 type_tick = node->getStringValue("tick_type");//hud Can be 'circle' or 'line'
301 length_tick = node->getStringValue("tick_length");//hud For variable length
302 working = node->getBoolValue("working");
303 radius = node->getFloatValue("radius"); //suma
304 divisions = node->getIntValue("divisions"); //suma
305 zoom = node->getIntValue("zoom"); //suma
307 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
311 span_units = maxValue - minValue;
314 if (loadfn=="anzg") {
316 } else if (loadfn=="heading") {
317 load_fn = get_heading;
318 } else if (loadfn=="aoa") {
320 } else if (loadfn=="climb") {
321 load_fn = get_climb_rate;
322 } else if (loadfn=="altitude") {
323 load_fn = get_altitude;
324 } else if (loadfn=="agl") {
326 } else if (loadfn=="speed") {
328 } else if (loadfn=="view_direction") {
329 load_fn = get_view_direction;
330 } else if (loadfn=="aileronval") {
331 load_fn = get_aileronval;
332 } else if (loadfn=="elevatorval") {
333 load_fn = get_elevatorval;
334 } else if (loadfn=="elevatortrimval") {
335 load_fn = get_elev_trimval;
336 } else if (loadfn=="rudderval") {
337 load_fn = get_rudderval;
338 } else if (loadfn=="throttleval") {
339 load_fn = get_throttleval;
343 if ( (type == "dial") | (type == "tape") ) {
344 p = (instr_item *) new hud_card( x,
352 major_divs, minor_divs,
376 p = (instr_item *) new gauge_instr( x, // x
380 load_fn, // data source
384 major_divs, minor_divs,
394 readLabel(const SGPropertyNode * node)
398 int font_size = (fgGetInt("/sim/startup/xsize") > 1000) ? HUD_FONT_LARGE : HUD_FONT_SMALL;
400 name = node->getStringValue("name");
401 x = node->getIntValue("x");
402 y = node->getIntValue("y");
403 width = node->getIntValue("width");
404 height = node->getIntValue("height");
405 loadfn = node->getStringValue("data_source");
406 label_format = node->getStringValue("label_format");
407 prelabel = node->getStringValue("pre_label_string");
408 postlabel = node->getStringValue("post_label_string");
409 scaling = node->getFloatValue("scale_data");
410 options = node->getIntValue("options");
411 justi = node->getIntValue("justification");
412 blinking = node->getIntValue("blinking");
413 latitude = node->getBoolValue("latitude",false);
414 longitude = node->getBoolValue("longitude",false);
415 label_box = node->getBoolValue("label_box",false);//hud
416 working = node->getBoolValue("working");
417 digits = node->getIntValue("digits"); //suma
420 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
424 justification = LEFT_JUST;
427 justification = CENTER_JUST;
430 justification = RIGHT_JUST;
435 if ( prelabel == "NULL" ) {
436 pre_label_string = NULL;
438 if ( prelabel == "blank" ) {
439 pre_label_string = " ";
441 pre_label_string = prelabel.c_str();
445 if ( postlabel == "blank" ) {
446 post_label_string = " ";
448 if ( postlabel == "NULL" ) {
449 post_label_string = NULL;
451 if ( postlabel == "units" ) {
452 post_label_string = units;
454 post_label_string = postlabel.c_str();
459 #ifdef ENABLE_SP_FMDS
460 if ( loadfn== "aux1" ) {
462 } else if ( loadfn == "aux2" ) {
464 } else if ( loadfn == "aux3" ) {
466 } else if ( loadfn == "aux4" ) {
468 } else if ( loadfn == "aux5" ) {
470 } else if ( loadfn == "aux6" ) {
472 } else if ( loadfn == "aux7" ) {
474 } else if ( loadfn == "aux8" ) {
476 } else if ( loadfn == "aux9" ) {
478 } else if ( loadfn == "aux10" ) {
480 } else if ( loadfn == "aux11" ) {
482 } else if ( loadfn == "aux12" ) {
484 } else if ( loadfn == "aux13" ) {
486 } else if ( loadfn == "aux14" ) {
488 } else if ( loadfn == "aux15" ) {
490 } else if ( loadfn == "aux16" ) {
492 } else if ( loadfn == "aux17" ) {
494 } else if ( loadfn == "aux18" ) {
498 if ( loadfn == "ax" ) {
500 } else if ( loadfn == "speed" ) {
502 } else if ( loadfn == "mach" ) {
504 } else if ( loadfn == "altitude" ) {
505 load_fn = get_altitude;
506 } else if ( loadfn == "agl" ) {
508 } else if ( loadfn == "framerate" ) {
509 load_fn = get_frame_rate;
510 } else if ( loadfn == "heading" ) {
511 load_fn = get_heading;
512 } else if ( loadfn == "fov" ) {
514 } else if ( loadfn == "vfc_tris_culled" ) {
515 load_fn = get_vfc_tris_culled;
516 } else if ( loadfn == "vfc_tris_drawn" ) {
517 load_fn = get_vfc_tris_drawn;
518 } else if ( loadfn == "aoa" ) {
520 } else if ( loadfn == "latitude" ) {
521 load_fn = get_latitude;
522 } else if ( loadfn == "anzg" ) {
524 } else if ( loadfn == "longitude" ) {
525 load_fn = get_longitude;
526 } else if (loadfn=="throttleval") {
527 load_fn = get_throttleval;
530 p = (instr_item *) new instr_label ( x,
535 label_format.c_str(),
553 readTBI(const SGPropertyNode * node)
558 name = node->getStringValue("name");
559 x = node->getIntValue("x");
560 y = node->getIntValue("y");
561 width = node->getIntValue("width");
562 height = node->getIntValue("height");
563 maxBankAngle = node->getFloatValue("maxBankAngle");
564 maxSlipAngle = node->getFloatValue("maxSlipAngle");
565 gap_width = node->getIntValue("gap_width");
566 working = node->getBoolValue("working");
567 tsi = node->getBoolValue("tsi"); //suma
568 rad = node->getFloatValue("rad"); //suma
570 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
573 p = (instr_item *) new fgTBI_instr( x,
590 readRunway(const SGPropertyNode * node) {
591 name = node->getStringValue("name");
592 x = node->getIntValue("x");
593 y = node->getIntValue("y");
594 width = node->getIntValue("width");
595 height = node->getIntValue("height");
596 scaling = node->getDoubleValue("scale");
597 working = node->getBoolValue("working",true);
598 runway_instr *ri = new runway_instr(x,y,width,height,scaling,working);
599 double scale = node->getDoubleValue("arrow_scale",1.0);
600 ri->setDrawArrow((scale>0)?true:false);
601 ri->setDrawArrowAlways((scale>0)?node->getBoolValue("arrow_always"):false);
602 ri->setStippleOutline(node->getIntValue("outer_stipple",0xFFFF));
603 ri->setStippleCenterline(node->getIntValue("center_stipple",0xFFFF));
604 ri->setArrowRotationRadius(node->getDoubleValue("arrow_radius"));
605 ri->setArrowScale(scale);
606 ri->setLineScale(node->getDoubleValue("line_scale",1.0));
607 ri->setScaleDist(node->getDoubleValue("scale_dist_nm"));
608 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
609 return (instr_item *) ri;
613 int readInstrument(const SGPropertyNode * node)
615 static const SGPropertyNode *startup_units_node
616 = fgGetNode("/sim/startup/units");
620 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
621 strcpy(units, " ft");
626 const SGPropertyNode * ladder_group = node->getNode("ladders");
628 if (ladder_group != 0) {
629 int nLadders = ladder_group->nChildren();
630 for (int j = 0; j < nLadders; j++) {
632 HIptr = readLadder(ladder_group->getChild(j));
633 HUD_deque.insert( HUD_deque.begin(), HIptr);
638 const SGPropertyNode * card_group = node->getNode("cards");
639 if (card_group != 0) {
640 int nCards = card_group->nChildren();
641 for (int j = 0; j < nCards; j++) {
643 HIptr = readCard(card_group->getChild(j));
644 HUD_deque.insert( HUD_deque.begin(), HIptr);
649 const SGPropertyNode * label_group = node->getNode("labels");
650 if (label_group != 0) {
651 int nLabels = label_group->nChildren();
652 for (int j = 0; j < nLabels; j++) {
654 HIptr = readLabel(label_group->getChild(j));
655 HUD_deque.insert( HUD_deque.begin(), HIptr);
660 const SGPropertyNode * tbi_group = node->getNode("tbis");
661 if (tbi_group != 0) {
662 int nTbis = tbi_group->nChildren();
663 for (int j = 0; j < nTbis; j++) {
665 HIptr = readTBI(tbi_group->getChild(j));
666 HUD_deque.insert( HUD_deque.begin(), HIptr);
671 const SGPropertyNode * rwy_group = node->getNode("runways");
672 if (rwy_group != 0) {
673 int nRwy = rwy_group->nChildren();
674 for (int j = 0; j < nRwy; j++) {
675 SG_LOG( SG_COCKPIT, SG_DEBUG,
676 "************** Reading runway properties" );
677 HIptr = readRunway(rwy_group->getChild(j));
678 HUD_deque.insert( HUD_deque.begin(), HIptr);
683 }//end readinstrument
686 int readHud( istream &input )
692 readProperties(input, &root);
693 } catch (const sg_exception &e) {
694 guiErrorMessage("Error reading HUD: ", e);
699 SG_LOG(SG_INPUT, SG_INFO, "Read properties for " <<
700 root.getStringValue("name"));
703 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end()); // empty the HUD deque
706 SG_LOG(SG_INPUT, SG_INFO, "Reading Hud instruments");
708 const SGPropertyNode * instrument_group = root.getChild("instruments");
709 int nInstruments = instrument_group->nChildren();
711 for (int i = 0; i < nInstruments; i++) {
713 const SGPropertyNode * node = instrument_group->getChild(i);
715 SGPath path( globals->get_fg_root() );
716 path.append(node->getStringValue("path"));
718 SG_LOG(SG_INPUT, SG_INFO, "Reading Instrument "
723 SGPropertyNode root2;
725 readProperties(path.str(), &root2);
726 } catch (const sg_exception &e) {
727 guiErrorMessage("Error reading HUD instrument: ", e);
730 readInstrument(&root2);
737 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
742 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
745 fgGetString("/sim/hud/path", "Huds/Default/default.xml");
746 SGPath path(globals->get_fg_root());
747 path.append(hud_path);
749 ifstream input(path.c_str());
751 SG_LOG(SG_INPUT, SG_ALERT,
752 "Cannot read Hud configuration from " << path.str());
761 // this chunk of code is not necessarily thread safe if the
762 // compiler optimizer reorders these statements. Note that
763 // "delete ptr" does not set "ptr = NULL". We have to do that
765 fntRenderer *tmp = HUDtext;
770 FGFontCache *fc = globals->get_fontcache();
771 HUD_Font = fc->getTexFont(fgGetString("/sim/hud/font/name", "Helvetica.txf"));
773 throw sg_throwable(string("/sim/hud/font/name is not a texture font"));
775 HUD_TextSize = fgGetFloat("/sim/hud/font/size", 10);
777 HUDtext = new fntRenderer();
778 HUDtext->setFont(HUD_Font);
779 HUDtext->setPointSize(HUD_TextSize);
780 HUD_TextList.setFont( HUDtext );
782 HUD = new HUD_Properties;
783 return 0; // For now. Later we may use this for an error code.
787 int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
792 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
794 SGPath path(globals->get_fg_root());
795 path.append("Huds/Minimal/default.xml");
798 ifstream input(path.c_str());
800 SG_LOG(SG_INPUT, SG_ALERT,
801 "Cannot read Hud configuration from " << path.str());
807 return 0; // For now. Later we may use this for an error code.
810 //$$$ End - added, Neetha, 28 Nov 2k
813 void fgHUDReshape(void) {
816 // this chunk of code is not necessarily thread safe if the
817 // compiler optimizer reorders these statements. Note that
818 // "delete ptr" does not set "ptr = NULL". We have to do that
820 fntRenderer *tmp = HUDtext;
825 HUD_TextSize = fgGetInt("/sim/startup/xsize") / 60;
827 HUDtext = new fntRenderer();
828 HUDtext -> setFont ( guiFntHandle ) ;
829 HUDtext -> setPointSize ( HUD_TextSize ) ;
830 HUD_TextList.setFont( HUDtext );
837 // Performs a once around the list of calls to instruments installed in
838 // the HUD object with requests for redraw. Kinda. It will when this is
841 void fgUpdateHUD( void ) {
843 static const SGPropertyNode *enable3d_node = fgGetNode("/sim/hud/enable3d");
844 if( HUD_style == 1 && enable3d_node->getBoolValue() )
846 fgUpdateHUDVirtual();
850 static const float normal_aspect = float(640) / float(480);
851 // note: aspect_ratio is Y/X
852 float current_aspect = 1.0f/globals->get_current_view()->get_aspect_ratio();
853 if( current_aspect > normal_aspect ) {
854 float aspect_adjust = current_aspect / normal_aspect;
855 float adjust = 320.0f*aspect_adjust - 320.0f;
856 fgUpdateHUD( -adjust, 0.0f, 640.0f+adjust, 480.0f );
858 float aspect_adjust = normal_aspect / current_aspect;
859 float adjust = 240.0f*aspect_adjust - 240.0f;
860 fgUpdateHUD( 0.0f, -adjust, 640.0f, 480.0f+adjust );
864 void fgUpdateHUDVirtual()
866 FGViewer* view = globals->get_current_view();
868 // Standard fgfs projection, with essentially meaningless clip
869 // planes (we'll map the whole HUD plane to z=-1)
870 glMatrixMode(GL_PROJECTION);
873 gluPerspective(view->get_v_fov(), 1/view->get_aspect_ratio(), 0.1, 10);
875 glMatrixMode(GL_MODELVIEW);
879 // Standard fgfs view direction computation
881 lookat[0] = -sin(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
882 lookat[1] = tan(SG_DEGREES_TO_RADIANS * view->getPitchOffset_deg());
883 lookat[2] = -cos(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
884 if(fabs(lookat[1]) > 9999) lookat[1] = 9999; // FPU sanity
885 gluLookAt(0, 0, 0, lookat[0], lookat[1], lookat[2], 0, 1, 0);
887 // Map the -1:1 square to a 55.0x41.25 degree wide patch at z=1.
888 // This is the default fgfs field of view, which the HUD files are
889 // written to assume.
890 float dx = 0.52056705; // tan(55/2)
891 float dy = dx * 0.75; // assumes 4:3 aspect ratio
893 m[0] = dx; m[4] = 0; m[ 8] = 0; m[12] = 0;
894 m[1] = 0; m[5] = dy; m[ 9] = 0; m[13] = 0;
895 m[2] = 0; m[6] = 0; m[10] = 1; m[14] = 0;
896 m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1;
899 // Convert the 640x480 "HUD standard" coordinate space to a square
900 // about the origin in the range [-1:1] at depth of -1
901 glScalef(1./320, 1./240, 1);
902 glTranslatef(-320, -240, -1);
908 glMatrixMode(GL_PROJECTION);
910 glMatrixMode(GL_MODELVIEW);
914 void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
915 GLfloat x_end, GLfloat y_end )
917 glMatrixMode(GL_PROJECTION);
920 gluOrtho2D(x_start, x_end, y_start, y_end);
922 glMatrixMode(GL_MODELVIEW);
928 glMatrixMode(GL_PROJECTION);
930 glMatrixMode(GL_MODELVIEW);
936 if( !HUD_deque.size() ) { // Trust everyone, but ALWAYS cut the cards!
940 HUD_TextList.erase();
941 HUD_LineList.erase();
942 // HUD_StippleLineList.erase();
944 glDisable(GL_DEPTH_TEST);
945 glDisable(GL_LIGHTING);
947 static const SGPropertyNode *heading_enabled
948 = fgGetNode("/autopilot/locks/heading", true);
949 static const SGPropertyNode *altitude_enabled
950 = fgGetNode("/autopilot/locks/altitude", true);
952 static char hud_hdg_text[256];
953 static char hud_wp0_text[256];
954 static char hud_wp1_text[256];
955 static char hud_wp2_text[256];
956 static char hud_alt_text[256];
958 if (HUD->isAntialiased()) {
959 glEnable(GL_LINE_SMOOTH);
960 // glEnable(GL_BLEND);
961 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
962 glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
969 for_each(HUD_deque.begin(), HUD_deque.end(), HUDdraw());
971 HUD_TextList.add( fgText(40, 10, get_formated_gmt_time(), 0) );
977 if (strcmp( heading_enabled->getStringValue(), "dg-heading-hold") == 0 ) {
978 snprintf( hud_hdg_text, 256, "hdg = %.1f\n",
979 fgGetDouble("/autopilot/settings/heading-bug-deg") );
980 HUD_TextList.add( fgText( 40, apY, hud_hdg_text ) );
982 } else if ( strcmp(heading_enabled->getStringValue(), "true-heading-hold") == 0 ) {
983 snprintf( hud_hdg_text, 256, "hdg = %.1f\n",
984 fgGetDouble("/autopilot/settings/true-heading-deg") );
985 HUD_TextList.add( fgText( 40, apY, hud_hdg_text ) );
988 string wp0_id = fgGetString( "/autopilot/route-manager/wp[0]/id" );
989 if ( wp0_id.length() > 0 ) {
990 snprintf( hud_wp0_text, 256, "%5s %6.1fnm %s", wp0_id.c_str(),
991 fgGetDouble( "/autopilot/route-manager/wp[0]/dist" ),
992 fgGetString( "/autopilot/route-manager/wp[0]/eta" ) );
993 HUD_TextList.add( fgText( 40, apY, hud_wp0_text ) );
996 string wp1_id = fgGetString( "/autopilot/route-manager/wp[1]/id" );
997 if ( wp1_id.length() > 0 ) {
998 snprintf( hud_wp1_text, 256, "%5s %6.1fnm %s", wp1_id.c_str(),
999 fgGetDouble( "/autopilot/route-manager/wp[1]/dist" ),
1000 fgGetString( "/autopilot/route-manager/wp[1]/eta" ) );
1001 HUD_TextList.add( fgText( 40, apY, hud_wp1_text ) );
1004 string wp2_id = fgGetString( "/autopilot/route-manager/wp-last/id" );
1005 if ( wp2_id.length() > 0 ) {
1006 snprintf( hud_wp2_text, 256, "%5s %6.1fnm %s", wp2_id.c_str(),
1007 fgGetDouble( "/autopilot/route-manager/wp-last/dist" ),
1008 fgGetString( "/autopilot/route-manager/wp-last/eta" ) );
1009 HUD_TextList.add( fgText( 40, apY, hud_wp2_text ) );
1014 if ( strcmp( altitude_enabled->getStringValue(), "altitude-hold" ) == 0 ) {
1015 snprintf( hud_alt_text, 256, "alt = %.0f\n",
1016 fgGetDouble("/autopilot/settings/target-altitude-ft") );
1017 HUD_TextList.add( fgText( 40, apY, hud_alt_text ) );
1019 } else if ( strcmp( altitude_enabled->getStringValue(), "agl-hold" ) == 0 ){
1020 snprintf( hud_alt_text, 256, "agl = %.0f\n",
1021 fgGetDouble("/autopilot/settings/target-agl-ft") );
1022 HUD_TextList.add( fgText( 40, apY, hud_alt_text ) );
1026 HUD_TextList.draw();
1028 HUD_LineList.draw();
1030 // glEnable(GL_LINE_STIPPLE);
1031 // glLineStipple( 1, 0x00FF );
1032 // HUD_StippleLineList.draw();
1033 // glDisable(GL_LINE_STIPPLE);
1035 if (HUD->isAntialiased()) {
1036 // glDisable(GL_BLEND);
1037 glDisable(GL_LINE_SMOOTH);
1041 glEnable(GL_DEPTH_TEST);
1042 glEnable(GL_LIGHTING);
1049 // HUD property listener class
1051 HUD_Properties::HUD_Properties()
1053 _colors = fgGetNode("/sim/hud/colors", true)->getChildren("color");
1054 _which = fgGetNode("/sim/hud/current-color", true);
1055 _brightness = fgGetNode("/sim/hud/brightness", true);
1056 _alpha = fgGetNode("/sim/hud/alpha", true);
1057 _visibility = fgGetNode("/sim/hud/visibility", true);
1058 _antialiasing = fgGetNode("/sim/hud/antialiased", true);
1060 _which->addChangeListener(this);
1061 _brightness->addChangeListener(this);
1062 _alpha->addChangeListener(this);
1063 _visibility->addChangeListener(this);
1064 _antialiasing->addChangeListener(this, true);
1068 void HUD_Properties::valueChanged(SGPropertyNode *n)
1070 _visible = _visibility->getBoolValue();
1071 _antialiased = _antialiasing->getBoolValue();
1072 float brt = _brightness->getFloatValue();
1073 int w = _which->getIntValue();
1074 if (w < 0 || w >= int(_colors.size()))
1077 _r = clamp(brt * _colors[w]->getFloatValue("red", 1.0));
1078 _g = clamp(brt * _colors[w]->getFloatValue("green", 1.0));
1079 _b = clamp(brt * _colors[w]->getFloatValue("blue", 1.0));
1081 _a = _alpha->getFloatValue();
1085 void HUD_Properties::setColor() const
1088 glColor4f(_r, _g, _b, _a);
1090 glColor3f(_r, _g, _b);