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., 675 Mass Ave, Cambridge, MA 02139, 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>
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);
71 // The following routines obtain information concerning the aircraft's
72 // current state and return it to calling instrument display routines.
73 // They should eventually be member functions of the aircraft.
76 deque< instr_item * > HUD_deque;
78 fgTextList HUD_TextList;
79 fgLineList HUD_LineList;
80 fgLineList HUD_StippleLineList;
82 fntRenderer *HUDtext = 0;
83 float HUD_TextSize = 0;
87 static float hud_trans_alpha = 0.67f;
90 //$$$ begin - added, Neetha, 28 Nov 2k
98 static float span_units;
99 static float division_units;
100 static float minor_division = 0;
101 static UINT screen_hole;
104 static string loadfn;
106 static float maxValue;
107 static float minValue;
108 static float scaling;
109 static UINT major_divs;
110 static UINT minor_divs;
111 static UINT modulator;
112 static int dp_showing = 0;
113 static string label_format;
114 static string prelabel;
115 static string postlabel;
118 static float maxBankAngle;
119 static float maxSlipAngle;
120 static UINT gap_width;
121 static bool latitude;
122 static bool longitude;
123 static bool tick_bottom;
124 static bool tick_top;
125 static bool tick_right;
126 static bool tick_left;
127 static bool cap_bottom;
129 static bool cap_right;
130 static bool cap_left;
131 static float marker_off;
133 static bool enable_pointer;
134 static string type_pointer;
135 static bool frl_spot;
137 static bool vel_vector;
141 static bool climb_dive;
143 static float glide_slope_val;
144 static bool worm_energy;
145 static bool waypoint;
146 static string type_tick;//hud
147 static string length_tick;//hud
148 static bool label_box;//hud
149 static int digits; //suma
150 static float radius; //suma
151 static int divisions; //suma
152 static int zoom; //suma
153 static int zenith; //suma
154 static int nadir ; //suma
155 static int hat; //suma
156 static bool tsi; //suma
157 static float rad; //suma
160 static FLTFNPTR load_fn;
161 static fgLabelJust justification;
162 static const char *pre_label_string = 0;
163 static const char *post_label_string = 0;
165 int readHud( istream &input );
166 int readInstrument ( const SGPropertyNode * node);
167 static instr_item * readLadder ( const SGPropertyNode * node);
168 static instr_item * readCard ( const SGPropertyNode * node);
169 static instr_item * readLabel( const SGPropertyNode * node);
170 static instr_item * readTBI( const SGPropertyNode * node);
171 //$$$ end - added, Neetha, 28 Nov 2k
173 static void drawHUD();
174 static void fgUpdateHUDVirtual();
176 void fgHUDalphaInit( void );
182 locRECT( UINT left, UINT top, UINT right, UINT bottom);
183 RECT get_rect(void) { return rect;}
186 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
191 rect.bottom = bottom;
196 //========================= End of Class Implementations===================
199 // Constructs a HUD object and then adds in instruments. At the present
200 // the instruments are hard coded into the routine. Ultimately these need
201 // to be defined by the aircraft's instrumentation records so that the
202 // display for a Piper Cub doesn't show the speed range of a North American
203 // mustange and the engine readouts of a B36!
208 //$$$ begin - added, Neetha, 28 Nov 2k
210 readLadder(const SGPropertyNode * node)
215 name = node->getStringValue("name");
216 x = node->getIntValue("x");
217 y = node->getIntValue("y");
218 width = node->getIntValue("width");
219 height = node->getIntValue("height");
220 factor = node->getFloatValue("compression_factor");
221 span_units = node->getFloatValue("span_units");
222 division_units = node->getFloatValue("division_units");
223 screen_hole = node->getIntValue("screen_hole");
224 lbl_pos = node->getIntValue("lbl_pos");
225 frl_spot = node->getBoolValue("enable_frl",false);
226 target = node->getBoolValue("enable_target_spot",false);
227 vel_vector = node->getBoolValue("enable_velocity_vector",false);
228 drift = node->getBoolValue("enable_drift_marker",false);
229 alpha = node->getBoolValue("enable_alpha_bracket",false);
230 energy = node->getBoolValue("enable_energy_marker",false);
231 climb_dive = node->getBoolValue("enable_climb_dive_marker",false);
232 glide = node->getBoolValue("enable_glide_slope_marker",false);
233 glide_slope_val = node->getFloatValue("glide_slope",-4.0);
234 worm_energy = node->getBoolValue("enable_energy_marker",false);
235 waypoint = node->getBoolValue("enable_waypoint_marker",false);
236 working = node->getBoolValue("working");
237 zenith = node->getIntValue("zenith"); //suma
238 nadir = node->getIntValue("nadir"); //suma
239 hat = node->getIntValue("hat");
240 // The factor assumes a base of 55 degrees per 640 pixels.
241 // Invert to convert the "compression" factor to a
242 // pixels-per-degree number.
243 if(fgGetBool("/sim/hud/enable3d", true))
248 factor = (640./55.) / factor;
252 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
254 p = (instr_item *) new HudLadder( name, x, y,
255 width, height, factor,
257 span_units, division_units, minor_division,
258 screen_hole, lbl_pos, frl_spot, target, vel_vector,
259 drift, alpha, energy, climb_dive,
260 glide, glide_slope_val, worm_energy,
261 waypoint, working, zenith, nadir, hat);
268 readCard(const SGPropertyNode * node)
273 name = node->getStringValue("name");
274 x = node->getIntValue("x");
275 y = node->getIntValue("y");
276 width = node->getIntValue("width");
277 height = node->getIntValue("height");
278 loadfn = node->getStringValue("loadfn");
279 options = node->getIntValue("options");
280 maxValue = node->getFloatValue("maxValue");
281 minValue = node->getFloatValue("minValue");
282 scaling = node->getFloatValue("disp_scaling");
283 major_divs = node->getIntValue("major_divs");
284 minor_divs = node->getIntValue("minor_divs");
285 modulator = node->getIntValue("modulator");
286 span_units = node->getFloatValue("value_span");
287 type = node->getStringValue("type");
288 tick_bottom = node->getBoolValue("tick_bottom",false);
289 tick_top = node->getBoolValue("tick_top",false);
290 tick_right = node->getBoolValue("tick_right",false);
291 tick_left = node->getBoolValue("tick_left",false);
292 cap_bottom = node->getBoolValue("cap_bottom",false);
293 cap_top = node->getBoolValue("cap_top",false);
294 cap_right = node->getBoolValue("cap_right",false);
295 cap_left = node->getBoolValue("cap_left",false);
296 marker_off = node->getFloatValue("marker_offset",0.0);
297 enable_pointer = node->getBoolValue("enable_pointer",true);
298 type_pointer = node->getStringValue("pointer_type");
299 type_tick = node->getStringValue("tick_type");//hud Can be 'circle' or 'line'
300 length_tick = node->getStringValue("tick_length");//hud For variable length
301 working = node->getBoolValue("working");
302 radius = node->getFloatValue("radius"); //suma
303 divisions = node->getIntValue("divisions"); //suma
304 zoom = node->getIntValue("zoom"); //suma
306 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
310 span_units = maxValue - minValue;
313 if (loadfn=="anzg") {
315 } else if (loadfn=="heading") {
316 load_fn = get_heading;
317 } else if (loadfn=="aoa") {
319 } else if (loadfn=="climb") {
320 load_fn = get_climb_rate;
321 } else if (loadfn=="altitude") {
322 load_fn = get_altitude;
323 } else if (loadfn=="agl") {
325 } else if (loadfn=="speed") {
327 } else if (loadfn=="view_direction") {
328 load_fn = get_view_direction;
329 } else if (loadfn=="aileronval") {
330 load_fn = get_aileronval;
331 } else if (loadfn=="elevatorval") {
332 load_fn = get_elevatorval;
333 } else if (loadfn=="elevatortrimval") {
334 load_fn = get_elev_trimval;
335 } else if (loadfn=="rudderval") {
336 load_fn = get_rudderval;
337 } else if (loadfn=="throttleval") {
338 load_fn = get_throttleval;
342 if ( (type == "dial") | (type == "tape") ) {
343 p = (instr_item *) new hud_card( x,
351 major_divs, minor_divs,
375 p = (instr_item *) new gauge_instr( x, // x
379 load_fn, // data source
383 major_divs, minor_divs,
393 readLabel(const SGPropertyNode * node)
397 int font_size = (fgGetInt("/sim/startup/xsize") > 1000) ? HUD_FONT_LARGE : HUD_FONT_SMALL;
399 name = node->getStringValue("name");
400 x = node->getIntValue("x");
401 y = node->getIntValue("y");
402 width = node->getIntValue("width");
403 height = node->getIntValue("height");
404 loadfn = node->getStringValue("data_source");
405 label_format = node->getStringValue("label_format");
406 prelabel = node->getStringValue("pre_label_string");
407 postlabel = node->getStringValue("post_label_string");
408 scaling = node->getFloatValue("scale_data");
409 options = node->getIntValue("options");
410 justi = node->getIntValue("justification");
411 blinking = node->getIntValue("blinking");
412 latitude = node->getBoolValue("latitude",false);
413 longitude = node->getBoolValue("longitude",false);
414 label_box = node->getBoolValue("label_box",false);//hud
415 working = node->getBoolValue("working");
416 digits = node->getIntValue("digits"); //suma
419 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
423 justification = LEFT_JUST;
426 justification = CENTER_JUST;
429 justification = RIGHT_JUST;
434 if ( prelabel == "NULL" ) {
435 pre_label_string = NULL;
437 if ( prelabel == "blank" ) {
438 pre_label_string = " ";
440 pre_label_string = prelabel.c_str();
444 if ( postlabel == "blank" ) {
445 post_label_string = " ";
447 if ( postlabel == "NULL" ) {
448 post_label_string = NULL;
450 if ( postlabel == "units" ) {
451 post_label_string = units;
453 post_label_string = postlabel.c_str();
458 #ifdef ENABLE_SP_FMDS
459 if ( loadfn== "aux1" ) {
461 } else if ( loadfn == "aux2" ) {
463 } else if ( loadfn == "aux3" ) {
465 } else if ( loadfn == "aux4" ) {
467 } else if ( loadfn == "aux5" ) {
469 } else if ( loadfn == "aux6" ) {
471 } else if ( loadfn == "aux7" ) {
473 } else if ( loadfn == "aux8" ) {
475 } else if ( loadfn == "aux9" ) {
477 } else if ( loadfn == "aux10" ) {
479 } else if ( loadfn == "aux11" ) {
481 } else if ( loadfn == "aux12" ) {
483 } else if ( loadfn == "aux13" ) {
485 } else if ( loadfn == "aux14" ) {
487 } else if ( loadfn == "aux15" ) {
489 } else if ( loadfn == "aux16" ) {
491 } else if ( loadfn == "aux17" ) {
493 } else if ( loadfn == "aux18" ) {
497 if ( loadfn == "ax" ) {
499 } else if ( loadfn == "speed" ) {
501 } else if ( loadfn == "mach" ) {
503 } else if ( loadfn == "altitude" ) {
504 load_fn = get_altitude;
505 } else if ( loadfn == "agl" ) {
507 } else if ( loadfn == "framerate" ) {
508 load_fn = get_frame_rate;
509 } else if ( loadfn == "heading" ) {
510 load_fn = get_heading;
511 } else if ( loadfn == "fov" ) {
513 } else if ( loadfn == "vfc_tris_culled" ) {
514 load_fn = get_vfc_tris_culled;
515 } else if ( loadfn == "vfc_tris_drawn" ) {
516 load_fn = get_vfc_tris_drawn;
517 } else if ( loadfn == "aoa" ) {
519 } else if ( loadfn == "latitude" ) {
520 load_fn = get_latitude;
521 } else if ( loadfn == "anzg" ) {
523 } else if ( loadfn == "longitude" ) {
524 load_fn = get_longitude;
525 } else if (loadfn=="throttleval") {
526 load_fn = get_throttleval;
529 p = (instr_item *) new instr_label ( x,
534 label_format.c_str(),
552 readTBI(const SGPropertyNode * node)
557 name = node->getStringValue("name");
558 x = node->getIntValue("x");
559 y = node->getIntValue("y");
560 width = node->getIntValue("width");
561 height = node->getIntValue("height");
562 maxBankAngle = node->getFloatValue("maxBankAngle");
563 maxSlipAngle = node->getFloatValue("maxSlipAngle");
564 gap_width = node->getIntValue("gap_width");
565 working = node->getBoolValue("working");
566 tsi = node->getBoolValue("tsi"); //suma
567 rad = node->getFloatValue("rad"); //suma
569 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
572 p = (instr_item *) new fgTBI_instr( x,
589 int readInstrument(const SGPropertyNode * node)
591 static const SGPropertyNode *startup_units_node
592 = fgGetNode("/sim/startup/units");
596 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
597 strcpy(units, " ft");
602 const SGPropertyNode * ladder_group = node->getNode("ladders");
604 if (ladder_group != 0) {
605 int nLadders = ladder_group->nChildren();
606 for (int j = 0; j < nLadders; j++) {
608 HIptr = readLadder(ladder_group->getChild(j));
609 HUD_deque.insert( HUD_deque.begin(), HIptr);
614 const SGPropertyNode * card_group = node->getNode("cards");
615 if (card_group != 0) {
616 int nCards = card_group->nChildren();
617 for (int j = 0; j < nCards; j++) {
619 HIptr = readCard(card_group->getChild(j));
620 HUD_deque.insert( HUD_deque.begin(), HIptr);
625 const SGPropertyNode * label_group = node->getNode("labels");
626 if (label_group != 0) {
627 int nLabels = label_group->nChildren();
628 for (int j = 0; j < nLabels; j++) {
630 HIptr = readLabel(label_group->getChild(j));
631 HUD_deque.insert( HUD_deque.begin(), HIptr);
636 const SGPropertyNode * tbi_group = node->getNode("tbis");
637 if (tbi_group != 0) {
638 int nTbis = tbi_group->nChildren();
639 for (int j = 0; j < nTbis; j++) {
641 HIptr = readTBI(tbi_group->getChild(j));
642 HUD_deque.insert( HUD_deque.begin(), HIptr);
647 }//end readinstrument
650 int readHud( istream &input )
656 readProperties(input, &root);
657 } catch (const sg_exception &e) {
658 guiErrorMessage("Error reading HUD: ", e);
663 SG_LOG(SG_INPUT, SG_INFO, "Read properties for " <<
664 root.getStringValue("name"));
667 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end()); // empty the HUD deque
670 SG_LOG(SG_INPUT, SG_INFO, "Reading Hud instruments");
672 const SGPropertyNode * instrument_group = root.getChild("instruments");
673 int nInstruments = instrument_group->nChildren();
675 for (int i = 0; i < nInstruments; i++) {
677 const SGPropertyNode * node = instrument_group->getChild(i);
679 SGPath path( globals->get_fg_root() );
680 path.append(node->getStringValue("path"));
682 SG_LOG(SG_INPUT, SG_INFO, "Reading Instrument "
687 SGPropertyNode root2;
689 readProperties(path.str(), &root2);
690 } catch (const sg_exception &e) {
691 guiErrorMessage("Error reading HUD instrument: ", e);
694 readInstrument(&root2);
701 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
706 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
709 fgGetString("/sim/hud/path", "Huds/Default/default.xml");
710 SGPath path(globals->get_fg_root());
711 path.append(hud_path);
713 ifstream input(path.c_str());
715 SG_LOG(SG_INPUT, SG_ALERT,
716 "Cannot read Hud configuration from " << path.str());
726 // this chunk of code is not necessarily thread safe if the
727 // compiler optimizer reorders these statements. Note that
728 // "delete ptr" does not set "ptr = NULL". We have to do that
730 fntRenderer *tmp = HUDtext;
735 // HUD_TextSize = fgGetInt("/sim/startup/xsize") / 60;
737 HUDtext = new fntRenderer();
738 HUDtext -> setFont ( guiFntHandle ) ;
739 HUDtext -> setPointSize ( HUD_TextSize ) ;
740 HUD_TextList.setFont( HUDtext );
742 return 0; // For now. Later we may use this for an error code.
746 int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
751 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
753 SGPath path(globals->get_fg_root());
754 path.append("Huds/Minimal/default.xml");
757 ifstream input(path.c_str());
759 SG_LOG(SG_INPUT, SG_ALERT,
760 "Cannot read Hud configuration from " << path.str());
766 return 0; // For now. Later we may use this for an error code.
769 //$$$ End - added, Neetha, 28 Nov 2k
771 static int global_day_night_switch = HUD_DAY;
773 void HUD_masterswitch( bool incr )
775 if ( fgGetBool("/sim/hud/visibility") ) {
776 if ( global_day_night_switch == HUD_DAY ) {
777 global_day_night_switch = HUD_NIGHT;
779 fgSetBool("/sim/hud/visibility", false);
782 fgSetBool("/sim/hud/visibility", true);
783 global_day_night_switch = HUD_DAY;
787 void HUD_brightkey( bool incr_bright )
789 instr_item *pHUDInstr = HUD_deque[0];
790 int brightness = pHUDInstr->get_brightness();
792 if( fgGetBool("/sim/hud/visibility") ) {
797 brightness = HUD_BRT_BLACK;
801 brightness = HUD_BRT_LIGHT;
805 brightness = HUD_BRT_MEDIUM;
809 brightness = HUD_BRT_DARK;
813 brightness = HUD_BRT_BLACK;
819 brightness = HUD_BRT_MEDIUM;
823 brightness = HUD_BRT_DARK;
827 brightness = HUD_BRT_BLACK;
831 brightness = HUD_BRT_LIGHT;
835 fgSetBool("/sim/hud/visibility", false);
839 fgSetBool("/sim/hud/visibility", true);
842 pHUDInstr->SetBrightness( brightness );
846 #define fgAP_CLAMP(val,min,max) ( (val) = (val) > (max) ? (max) : (val) < (min) ? (min) : (val) )
848 static puDialogBox *HUDalphaDialog;
849 static puText *HUDalphaText;
850 static puSlider *HUDalphaHS0;
851 //static puText *HUDtextText;
852 //static puSlider *HUDalphaHS1;
853 static char SliderText[2][ 8 ];
855 static void alpha_adj( puObject *hs ) {
858 hs-> getValue ( &val ) ;
859 fgAP_CLAMP ( val, 0.1, 1.0 ) ;
860 // printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
861 hud_trans_alpha = val;
862 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
863 HUDalphaText -> setLabel ( SliderText[ 0 ] ) ;
866 void fgHUDalphaAdjust( puObject * ) {
867 fgSetBool("/sim/hud/antialiased", true);
868 FG_PUSH_PUI_DIALOG( HUDalphaDialog );
871 static void goAwayHUDalphaAdjust (puObject *)
873 FG_POP_PUI_DIALOG( HUDalphaDialog );
876 static void cancelHUDalphaAdjust (puObject *)
878 fgSetBool("/sim/hud/antialiased", false);
879 FG_POP_PUI_DIALOG( HUDalphaDialog );
882 // Done once at system initialization
883 void fgHUDalphaInit( void ) {
885 // printf("fgHUDalphaInit\n");
886 #define HORIZONTAL FALSE
890 int DialogWidth = 240;
892 char Label[] = "HUD Adjuster";
895 int labelX = (DialogWidth / 2) -
896 ( puGetDefaultLabelFont().getStringWidth( Label ) / 2);
901 int slider_width = 220;
902 int slider_title_x = 15;
903 int slider_value_x = 160;
904 float slider_delta = 0.05f;
906 puFont HUDalphaLegendFont;
907 puFont HUDalphaLabelFont;
908 puGetDefaultFonts ( &HUDalphaLegendFont, &HUDalphaLabelFont );
910 HUDalphaDialog = new puDialogBox ( DialogX, DialogY ); {
911 int horiz_slider_height = HUDalphaLabelFont.getStringHeight() +
912 HUDalphaLabelFont.getStringDescender() +
913 PUSTR_TGAP + PUSTR_BGAP + 5;
916 HUDalphaFrame = new puFrame ( 0, 0, DialogWidth,
918 * horiz_slider_height ); */
921 HUDalphaDialogMessage = new puText ( labelX,
923 * horiz_slider_height );
924 HUDalphaDialogMessage -> setDefaultValue ( Label );
925 HUDalphaDialogMessage -> getDefaultValue ( &s );
926 HUDalphaDialogMessage -> setLabel ( s );
928 HUDalphaHS0 = new puSlider ( slider_x, slider_y,
929 slider_width, HORIZONTAL ) ;
930 HUDalphaHS0-> setDelta ( slider_delta ) ;
931 HUDalphaHS0-> setValue ( hud_trans_alpha ) ;
932 HUDalphaHS0-> setCBMode ( PUSLIDER_DELTA ) ;
933 HUDalphaHS0-> setCallback ( alpha_adj ) ;
936 HUDalphaTitle = new puText ( slider_title_x, slider_y ) ;
937 HUDalphaTitle-> setDefaultValue ( "Alpha" ) ;
938 HUDalphaTitle-> getDefaultValue ( &s ) ;
939 HUDalphaTitle-> setLabel ( s ) ;
941 HUDalphaText = new puText ( slider_value_x, slider_y ) ;
942 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
943 HUDalphaText-> setLabel ( SliderText[ 0 ] ) ;
946 HUDalphaOkButton = new puOneShot ( 10, 10, 60, 45 );
947 HUDalphaOkButton-> setLegend ( gui_msg_OK );
948 HUDalphaOkButton-> makeReturnDefault ( TRUE );
949 HUDalphaOkButton-> setCallback ( goAwayHUDalphaAdjust );
952 HUDalphaNoButton = new puOneShot ( 160, 10, 230, 45 );
953 HUDalphaNoButton-> setLegend ( gui_msg_CANCEL );
954 HUDalphaNoButton-> setCallback ( cancelHUDalphaAdjust );
956 FG_FINALIZE_PUI_DIALOG( HUDalphaDialog );
962 void fgHUDReshape(void) {
965 // this chunk of code is not necessarily thread safe if the
966 // compiler optimizer reorders these statements. Note that
967 // "delete ptr" does not set "ptr = NULL". We have to do that
969 fntRenderer *tmp = HUDtext;
974 HUD_TextSize = fgGetInt("/sim/startup/xsize") / 60;
976 HUDtext = new fntRenderer();
977 HUDtext -> setFont ( guiFntHandle ) ;
978 HUDtext -> setPointSize ( HUD_TextSize ) ;
979 HUD_TextList.setFont( HUDtext );
984 static void set_hud_color(float r, float g, float b) {
985 fgGetBool("/sim/hud/antialiased") ?
986 glColor4f(r,g,b,hud_trans_alpha) :
993 // Performs a once around the list of calls to instruments installed in
994 // the HUD object with requests for redraw. Kinda. It will when this is
997 void fgUpdateHUD( void ) {
999 static const SGPropertyNode *enable3d_node = fgGetNode("/sim/hud/enable3d");
1000 if( HUD_style == 1 && enable3d_node->getBoolValue() )
1002 fgUpdateHUDVirtual();
1006 static const float normal_aspect = float(640) / float(480);
1007 // note: aspect_ratio is Y/X
1008 float current_aspect = 1.0f/globals->get_current_view()->get_aspect_ratio();
1009 if( current_aspect > normal_aspect ) {
1010 float aspect_adjust = current_aspect / normal_aspect;
1011 float adjust = 320.0f*aspect_adjust - 320.0f;
1012 fgUpdateHUD( -adjust, 0.0f, 640.0f+adjust, 480.0f );
1014 float aspect_adjust = normal_aspect / current_aspect;
1015 float adjust = 240.0f*aspect_adjust - 240.0f;
1016 fgUpdateHUD( 0.0f, -adjust, 640.0f, 480.0f+adjust );
1020 void fgUpdateHUDVirtual()
1022 FGViewer* view = globals->get_current_view();
1024 // Standard fgfs projection, with essentially meaningless clip
1025 // planes (we'll map the whole HUD plane to z=-1)
1026 glMatrixMode(GL_PROJECTION);
1029 gluPerspective(view->get_v_fov(), 1/view->get_aspect_ratio(), 0.1, 10);
1031 glMatrixMode(GL_MODELVIEW);
1035 // Standard fgfs view direction computation
1037 lookat[0] = -sin(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
1038 lookat[1] = tan(SG_DEGREES_TO_RADIANS * view->getPitchOffset_deg());
1039 lookat[2] = -cos(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
1040 if(fabs(lookat[1]) > 9999) lookat[1] = 9999; // FPU sanity
1041 gluLookAt(0, 0, 0, lookat[0], lookat[1], lookat[2], 0, 1, 0);
1043 // Map the -1:1 square to a 55.0x41.25 degree wide patch at z=1.
1044 // This is the default fgfs field of view, which the HUD files are
1045 // written to assume.
1046 float dx = 0.52056705; // tan(55/2)
1047 float dy = dx * 0.75; // assumes 4:3 aspect ratio
1049 m[0] = dx; m[4] = 0; m[ 8] = 0; m[12] = 0;
1050 m[1] = 0; m[5] = dy; m[ 9] = 0; m[13] = 0;
1051 m[2] = 0; m[6] = 0; m[10] = 1; m[14] = 0;
1052 m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1;
1055 // Convert the 640x480 "HUD standard" coordinate space to a square
1056 // about the origin in the range [-1:1] at depth of -1
1057 glScalef(1./320, 1./240, 1);
1058 glTranslatef(-320, -240, -1);
1063 // Clean up our mess
1064 glMatrixMode(GL_PROJECTION);
1066 glMatrixMode(GL_MODELVIEW);
1070 void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
1071 GLfloat x_end, GLfloat y_end )
1073 glMatrixMode(GL_PROJECTION);
1076 gluOrtho2D(x_start, x_end, y_start, y_end);
1078 glMatrixMode(GL_MODELVIEW);
1084 glMatrixMode(GL_PROJECTION);
1086 glMatrixMode(GL_MODELVIEW);
1092 if( !HUD_deque.size() ) { // Trust everyone, but ALWAYS cut the cards!
1096 HUD_TextList.erase();
1097 HUD_LineList.erase();
1098 // HUD_StippleLineList.erase();
1100 glDisable(GL_DEPTH_TEST);
1101 glDisable(GL_LIGHTING);
1103 static const SGPropertyNode *antialiased_node
1104 = fgGetNode("/sim/hud/antialiased", true);
1105 static const SGPropertyNode *heading_enabled
1106 = fgGetNode("/autopilot/locks/heading", true);
1107 static const SGPropertyNode *altitude_enabled
1108 = fgGetNode("/autopilot/locks/altitude", true);
1110 static char hud_hdg_text[256];
1111 static char hud_wp0_text[256];
1112 static char hud_wp1_text[256];
1113 static char hud_wp2_text[256];
1114 static char hud_alt_text[256];
1116 if( antialiased_node->getBoolValue() ) {
1117 glEnable(GL_LINE_SMOOTH);
1118 // glEnable(GL_BLEND);
1119 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1120 glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
1126 if( global_day_night_switch == HUD_DAY) {
1127 switch (HUD_deque[0]->get_brightness())
1130 set_hud_color (0.1f, 0.9f, 0.1f);
1133 case HUD_BRT_MEDIUM:
1134 set_hud_color (0.1f, 0.7f, 0.0f);
1138 set_hud_color (0.0f, 0.6f, 0.0f);
1142 set_hud_color( 0.0f, 0.0f, 0.0f);
1146 set_hud_color (0.1f, 0.9f, 0.1f);
1149 if( global_day_night_switch == HUD_NIGHT) {
1150 switch (HUD_deque[0]->get_brightness())
1153 set_hud_color (0.9f, 0.1f, 0.1f);
1156 case HUD_BRT_MEDIUM:
1157 set_hud_color (0.7f, 0.0f, 0.1f);
1161 set_hud_color (0.6f, 0.0f, 0.0f);
1165 set_hud_color( 0.0f, 0.0f, 0.0f);
1169 set_hud_color (0.6f, 0.0f, 0.0f);
1171 } else { // Just in case default
1172 set_hud_color (0.1f, 0.9f, 0.1f);
1176 for_each(HUD_deque.begin(), HUD_deque.end(), HUDdraw());
1178 HUD_TextList.add( fgText(40, 10, get_formated_gmt_time(), 0) );
1184 if (strcmp( heading_enabled->getStringValue(), "dg-heading-hold") == 0 ) {
1185 snprintf( hud_hdg_text, 256, "hdg = %.1f\n",
1186 fgGetDouble("/autopilot/settings/heading-bug-deg") );
1187 HUD_TextList.add( fgText( 40, apY, hud_hdg_text ) );
1189 } else if ( strcmp(heading_enabled->getStringValue(), "true-heading-hold") == 0 ) {
1190 snprintf( hud_hdg_text, 256, "hdg = %.1f\n",
1191 fgGetDouble("/autopilot/settings/true-heading-deg") );
1192 HUD_TextList.add( fgText( 40, apY, hud_hdg_text ) );
1195 string wp0_id = fgGetString( "/autopilot/route-manager/wp[0]/id" );
1196 if ( wp0_id.length() > 0 ) {
1197 snprintf( hud_wp0_text, 256, "%5s %6.1fnm %s", wp0_id.c_str(),
1198 fgGetDouble( "/autopilot/route-manager/wp[0]/dist" ),
1199 fgGetString( "/autopilot/route-manager/wp[0]/eta" ) );
1200 HUD_TextList.add( fgText( 40, apY, hud_wp0_text ) );
1203 string wp1_id = fgGetString( "/autopilot/route-manager/wp[1]/id" );
1204 if ( wp1_id.length() > 0 ) {
1205 snprintf( hud_wp1_text, 256, "%5s %6.1fnm %s", wp1_id.c_str(),
1206 fgGetDouble( "/autopilot/route-manager/wp[1]/dist" ),
1207 fgGetString( "/autopilot/route-manager/wp[1]/eta" ) );
1208 HUD_TextList.add( fgText( 40, apY, hud_wp1_text ) );
1211 string wp2_id = fgGetString( "/autopilot/route-manager/wp-last/id" );
1212 if ( wp2_id.length() > 0 ) {
1213 snprintf( hud_wp2_text, 256, "%5s %6.1fnm %s", wp2_id.c_str(),
1214 fgGetDouble( "/autopilot/route-manager/wp-last/dist" ),
1215 fgGetString( "/autopilot/route-manager/wp-last/eta" ) );
1216 HUD_TextList.add( fgText( 40, apY, hud_wp2_text ) );
1221 if ( strcmp( altitude_enabled->getStringValue(), "altitude-hold" ) == 0 ) {
1222 snprintf( hud_alt_text, 256, "alt = %.0f\n",
1223 fgGetDouble("/autopilot/settings/target-altitude-ft") );
1224 HUD_TextList.add( fgText( 40, apY, hud_alt_text ) );
1226 } else if ( strcmp( altitude_enabled->getStringValue(), "agl-hold" ) == 0 ){
1227 snprintf( hud_alt_text, 256, "agl = %.0f\n",
1228 fgGetDouble("/autopilot/settings/target-agl-ft") );
1229 HUD_TextList.add( fgText( 40, apY, hud_alt_text ) );
1233 HUD_TextList.draw();
1235 HUD_LineList.draw();
1237 // glEnable(GL_LINE_STIPPLE);
1238 // glLineStipple( 1, 0x00FF );
1239 // HUD_StippleLineList.draw();
1240 // glDisable(GL_LINE_STIPPLE);
1242 if( antialiased_node->getBoolValue() ) {
1243 // glDisable(GL_BLEND);
1244 glDisable(GL_LINE_SMOOTH);
1248 glEnable(GL_DEPTH_TEST);
1249 glEnable(GL_LIGHTING);