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)
38 # include <values.h> // for MAXINT
41 #include <Aircraft/aircraft.hxx>
42 #include <Debug/fg_debug.h>
43 #include <Include/fg_constants.h>
44 #include <Main/options.hxx>
45 #include <Math/fg_random.h>
46 #include <Math/mat3.h>
47 #include <Math/polar3d.hxx>
48 #include <Scenery/scenery.hxx>
49 #include <Time/fg_timer.hxx>
51 #if defined ( __sun__ ) || defined ( __sgi )
53 extern void *memmove(void *, const void *, size_t);
61 // The following routines obtain information concerntin the aircraft's
62 // current state and return it to calling instrument display routines.
63 // They should eventually be member functions of the aircraft.
66 deque< instr_item * > HUD_deque;
72 locRECT( UINT left, UINT top, UINT right, UINT bottom);
73 RECT get_rect(void) { return rect;}
76 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
86 void drawOneLine( UINT x1, UINT y1, UINT x2, UINT y2)
94 void drawOneLine( RECT &rect)
97 glVertex2f(rect.left, rect.top);
98 glVertex2f(rect.right, rect.bottom);
103 // The following code deals with painting the "instrument" on the display
105 /* textString - Bitmap font string */
107 void textString( int x, int y, char *msg, void *font ){
110 glutBitmapCharacter(font, *msg);
115 /* strokeString - Stroke font string */
117 void strokeString(int x, int y, char *msg, void *font, float theta)
123 glRotatef(theta * RAD_TO_DEG, 0.0, 0.0, 1.0);
124 xx = (int)(x * cos(theta) + y * sin( theta ));
125 yy = (int)(y * cos(theta) - x * sin( theta ));
126 glTranslatef( xx, yy, 0);
127 glScalef(.1, .1, 0.0);
129 glutStrokeCharacter(font, *msg);
135 //========================= End of Class Implementations===================
138 // Constructs a HUD object and then adds in instruments. At the present
139 // the instruments are hard coded into the routine. Ultimately these need
140 // to be defined by the aircraft's instrumentation records so that the
141 // display for a Piper Cub doesn't show the speed range of a North American
142 // mustange and the engine readouts of a B36!
147 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
152 fgPrintf( FG_COCKPIT, FG_INFO, "Initializing current aircraft HUD\n" );
154 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end()); // empty the HUD deque
159 // For now lets just hardcode the hud here.
160 // In the future, hud information has to come from the same place
161 // aircraft information came from.
163 // fgHUDSetTimeMode( hud, NIGHT );
164 // fgHUDSetBrightness( hud, BRT_LIGHT );
171 HIptr = (instr_item *) new fgTBI_instr( 270, 100, 60, 10 );
174 case 1: // Artificial Horizon
175 HIptr = (instr_item *) new HudLadder( 240, 195, 120, 180 );
179 HIptr = (instr_item *) new hud_card( 130,
184 HUDS_LEFT | HUDS_VERT,
195 case 3: // Radio Altimeter
196 HIptr = (instr_item *) new hud_card( 420,
201 HUDS_LEFT | HUDS_VERT,
211 case 4: // GYRO COMPASS
212 HIptr = (instr_item *) new hud_card( 200,
228 HIptr = (instr_item *) new hud_card( 460,
233 HUDS_RIGHT | HUDS_VERT,
244 HIptr = (instr_item *) new guage_instr( 250, // x
248 get_aileronval, // data source
249 HUDS_BOTTOM | HUDS_NOTEXT,
256 HIptr = (instr_item *) new guage_instr( 170, // x
260 get_elevatorval, // data source
261 HUDS_RIGHT | HUDS_VERT | HUDS_NOTEXT,
262 -100.0, // Scale data
268 HIptr = (instr_item *) new guage_instr( 250, // x
272 get_rudderval, // data source
273 HUDS_TOP | HUDS_NOTEXT,
280 HIptr = (instr_item *) new guage_instr( 100, // x
284 get_throttleval, // data source
285 HUDS_VERT | HUDS_RIGHT | HUDS_NOTEXT,
291 case 10: // Digital KIAS
292 HIptr = (instr_item *) new instr_label ( 110,
308 case 11: // Digital Rate of Climb
309 HIptr = (instr_item *) new instr_label ( 110,
325 case 12: // Roll indication diagnostic
326 HIptr = (instr_item *) new instr_label ( 110,
342 case 13: // Angle of attack diagnostic
343 HIptr = (instr_item *) new instr_label ( 440,
360 HIptr = (instr_item *) new instr_label ( 440,
377 HIptr = (instr_item *) new instr_label ( 440,
394 HIptr = (instr_item *) new instr_label( 440,
411 HIptr = (instr_item *) new instr_label( 440,
428 HIptr = (instr_item *) new instr_label( 440,
446 HIptr = (instr_item *) new instr_label( 10,
463 switch( current_options.get_tris_or_culled() ) {
465 HIptr = (instr_item *) new instr_label( 10,
481 HIptr = (instr_item *) new instr_label( 10,
500 HIptr = (instr_item *) new instr_label( 10,
519 if( HIptr ) { // Anything to install?
520 HUD_deque.insert( HUD_deque.begin(), HIptr);
526 return 0; // For now. Later we may use this for an error code.
529 int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
534 fgPrintf( FG_COCKPIT, FG_INFO, "Initializing current aircraft HUD\n" );
536 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end());
541 // For now lets just hardcode the hud here.
542 // In the future, hud information has to come from the same place
543 // aircraft information came from.
545 // fgHUDSetTimeMode( hud, NIGHT );
546 // fgHUDSetBrightness( hud, BRT_LIGHT );
553 p = new instr_label( 10, 10, 60, 10,
564 HUD_deque.push_front( p );
566 if ( current_options.get_tris_or_culled() == 0 )
567 p = new instr_label( 10, 25, 90, 10,
579 p = new instr_label( 10, 25, 90, 10,
590 HUD_deque.push_front( p );
592 p = new instr_label( 10, 40, 90, 10,
603 HUD_deque.push_front( p );
605 const int x_pos = 480;
606 p = new instr_label( x_pos, 40, 40, 30,
617 HUD_deque.push_front( p );
619 p = new instr_label( x_pos, 25, 40, 10,
630 HUD_deque.push_front( p );
632 p = new instr_label( x_pos, 10, 60, 10,
643 HUD_deque.push_front( p );
645 return 0; // For now. Later we may use this for an error code.
648 int global_day_night_switch = DAY;
650 void HUD_brightkey( bool incr_bright )
652 instr_item *pHUDInstr = HUD_deque[0];
653 int brightness = pHUDInstr->get_brightness();
655 if( current_options.get_hud_status() ) {
657 switch (brightness) {
659 current_options.set_hud_status(0);
663 brightness = BRT_LIGHT;
667 brightness = BRT_MEDIUM;
671 brightness = BRT_DARK;
675 brightness = BRT_BLACK;
679 switch (brightness) {
681 brightness = BRT_MEDIUM;
685 brightness = BRT_DARK;
689 brightness = BRT_BLACK;
694 current_options.set_hud_status(0);
699 current_options.set_hud_status(1);
701 if( DAY == global_day_night_switch ) {
702 brightness = BRT_BLACK;
705 brightness = BRT_DARK;
706 global_day_night_switch = DAY;
710 if( NIGHT == global_day_night_switch ) {
711 brightness = BRT_DARK;
714 brightness = BRT_MEDIUM;
715 global_day_night_switch = NIGHT;
719 pHUDInstr->SetBrightness( brightness );
724 // Performs a once around the list of calls to instruments installed in
725 // the HUD object with requests for redraw. Kinda. It will when this is
728 void fgUpdateHUD( void ) {
731 // int day_night_sw = current_aircraft.controls->day_night_switch;
732 int day_night_sw = global_day_night_switch;
733 int hud_displays = HUD_deque.size();
734 instr_item *pHUDInstr;
736 if( !hud_displays ) { // Trust everyone, but ALWAYS cut the cards!
740 pHUDInstr = HUD_deque[0];
741 brightness = pHUDInstr->get_brightness();
742 // brightness = HUD_deque.at(0)->get_brightness();
744 glMatrixMode(GL_PROJECTION);
748 gluOrtho2D(0, 640, 0, 480);
749 glMatrixMode(GL_MODELVIEW);
753 glColor3f(1.0, 1.0, 1.0);
756 glDisable(GL_DEPTH_TEST);
757 glDisable(GL_LIGHTING);
761 deque < instr_item * > :: iterator current = HUD_deque.begin();
762 deque < instr_item * > :: iterator last = HUD_deque.end();
764 for ( ; current != last; ++current ) {
765 pHUDInstr = *current;
767 // for( i = hud_displays; i; --i) { // Draw everything
768 // if( HUD_deque.at(i)->enabled()) {
769 // pHUDInstr = HUD_deque[i - 1];
770 if( pHUDInstr->enabled()) {
771 // We should to respond to a dial instead
772 // or as well to the of time of day. Of
773 // course, we have no dial!
774 if( day_night_sw == DAY) {
775 switch (brightness) {
777 glColor3f (0.1, 0.9, 0.1);
781 glColor3f (0.1, 0.7, 0.0);
785 glColor3f (0.0, 0.5, 0.0);
789 glColor3f( 0.0, 0.0, 0.0);
796 if( day_night_sw == NIGHT) {
797 switch (brightness) {
799 glColor3f (0.9, 0.1, 0.1);
803 glColor3f (0.7, 0.0, 0.1);
808 glColor3f (0.5, 0.0, 0.0);
811 else { // Just in case default
812 glColor3f (0.1, 0.9, 0.1);
815 // fgPrintf( FG_COCKPIT, FG_DEBUG, "HUD Code %d Status %d\n",
816 // hud->code, hud->status );
818 // HUD_deque.at(i)->draw(); // Responsible for broken or fixed variants.
819 // No broken displays honored just now.
823 glEnable(GL_DEPTH_TEST);
824 glEnable(GL_LIGHTING);
825 glMatrixMode(GL_PROJECTION);
827 glMatrixMode(GL_MODELVIEW);
832 // Revision 1.25 1998/10/17 01:33:57 curt
835 // Revision 1.24 1998/10/16 23:27:25 curt
838 // Revision 1.23 1998/10/16 00:53:00 curt
839 // Mods to display a bit more info when mini-hud is active.
841 // Revision 1.22 1998/09/29 14:56:31 curt
842 // c++-ified comments.
844 // Revision 1.21 1998/09/29 02:01:07 curt
845 // Added a "rate of climb" indicator.
847 // Revision 1.20 1998/08/24 20:05:16 curt
848 // Added a second minimalistic HUD.
849 // Added code to display the number of triangles rendered.
851 // Revision 1.19 1998/07/30 23:44:05 curt
852 // Tweaks for sgi building.
854 // Revision 1.18 1998/07/20 12:47:55 curt
855 // Replace the hud rendering for loop (which linearly searches the the hud
856 // list to find the entry with the proper position) with a simple linear
857 // traversal using an "iterator."
859 // Revision 1.17 1998/07/13 21:28:02 curt
860 // Converted the aoa scale to a radio altimeter.
862 // Revision 1.16 1998/07/13 21:00:47 curt
863 // Integrated Charlies latest HUD updates.
864 // Wrote access functions for current fgOPTIONS.
866 // Revision 1.15 1998/07/08 14:41:08 curt
867 // Renamed polar3d.h to polar3d.hxx
869 // Revision 1.14 1998/07/06 21:31:20 curt
870 // Removed an extraneous ^M.
872 // Revision 1.13 1998/07/03 13:16:28 curt
873 // Added Charlie Hotchkiss's HUD updates and improvementes.
875 // Revision 1.11 1998/06/05 18:17:10 curt
876 // Added the declaration of memmove needed by the stl which apparently
877 // solaris only defines for cc compilations and not for c++ (__STDC__)
879 // Revision 1.10 1998/05/17 16:58:12 curt
880 // Added a View Frustum Culling ratio display to the hud.
882 // Revision 1.9 1998/05/16 13:04:14 curt
883 // New updates from Charlie Hotchkiss.
885 // Revision 1.8 1998/05/13 18:27:54 curt
886 // Added an fov to hud display.
888 // Revision 1.7 1998/05/11 18:13:11 curt
889 // Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
891 // Revision 1.22 1998/04/18 04:14:02 curt
892 // Moved fg_debug.c to it's own library.
894 // Revision 1.21 1998/04/03 21:55:28 curt
895 // Converting to Gnu autoconf system.
898 // Revision 1.20 1998/03/09 22:48:40 curt
899 // Minor "formatting" tweaks.
901 // Revision 1.19 1998/02/23 20:18:28 curt
902 // Incorporated Michele America's hud changes.
904 // Revision 1.18 1998/02/21 14:53:10 curt
905 // Added Charlie's HUD changes.
907 // Revision 1.17 1998/02/20 00:16:21 curt
908 // Thursday's tweaks.
910 // Revision 1.16 1998/02/19 13:05:49 curt
911 // Incorporated some HUD tweaks from Michelle America.
912 // Tweaked the sky's sunset/rise colors.
913 // Other misc. tweaks.
915 // Revision 1.15 1998/02/16 13:38:39 curt
916 // Integrated changes from Charlie Hotchkiss.
918 // Revision 1.14 1998/02/12 21:59:41 curt
919 // Incorporated code changes contributed by Charlie Hotchkiss
920 // <chotchkiss@namg.us.anritsu.com>
922 // Revision 1.12 1998/02/09 15:07:48 curt
925 // Revision 1.11 1998/02/07 15:29:34 curt
926 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
927 // <chotchkiss@namg.us.anritsu.com>
929 // Revision 1.10 1998/02/03 23:20:14 curt
930 // Lots of little tweaks to fix various consistency problems discovered by
931 // Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
932 // passed arguments along to the real printf(). Also incorporated HUD changes
933 // by Michele America.
935 // Revision 1.9 1998/01/31 00:43:04 curt
936 // Added MetroWorks patches from Carmen Volpe.
938 // Revision 1.8 1998/01/27 00:47:51 curt
939 // Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
940 // system and commandline/config file processing code.
942 // Revision 1.7 1998/01/19 18:40:20 curt
943 // Tons of little changes to clean up the code and to remove fatal errors
944 // when building with the c++ compiler.
946 // Revision 1.6 1997/12/15 23:54:34 curt
947 // Add xgl wrappers for debugging.
948 // Generate terrain normals on the fly.
950 // Revision 1.5 1997/12/10 22:37:39 curt
951 // Prepended "fg" on the name of all global structures that didn't have it yet.
952 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
954 // Revision 1.4 1997/09/23 00:29:32 curt
955 // Tweaks to get things to compile with gcc-win32.
957 // Revision 1.3 1997/09/05 14:17:26 curt
958 // More tweaking with stars.
960 // Revision 1.2 1997/09/04 02:17:30 curt
963 // Revision 1.1 1997/08/29 18:03:22 curt