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()
47 #include <simgear/constants.h>
48 #include <simgear/debug/logstream.hxx>
49 #include <simgear/props/props.hxx>
50 #include <simgear/misc/sg_path.hxx>
52 #include <Aircraft/aircraft.hxx>
53 #include <Autopilot/newauto.hxx>
55 #include <Main/globals.hxx>
56 #include <Main/fg_props.hxx>
58 #include <NetworkOLK/network.h>
60 #include <Scenery/scenery.hxx>
62 #if defined ( __sun__ ) || defined ( __sgi )
64 extern void *memmove(void *, const void *, size_t);
72 // The following routines obtain information concerning the aircraft's
73 // current state and return it to calling instrument display routines.
74 // They should eventually be member functions of the aircraft.
77 deque< instr_item * > HUD_deque;
79 fgTextList HUD_TextList;
80 fgLineList HUD_LineList;
81 fgLineList HUD_StippleLineList;
83 fntRenderer *HUDtext = 0;
84 float HUD_TextSize = 0;
88 static float hud_trans_alpha = 0.67f;
91 //$$$ begin - added, Neetha, 28 Nov 2k
99 static float span_units;
100 static float division_units;
101 static float minor_division = 0;
102 static UINT screen_hole;
105 static string loadfn;
107 static float maxValue;
108 static float minValue;
109 static float scaling;
110 static UINT major_divs;
111 static UINT minor_divs;
112 static UINT modulator;
113 static int dp_showing = 0;
114 static string label_format;
115 static string prelabel;
116 static string postlabel;
119 static float maxBankAngle;
120 static float maxSlipAngle;
121 static UINT gap_width;
122 static bool latitude;
123 static bool longitude;
124 static bool tick_bottom;
125 static bool tick_top;
126 static bool tick_right;
127 static bool tick_left;
128 static bool cap_bottom;
130 static bool cap_right;
131 static bool cap_left;
132 static float marker_off;
134 static bool enable_pointer;
135 static string type_pointer;
136 static bool frl_spot;
138 static bool vel_vector;
142 static bool climb_dive;
144 static float glide_slope_val;
145 static bool worm_energy;
146 static bool waypoint;
147 static string type_tick;//hud
148 static string length_tick;//hud
149 static bool label_box;//hud
150 static int digits; //suma
151 static float radius; //suma
152 static int divisions; //suma
153 static int zoom; //suma
154 static int zenith; //suma
155 static int nadir ; //suma
156 static int hat; //suma
157 static bool tsi; //suma
158 static float rad; //suma
161 static FLTFNPTR load_fn;
162 static fgLabelJust justification;
163 static const char *pre_label_string = 0;
164 static const char *post_label_string = 0;
166 int readHud( istream &input );
167 int readInstrument ( const SGPropertyNode * node);
168 static instr_item * readLadder ( const SGPropertyNode * node);
169 static instr_item * readCard ( const SGPropertyNode * node);
170 static instr_item * readLabel( const SGPropertyNode * node);
171 static instr_item * readTBI( const SGPropertyNode * node);
172 //$$$ end - added, Neetha, 28 Nov 2k
174 static void drawHUD();
175 static void fgUpdateHUDVirtual();
177 void fgHUDalphaInit( void );
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 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" ) {
495 } else if ( loadfn == "ax" ) {
497 } else if ( loadfn == "speed" ) {
499 } else if ( loadfn == "mach" ) {
501 } else if ( loadfn == "altitude" ) {
502 load_fn = get_altitude;
503 } else if ( loadfn == "agl" ) {
505 } else if ( loadfn == "framerate" ) {
506 load_fn = get_frame_rate;
507 } else if ( loadfn == "heading" ) {
508 load_fn = get_heading;
509 } else if ( loadfn == "fov" ) {
511 } else if ( loadfn == "vfc_tris_culled" ) {
512 load_fn = get_vfc_tris_culled;
513 } else if ( loadfn == "vfc_tris_drawn" ) {
514 load_fn = get_vfc_tris_drawn;
515 } else if ( loadfn == "aoa" ) {
517 } else if ( loadfn == "latitude" ) {
518 load_fn = get_latitude;
519 } else if ( loadfn == "anzg" ) {
521 } else if ( loadfn == "longitude" ) {
522 load_fn = get_longitude;
523 } else if (loadfn=="throttleval") {
524 load_fn = get_throttleval;
527 p = (instr_item *) new instr_label ( x,
532 label_format.c_str(),
550 readTBI(const SGPropertyNode * node)
555 name = node->getStringValue("name");
556 x = node->getIntValue("x");
557 y = node->getIntValue("y");
558 width = node->getIntValue("width");
559 height = node->getIntValue("height");
560 maxBankAngle = node->getFloatValue("maxBankAngle");
561 maxSlipAngle = node->getFloatValue("maxSlipAngle");
562 gap_width = node->getIntValue("gap_width");
563 working = node->getBoolValue("working");
564 tsi = node->getBoolValue("tsi"); //suma
565 rad = node->getFloatValue("rad"); //suma
567 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
570 p = (instr_item *) new fgTBI_instr( x,
587 int readInstrument(const SGPropertyNode * node)
589 static const SGPropertyNode *startup_units_node
590 = fgGetNode("/sim/startup/units");
594 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
595 strcpy(units, " ft");
600 const SGPropertyNode * ladder_group = node->getNode("ladders");
602 if (ladder_group != 0) {
603 int nLadders = ladder_group->nChildren();
604 for (int j = 0; j < nLadders; j++) {
606 HIptr = readLadder(ladder_group->getChild(j));
607 HUD_deque.insert( HUD_deque.begin(), HIptr);
612 const SGPropertyNode * card_group = node->getNode("cards");
613 if (card_group != 0) {
614 int nCards = card_group->nChildren();
615 for (int j = 0; j < nCards; j++) {
617 HIptr = readCard(card_group->getChild(j));
618 HUD_deque.insert( HUD_deque.begin(), HIptr);
623 const SGPropertyNode * label_group = node->getNode("labels");
624 if (label_group != 0) {
625 int nLabels = label_group->nChildren();
626 for (int j = 0; j < nLabels; j++) {
628 HIptr = readLabel(label_group->getChild(j));
629 HUD_deque.insert( HUD_deque.begin(), HIptr);
634 const SGPropertyNode * tbi_group = node->getNode("tbis");
635 if (tbi_group != 0) {
636 int nTbis = tbi_group->nChildren();
637 for (int j = 0; j < nTbis; j++) {
639 HIptr = readTBI(tbi_group->getChild(j));
640 HUD_deque.insert( HUD_deque.begin(), HIptr);
645 }//end readinstrument
648 int readHud( istream &input )
654 readProperties(input, &root);
655 } catch (const sg_exception &e) {
656 guiErrorMessage("Error reading HUD: ", e);
661 SG_LOG(SG_INPUT, SG_INFO, "Read properties for " <<
662 root.getStringValue("name"));
665 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end()); // empty the HUD deque
668 SG_LOG(SG_INPUT, SG_INFO, "Reading Hud instruments");
670 const SGPropertyNode * instrument_group = root.getChild("instruments");
671 int nInstruments = instrument_group->nChildren();
673 for (int i = 0; i < nInstruments; i++) {
675 const SGPropertyNode * node = instrument_group->getChild(i);
677 SGPath path( globals->get_fg_root() );
678 path.append(node->getStringValue("path"));
680 SG_LOG(SG_INPUT, SG_INFO, "Reading Instrument "
685 SGPropertyNode root2;
687 readProperties(path.str(), &root2);
688 } catch (const sg_exception &e) {
689 guiErrorMessage("Error reading HUD instrument: ", e);
692 readInstrument(&root2);
699 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
704 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
707 fgGetString("/sim/hud/path", "Huds/Default/default.xml");
708 SGPath path(globals->get_fg_root());
709 path.append(hud_path);
711 ifstream input(path.c_str());
713 SG_LOG(SG_INPUT, SG_ALERT,
714 "Cannot read Hud configuration from " << path.str());
724 // this chunk of code is not necessarily thread safe if the
725 // compiler optimizer reorders these statements. Note that
726 // "delete ptr" does not set "ptr = NULL". We have to do that
728 fntRenderer *tmp = HUDtext;
733 // HUD_TextSize = fgGetInt("/sim/startup/xsize") / 60;
735 HUDtext = new fntRenderer();
736 HUDtext -> setFont ( guiFntHandle ) ;
737 HUDtext -> setPointSize ( HUD_TextSize ) ;
738 HUD_TextList.setFont( HUDtext );
740 return 0; // For now. Later we may use this for an error code.
744 int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
749 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
751 SGPath path(globals->get_fg_root());
752 path.append("Huds/Minimal/default.xml");
755 ifstream input(path.c_str());
757 SG_LOG(SG_INPUT, SG_ALERT,
758 "Cannot read Hud configuration from " << path.str());
764 return 0; // For now. Later we may use this for an error code.
767 //$$$ End - added, Neetha, 28 Nov 2k
769 static int global_day_night_switch = HUD_DAY;
771 void HUD_masterswitch( bool incr )
773 if ( fgGetBool("/sim/hud/visibility") ) {
774 if ( global_day_night_switch == HUD_DAY ) {
775 global_day_night_switch = HUD_NIGHT;
777 fgSetBool("/sim/hud/visibility", false);
780 fgSetBool("/sim/hud/visibility", true);
781 global_day_night_switch = HUD_DAY;
785 void HUD_brightkey( bool incr_bright )
787 instr_item *pHUDInstr = HUD_deque[0];
788 int brightness = pHUDInstr->get_brightness();
790 if( fgGetBool("/sim/hud/visibility") ) {
795 brightness = HUD_BRT_BLACK;
799 brightness = HUD_BRT_LIGHT;
803 brightness = HUD_BRT_MEDIUM;
807 brightness = HUD_BRT_DARK;
811 brightness = HUD_BRT_BLACK;
817 brightness = HUD_BRT_MEDIUM;
821 brightness = HUD_BRT_DARK;
825 brightness = HUD_BRT_BLACK;
829 brightness = HUD_BRT_LIGHT;
833 fgSetBool("/sim/hud/visibility", false);
837 fgSetBool("/sim/hud/visibility", true);
840 pHUDInstr->SetBrightness( brightness );
844 #define fgAP_CLAMP(val,min,max) ( (val) = (val) > (max) ? (max) : (val) < (min) ? (min) : (val) )
846 static puDialogBox *HUDalphaDialog;
847 static puText *HUDalphaText;
848 static puSlider *HUDalphaHS0;
849 //static puText *HUDtextText;
850 //static puSlider *HUDalphaHS1;
851 static char SliderText[2][ 8 ];
853 static void alpha_adj( puObject *hs ) {
856 hs-> getValue ( &val ) ;
857 fgAP_CLAMP ( val, 0.1, 1.0 ) ;
858 // printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
859 hud_trans_alpha = val;
860 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
861 HUDalphaText -> setLabel ( SliderText[ 0 ] ) ;
864 void fgHUDalphaAdjust( puObject * ) {
865 fgSetBool("/sim/hud/antialiased", true);
866 FG_PUSH_PUI_DIALOG( HUDalphaDialog );
869 static void goAwayHUDalphaAdjust (puObject *)
871 FG_POP_PUI_DIALOG( HUDalphaDialog );
874 static void cancelHUDalphaAdjust (puObject *)
876 fgSetBool("/sim/hud/antialiased", false);
877 FG_POP_PUI_DIALOG( HUDalphaDialog );
880 // Done once at system initialization
881 void fgHUDalphaInit( void ) {
883 // printf("fgHUDalphaInit\n");
884 #define HORIZONTAL FALSE
888 int DialogWidth = 240;
890 char Label[] = "HUD Adjuster";
893 int labelX = (DialogWidth / 2) -
894 ( puGetDefaultLabelFont().getStringWidth( Label ) / 2);
899 int slider_width = 220;
900 int slider_title_x = 15;
901 int slider_value_x = 160;
902 float slider_delta = 0.05f;
904 puFont HUDalphaLegendFont;
905 puFont HUDalphaLabelFont;
906 puGetDefaultFonts ( &HUDalphaLegendFont, &HUDalphaLabelFont );
908 HUDalphaDialog = new puDialogBox ( DialogX, DialogY ); {
909 int horiz_slider_height = HUDalphaLabelFont.getStringHeight() +
910 HUDalphaLabelFont.getStringDescender() +
911 PUSTR_TGAP + PUSTR_BGAP + 5;
914 HUDalphaFrame = new puFrame ( 0, 0, DialogWidth,
916 * horiz_slider_height ); */
919 HUDalphaDialogMessage = new puText ( labelX,
921 * horiz_slider_height );
922 HUDalphaDialogMessage -> setDefaultValue ( Label );
923 HUDalphaDialogMessage -> getDefaultValue ( &s );
924 HUDalphaDialogMessage -> setLabel ( s );
926 HUDalphaHS0 = new puSlider ( slider_x, slider_y,
927 slider_width, HORIZONTAL ) ;
928 HUDalphaHS0-> setDelta ( slider_delta ) ;
929 HUDalphaHS0-> setValue ( hud_trans_alpha ) ;
930 HUDalphaHS0-> setCBMode ( PUSLIDER_DELTA ) ;
931 HUDalphaHS0-> setCallback ( alpha_adj ) ;
934 HUDalphaTitle = new puText ( slider_title_x, slider_y ) ;
935 HUDalphaTitle-> setDefaultValue ( "Alpha" ) ;
936 HUDalphaTitle-> getDefaultValue ( &s ) ;
937 HUDalphaTitle-> setLabel ( s ) ;
939 HUDalphaText = new puText ( slider_value_x, slider_y ) ;
940 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
941 HUDalphaText-> setLabel ( SliderText[ 0 ] ) ;
944 HUDalphaOkButton = new puOneShot ( 10, 10, 60, 45 );
945 HUDalphaOkButton-> setLegend ( gui_msg_OK );
946 HUDalphaOkButton-> makeReturnDefault ( TRUE );
947 HUDalphaOkButton-> setCallback ( goAwayHUDalphaAdjust );
950 HUDalphaNoButton = new puOneShot ( 160, 10, 230, 45 );
951 HUDalphaNoButton-> setLegend ( gui_msg_CANCEL );
952 HUDalphaNoButton-> setCallback ( cancelHUDalphaAdjust );
954 FG_FINALIZE_PUI_DIALOG( HUDalphaDialog );
960 void fgHUDReshape(void) {
963 // this chunk of code is not necessarily thread safe if the
964 // compiler optimizer reorders these statements. Note that
965 // "delete ptr" does not set "ptr = NULL". We have to do that
967 fntRenderer *tmp = HUDtext;
972 HUD_TextSize = fgGetInt("/sim/startup/xsize") / 60;
974 HUDtext = new fntRenderer();
975 HUDtext -> setFont ( guiFntHandle ) ;
976 HUDtext -> setPointSize ( HUD_TextSize ) ;
977 HUD_TextList.setFont( HUDtext );
982 static void set_hud_color(float r, float g, float b) {
983 fgGetBool("/sim/hud/antialiased") ?
984 glColor4f(r,g,b,hud_trans_alpha) :
991 // Performs a once around the list of calls to instruments installed in
992 // the HUD object with requests for redraw. Kinda. It will when this is
995 void fgUpdateHUD( void ) {
997 static const SGPropertyNode *enable3d_node = fgGetNode("/sim/hud/enable3d");
998 if( HUD_style == 1 && enable3d_node->getBoolValue() )
1000 fgUpdateHUDVirtual();
1004 static const float normal_aspect = float(640) / float(480);
1005 // note: aspect_ratio is Y/X
1006 float current_aspect = 1.0f/globals->get_current_view()->get_aspect_ratio();
1007 if( current_aspect > normal_aspect ) {
1008 float aspect_adjust = current_aspect / normal_aspect;
1009 float adjust = 320.0f*aspect_adjust - 320.0f;
1010 fgUpdateHUD( -adjust, 0.0f, 640.0f+adjust, 480.0f );
1012 float aspect_adjust = normal_aspect / current_aspect;
1013 float adjust = 240.0f*aspect_adjust - 240.0f;
1014 fgUpdateHUD( 0.0f, -adjust, 640.0f, 480.0f+adjust );
1018 void fgUpdateHUDVirtual()
1020 FGViewer* view = globals->get_current_view();
1022 // Standard fgfs projection, with essentially meaningless clip
1023 // planes (we'll map the whole HUD plane to z=-1)
1024 glMatrixMode(GL_PROJECTION);
1027 gluPerspective(view->get_v_fov(), 1/view->get_aspect_ratio(), 0.1, 10);
1029 glMatrixMode(GL_MODELVIEW);
1033 // Standard fgfs view direction computation
1035 lookat[0] = -sin(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
1036 lookat[1] = tan(SG_DEGREES_TO_RADIANS * view->getPitchOffset_deg());
1037 lookat[2] = -cos(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
1038 if(fabs(lookat[1]) > 9999) lookat[1] = 9999; // FPU sanity
1039 gluLookAt(0, 0, 0, lookat[0], lookat[1], lookat[2], 0, 1, 0);
1041 // Map the -1:1 square to a 55.0x41.25 degree wide patch at z=1.
1042 // This is the default fgfs field of view, which the HUD files are
1043 // written to assume.
1044 float dx = 0.52056705; // tan(55/2)
1045 float dy = dx * 0.75; // assumes 4:3 aspect ratio
1047 m[0] = dx; m[4] = 0; m[ 8] = 0; m[12] = 0;
1048 m[1] = 0; m[5] = dy; m[ 9] = 0; m[13] = 0;
1049 m[2] = 0; m[6] = 0; m[10] = 1; m[14] = 0;
1050 m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1;
1053 // Convert the 640x480 "HUD standard" coordinate space to a square
1054 // about the origin in the range [-1:1] at depth of -1
1055 glScalef(1./320, 1./240, 1);
1056 glTranslatef(-320, -240, -1);
1061 // Clean up our mess
1062 glMatrixMode(GL_PROJECTION);
1064 glMatrixMode(GL_MODELVIEW);
1068 void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
1069 GLfloat x_end, GLfloat y_end )
1071 glMatrixMode(GL_PROJECTION);
1074 gluOrtho2D(x_start, x_end, y_start, y_end);
1076 glMatrixMode(GL_MODELVIEW);
1082 glMatrixMode(GL_PROJECTION);
1084 glMatrixMode(GL_MODELVIEW);
1090 if( !HUD_deque.size() ) { // Trust everyone, but ALWAYS cut the cards!
1094 HUD_TextList.erase();
1095 HUD_LineList.erase();
1096 // HUD_StippleLineList.erase();
1098 glDisable(GL_DEPTH_TEST);
1099 glDisable(GL_LIGHTING);
1101 static const SGPropertyNode * antialiased_node
1102 = fgGetNode("/sim/hud/antialiased");
1104 if( antialiased_node->getBoolValue() ) {
1105 glEnable(GL_LINE_SMOOTH);
1106 // glEnable(GL_BLEND);
1107 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1108 glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
1114 if( global_day_night_switch == HUD_DAY) {
1115 switch (HUD_deque[0]->get_brightness())
1118 set_hud_color (0.1f, 0.9f, 0.1f);
1121 case HUD_BRT_MEDIUM:
1122 set_hud_color (0.1f, 0.7f, 0.0f);
1126 set_hud_color (0.0f, 0.6f, 0.0f);
1130 set_hud_color( 0.0f, 0.0f, 0.0f);
1134 set_hud_color (0.1f, 0.9f, 0.1f);
1137 if( global_day_night_switch == HUD_NIGHT) {
1138 switch (HUD_deque[0]->get_brightness())
1141 set_hud_color (0.9f, 0.1f, 0.1f);
1144 case HUD_BRT_MEDIUM:
1145 set_hud_color (0.7f, 0.0f, 0.1f);
1149 set_hud_color (0.6f, 0.0f, 0.0f);
1153 set_hud_color( 0.0f, 0.0f, 0.0f);
1157 set_hud_color (0.6f, 0.0f, 0.0f);
1159 } else { // Just in case default
1160 set_hud_color (0.1f, 0.9f, 0.1f);
1164 for_each(HUD_deque.begin(), HUD_deque.end(), HUDdraw());
1166 HUD_TextList.add( fgText(40, 10, get_formated_gmt_time(), 0) );
1168 #ifdef FG_NETWORK_OLK
1169 if ( net_hud_display ) {
1176 // char scratch[128];
1177 // HUD_TextList.add( fgText( "AUTOPILOT", 20, apY) );
1179 FGAutopilot *AP = globals->get_autopilot();
1181 if( AP->get_HeadingEnabled() ) {
1182 HUD_TextList.add( fgText( 40, apY, AP->get_TargetHeadingStr()) );
1185 if( AP->get_AltitudeEnabled() ) {
1186 HUD_TextList.add( fgText( 40, apY, AP->get_TargetAltitudeStr()) );
1189 if( AP->get_HeadingMode() == FGAutopilot::FG_HEADING_WAYPOINT )
1191 if ( strlen( AP->get_TargetWP1Str() ) ) {
1192 HUD_TextList.add( fgText( 40, apY, AP->get_TargetWP1Str() ) );
1195 if ( strlen( AP->get_TargetWP2Str() ) ) {
1196 HUD_TextList.add( fgText( 40, apY, AP->get_TargetWP2Str() ) );
1199 if ( strlen( AP->get_TargetWP3Str() ) ) {
1200 HUD_TextList.add( fgText( 40, apY, AP->get_TargetWP3Str() ) );
1205 HUD_TextList.draw();
1207 HUD_LineList.draw();
1209 // glEnable(GL_LINE_STIPPLE);
1210 // glLineStipple( 1, 0x00FF );
1211 // HUD_StippleLineList.draw();
1212 // glDisable(GL_LINE_STIPPLE);
1214 if( antialiased_node->getBoolValue() ) {
1215 // glDisable(GL_BLEND);
1216 glDisable(GL_LINE_SMOOTH);
1220 glEnable(GL_DEPTH_TEST);
1221 glEnable(GL_LIGHTING);