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.
22 // (Log is kept at end of this file)
34 # define exception c_exception
42 #include <Aircraft/aircraft.hxx>
43 #include <Debug/logstream.hxx>
44 #include <Include/fg_constants.h>
45 #include <Main/options.hxx>
46 #include <Math/fg_random.h>
47 #include <Math/mat3.h>
48 #include <Math/polar3d.hxx>
49 #include <Scenery/scenery.hxx>
50 #include <Time/fg_timer.hxx>
52 #if defined ( __sun__ ) || defined ( __sgi )
54 extern void *memmove(void *, const void *, size_t);
63 // The following routines obtain information concerntin the aircraft's
64 // current state and return it to calling instrument display routines.
65 // They should eventually be member functions of the aircraft.
68 HudContainerType HUD_deque;
74 locRECT( UINT left, UINT top, UINT right, UINT bottom);
75 RECT get_rect(void) { return rect;}
78 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
88 void drawOneLine( UINT x1, UINT y1, UINT x2, UINT y2)
96 void drawOneLine( RECT &rect)
99 glVertex2f(rect.left, rect.top);
100 glVertex2f(rect.right, rect.bottom);
105 // The following code deals with painting the "instrument" on the display
107 /* textString - Bitmap font string */
109 void textString( int x, int y, char *msg, void *font ){
112 glutBitmapCharacter(font, *msg);
117 /* strokeString - Stroke font string */
119 void strokeString(int x, int y, char *msg, void *font, float theta)
125 glRotatef(theta * RAD_TO_DEG, 0.0, 0.0, 1.0);
126 xx = (int)(x * cos(theta) + y * sin( theta ));
127 yy = (int)(y * cos(theta) - x * sin( theta ));
128 glTranslatef( xx, yy, 0);
129 glScalef(.1, .1, 0.0);
131 glutStrokeCharacter(font, *msg);
137 //========================= End of Class Implementations===================
140 // Constructs a HUD object and then adds in instruments. At the present
141 // the instruments are hard coded into the routine. Ultimately these need
142 // to be defined by the aircraft's instrumentation records so that the
143 // display for a Piper Cub doesn't show the speed range of a North American
144 // mustange and the engine readouts of a B36!
149 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
154 FG_LOG( FG_COCKPIT, FG_INFO, "Initializing current aircraft HUD" );
156 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end()); // empty the HUD deque
161 // For now lets just hardcode the hud here.
162 // In the future, hud information has to come from the same place
163 // aircraft information came from.
165 // fgHUDSetTimeMode( hud, NIGHT );
166 // fgHUDSetBrightness( hud, BRT_LIGHT );
173 HIptr = (instr_item *) new fgTBI_instr( 270, 100, 60, 10 );
176 case 1: // Artificial Horizon
177 HIptr = (instr_item *) new HudLadder( 240, 195, 120, 180 );
181 HIptr = (instr_item *) new hud_card( 130,
186 HUDS_LEFT | HUDS_VERT,
197 case 3: // Radio Altimeter
198 HIptr = (instr_item *) new hud_card( 420,
203 HUDS_LEFT | HUDS_VERT,
213 case 4: // GYRO COMPASS
214 HIptr = (instr_item *) new hud_card( 200,
230 HIptr = (instr_item *) new hud_card( 460,
235 HUDS_RIGHT | HUDS_VERT,
246 HIptr = (instr_item *) new guage_instr( 250, // x
250 get_aileronval, // data source
251 HUDS_BOTTOM | HUDS_NOTEXT,
258 HIptr = (instr_item *) new guage_instr( 170, // x
262 get_elevatorval, // data source
263 HUDS_RIGHT | HUDS_VERT | HUDS_NOTEXT,
264 -100.0, // Scale data
270 HIptr = (instr_item *) new guage_instr( 250, // x
274 get_rudderval, // data source
275 HUDS_TOP | HUDS_NOTEXT,
282 HIptr = (instr_item *) new guage_instr( 100, // x
286 get_throttleval, // data source
287 HUDS_VERT | HUDS_RIGHT | HUDS_NOTEXT,
293 case 10: // Digital KIAS
294 HIptr = (instr_item *) new instr_label ( 110,
310 case 11: // Digital Rate of Climb
311 HIptr = (instr_item *) new instr_label ( 110,
327 case 12: // Roll indication diagnostic
328 HIptr = (instr_item *) new instr_label ( 110,
344 case 13: // Angle of attack diagnostic
345 HIptr = (instr_item *) new instr_label ( 440,
362 HIptr = (instr_item *) new instr_label ( 440,
379 HIptr = (instr_item *) new instr_label ( 440,
396 HIptr = (instr_item *) new instr_label( 440,
413 HIptr = (instr_item *) new instr_label( 440,
430 HIptr = (instr_item *) new instr_label( 440,
448 HIptr = (instr_item *) new instr_label( 10,
465 switch( current_options.get_tris_or_culled() ) {
467 HIptr = (instr_item *) new instr_label( 10,
483 HIptr = (instr_item *) new instr_label( 10,
502 HIptr = (instr_item *) new instr_label( 10,
521 if( HIptr ) { // Anything to install?
522 HUD_deque.insert( HUD_deque.begin(), HIptr);
528 return 0; // For now. Later we may use this for an error code.
531 int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
535 FG_LOG( FG_COCKPIT, FG_INFO, "Initializing current aircraft HUD" );
537 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end());
542 // For now lets just hardcode the hud here.
543 // In the future, hud information has to come from the same place
544 // aircraft information came from.
546 // fgHUDSetTimeMode( hud, NIGHT );
547 // fgHUDSetBrightness( hud, BRT_LIGHT );
554 p = new instr_label( 10, 10, 60, 10,
565 HUD_deque.push_front( p );
567 if ( current_options.get_tris_or_culled() == 0 )
568 p = new instr_label( 10, 25, 90, 10,
580 p = new instr_label( 10, 25, 90, 10,
591 HUD_deque.push_front( p );
593 p = new instr_label( 10, 40, 90, 10,
604 HUD_deque.push_front( p );
606 const int x_pos = 480;
607 p = new instr_label( x_pos, 40, 40, 30,
618 HUD_deque.push_front( p );
620 if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
621 strcpy(units, " ft");
625 p = new instr_label( x_pos, 25, 40, 10,
636 HUD_deque.push_front( p );
638 p = new instr_label( x_pos, 10, 60, 10,
649 HUD_deque.push_front( p );
651 return 0; // For now. Later we may use this for an error code.
654 int global_day_night_switch = DAY;
656 void HUD_brightkey( bool incr_bright )
658 instr_item *pHUDInstr = HUD_deque[0];
659 int brightness = pHUDInstr->get_brightness();
661 if( current_options.get_hud_status() ) {
663 switch (brightness) {
665 current_options.set_hud_status(0);
669 brightness = BRT_LIGHT;
673 brightness = BRT_MEDIUM;
677 brightness = BRT_DARK;
681 brightness = BRT_BLACK;
685 switch (brightness) {
687 brightness = BRT_MEDIUM;
691 brightness = BRT_DARK;
695 brightness = BRT_BLACK;
700 current_options.set_hud_status(0);
705 current_options.set_hud_status(1);
707 if( DAY == global_day_night_switch ) {
708 brightness = BRT_BLACK;
711 brightness = BRT_DARK;
712 global_day_night_switch = DAY;
716 if( NIGHT == global_day_night_switch ) {
717 brightness = BRT_DARK;
720 brightness = BRT_MEDIUM;
721 global_day_night_switch = NIGHT;
725 pHUDInstr->SetBrightness( brightness );
730 // Performs a once around the list of calls to instruments installed in
731 // the HUD object with requests for redraw. Kinda. It will when this is
734 void fgUpdateHUD( void ) {
737 // int day_night_sw = current_aircraft.controls->day_night_switch;
738 int day_night_sw = global_day_night_switch;
739 int hud_displays = HUD_deque.size();
740 instr_item *pHUDInstr;
742 if( !hud_displays ) { // Trust everyone, but ALWAYS cut the cards!
746 pHUDInstr = HUD_deque[0];
747 brightness = pHUDInstr->get_brightness();
748 // brightness = HUD_deque.at(0)->get_brightness();
750 glMatrixMode(GL_PROJECTION);
754 gluOrtho2D(0, 640, 0, 480);
755 glMatrixMode(GL_MODELVIEW);
759 glColor3f(1.0, 1.0, 1.0);
762 glDisable(GL_DEPTH_TEST);
763 glDisable(GL_LIGHTING);
767 HudIterator current = HUD_deque.begin();
768 HudIterator last = HUD_deque.end();
770 for ( ; current != last; ++current ) {
771 pHUDInstr = *current;
773 // for( i = hud_displays; i; --i) { // Draw everything
774 // if( HUD_deque.at(i)->enabled()) {
775 // pHUDInstr = HUD_deque[i - 1];
776 if( pHUDInstr->enabled()) {
777 // We should to respond to a dial instead
778 // or as well to the of time of day. Of
779 // course, we have no dial!
780 if( day_night_sw == DAY) {
781 switch (brightness) {
783 glColor3f (0.1, 0.9, 0.1);
787 glColor3f (0.1, 0.7, 0.0);
791 glColor3f (0.0, 0.5, 0.0);
795 glColor3f( 0.0, 0.0, 0.0);
802 if( day_night_sw == NIGHT) {
803 switch (brightness) {
805 glColor3f (0.9, 0.1, 0.1);
809 glColor3f (0.7, 0.0, 0.1);
814 glColor3f (0.5, 0.0, 0.0);
817 else { // Just in case default
818 glColor3f (0.1, 0.9, 0.1);
821 // fgPrintf( FG_COCKPIT, FG_DEBUG, "HUD Code %d Status %d\n",
822 // hud->code, hud->status );
824 // HUD_deque.at(i)->draw(); // Responsible for broken or fixed variants.
825 // No broken displays honored just now.
829 glEnable(GL_DEPTH_TEST);
830 glEnable(GL_LIGHTING);
831 glMatrixMode(GL_PROJECTION);
833 glMatrixMode(GL_MODELVIEW);
838 // Revision 1.32 1999/03/02 01:02:37 curt
839 // Tweaks for building with native SGI compilers.
841 // Revision 1.31 1999/02/02 20:13:31 curt
842 // MSVC++ portability changes by Bernie Bright:
844 // Lib/Serial/serial.[ch]xx: Initial Windows support - incomplete.
845 // Simulator/Astro/stars.cxx: typo? included <stdio> instead of <cstdio>
846 // Simulator/Cockpit/hud.cxx: Added Standard headers
847 // Simulator/Cockpit/panel.cxx: Redefinition of default parameter
848 // Simulator/Flight/flight.cxx: Replaced cout with FG_LOG. Deleted <stdio.h>
849 // Simulator/Main/fg_init.cxx:
850 // Simulator/Main/GLUTmain.cxx:
851 // Simulator/Main/options.hxx: Shuffled <fg_serial.hxx> dependency
852 // Simulator/Objects/material.hxx:
853 // Simulator/Time/timestamp.hxx: VC++ friend kludge
854 // Simulator/Scenery/tile.[ch]xx: Fixed using std::X declarations
855 // Simulator/Main/views.hxx: Added a constant
857 // Revision 1.30 1999/01/27 04:47:52 curt
858 // Make lower end of altitude = -500 so the altimeter is guaged below zero (such
859 // as in death valley.)
861 // Revision 1.29 1998/12/18 23:35:10 curt
862 // Converted to a simpler frame rate counting method.
864 // Revision 1.28 1998/11/23 21:48:59 curt
865 // Borland portability tweaks.
867 // Revision 1.27 1998/11/06 21:17:47 curt
868 // Converted to new logstream debugging facility. This allows release
869 // builds with no messages at all (and no performance impact) by using
870 // the -DFG_NDEBUG flag.
872 // Revision 1.26 1998/11/03 12:33:11 curt
873 // Display ft or m in mini-hud next to altitude.
875 // Revision 1.25 1998/10/17 01:33:57 curt
878 // Revision 1.24 1998/10/16 23:27:25 curt
881 // Revision 1.23 1998/10/16 00:53:00 curt
882 // Mods to display a bit more info when mini-hud is active.
884 // Revision 1.22 1998/09/29 14:56:31 curt
885 // c++-ified comments.
887 // Revision 1.21 1998/09/29 02:01:07 curt
888 // Added a "rate of climb" indicator.
890 // Revision 1.20 1998/08/24 20:05:16 curt
891 // Added a second minimalistic HUD.
892 // Added code to display the number of triangles rendered.
894 // Revision 1.19 1998/07/30 23:44:05 curt
895 // Tweaks for sgi building.
897 // Revision 1.18 1998/07/20 12:47:55 curt
898 // Replace the hud rendering for loop (which linearly searches the the hud
899 // list to find the entry with the proper position) with a simple linear
900 // traversal using an "iterator."
902 // Revision 1.17 1998/07/13 21:28:02 curt
903 // Converted the aoa scale to a radio altimeter.
905 // Revision 1.16 1998/07/13 21:00:47 curt
906 // Integrated Charlies latest HUD updates.
907 // Wrote access functions for current fgOPTIONS.
909 // Revision 1.15 1998/07/08 14:41:08 curt
910 // Renamed polar3d.h to polar3d.hxx
912 // Revision 1.14 1998/07/06 21:31:20 curt
913 // Removed an extraneous ^M.
915 // Revision 1.13 1998/07/03 13:16:28 curt
916 // Added Charlie Hotchkiss's HUD updates and improvementes.
918 // Revision 1.11 1998/06/05 18:17:10 curt
919 // Added the declaration of memmove needed by the stl which apparently
920 // solaris only defines for cc compilations and not for c++ (__STDC__)
922 // Revision 1.10 1998/05/17 16:58:12 curt
923 // Added a View Frustum Culling ratio display to the hud.
925 // Revision 1.9 1998/05/16 13:04:14 curt
926 // New updates from Charlie Hotchkiss.
928 // Revision 1.8 1998/05/13 18:27:54 curt
929 // Added an fov to hud display.
931 // Revision 1.7 1998/05/11 18:13:11 curt
932 // Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
934 // Revision 1.22 1998/04/18 04:14:02 curt
935 // Moved fg_debug.c to it's own library.
937 // Revision 1.21 1998/04/03 21:55:28 curt
938 // Converting to Gnu autoconf system.
941 // Revision 1.20 1998/03/09 22:48:40 curt
942 // Minor "formatting" tweaks.
944 // Revision 1.19 1998/02/23 20:18:28 curt
945 // Incorporated Michele America's hud changes.
947 // Revision 1.18 1998/02/21 14:53:10 curt
948 // Added Charlie's HUD changes.
950 // Revision 1.17 1998/02/20 00:16:21 curt
951 // Thursday's tweaks.
953 // Revision 1.16 1998/02/19 13:05:49 curt
954 // Incorporated some HUD tweaks from Michelle America.
955 // Tweaked the sky's sunset/rise colors.
956 // Other misc. tweaks.
958 // Revision 1.15 1998/02/16 13:38:39 curt
959 // Integrated changes from Charlie Hotchkiss.
961 // Revision 1.14 1998/02/12 21:59:41 curt
962 // Incorporated code changes contributed by Charlie Hotchkiss
963 // <chotchkiss@namg.us.anritsu.com>
965 // Revision 1.12 1998/02/09 15:07:48 curt
968 // Revision 1.11 1998/02/07 15:29:34 curt
969 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
970 // <chotchkiss@namg.us.anritsu.com>
972 // Revision 1.10 1998/02/03 23:20:14 curt
973 // Lots of little tweaks to fix various consistency problems discovered by
974 // Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
975 // passed arguments along to the real printf(). Also incorporated HUD changes
976 // by Michele America.
978 // Revision 1.9 1998/01/31 00:43:04 curt
979 // Added MetroWorks patches from Carmen Volpe.
981 // Revision 1.8 1998/01/27 00:47:51 curt
982 // Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
983 // system and commandline/config file processing code.
985 // Revision 1.7 1998/01/19 18:40:20 curt
986 // Tons of little changes to clean up the code and to remove fatal errors
987 // when building with the c++ compiler.
989 // Revision 1.6 1997/12/15 23:54:34 curt
990 // Add xgl wrappers for debugging.
991 // Generate terrain normals on the fly.
993 // Revision 1.5 1997/12/10 22:37:39 curt
994 // Prepended "fg" on the name of all global structures that didn't have it yet.
995 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
997 // Revision 1.4 1997/09/23 00:29:32 curt
998 // Tweaks to get things to compile with gcc-win32.
1000 // Revision 1.3 1997/09/05 14:17:26 curt
1001 // More tweaking with stars.
1003 // Revision 1.2 1997/09/04 02:17:30 curt
1006 // Revision 1.1 1997/08/29 18:03:22 curt
1007 // Initial revision.