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
43 # include <values.h> // for MAXINT
46 #include <Aircraft/aircraft.hxx>
47 #include <Debug/logstream.hxx>
48 #include <Include/fg_constants.h>
49 #include <Main/options.hxx>
50 #include <Math/fg_random.h>
51 #include <Math/mat3.h>
52 #include <Math/polar3d.hxx>
53 #include <Scenery/scenery.hxx>
54 #include <Time/fg_timer.hxx>
56 #if defined ( __sun__ ) || defined ( __sgi )
58 extern void *memmove(void *, const void *, size_t);
67 // The following routines obtain information concerntin the aircraft's
68 // current state and return it to calling instrument display routines.
69 // They should eventually be member functions of the aircraft.
72 deque< instr_item * > HUD_deque;
78 locRECT( UINT left, UINT top, UINT right, UINT bottom);
79 RECT get_rect(void) { return rect;}
82 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
92 void drawOneLine( UINT x1, UINT y1, UINT x2, UINT y2)
100 void drawOneLine( RECT &rect)
103 glVertex2f(rect.left, rect.top);
104 glVertex2f(rect.right, rect.bottom);
109 // The following code deals with painting the "instrument" on the display
111 /* textString - Bitmap font string */
113 void textString( int x, int y, char *msg, void *font ){
116 glutBitmapCharacter(font, *msg);
121 /* strokeString - Stroke font string */
123 void strokeString(int x, int y, char *msg, void *font, float theta)
129 glRotatef(theta * RAD_TO_DEG, 0.0, 0.0, 1.0);
130 xx = (int)(x * cos(theta) + y * sin( theta ));
131 yy = (int)(y * cos(theta) - x * sin( theta ));
132 glTranslatef( xx, yy, 0);
133 glScalef(.1, .1, 0.0);
135 glutStrokeCharacter(font, *msg);
141 //========================= End of Class Implementations===================
144 // Constructs a HUD object and then adds in instruments. At the present
145 // the instruments are hard coded into the routine. Ultimately these need
146 // to be defined by the aircraft's instrumentation records so that the
147 // display for a Piper Cub doesn't show the speed range of a North American
148 // mustange and the engine readouts of a B36!
153 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
158 FG_LOG( FG_COCKPIT, FG_INFO, "Initializing current aircraft HUD" );
160 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end()); // empty the HUD deque
165 // For now lets just hardcode the hud here.
166 // In the future, hud information has to come from the same place
167 // aircraft information came from.
169 // fgHUDSetTimeMode( hud, NIGHT );
170 // fgHUDSetBrightness( hud, BRT_LIGHT );
177 HIptr = (instr_item *) new fgTBI_instr( 270, 100, 60, 10 );
180 case 1: // Artificial Horizon
181 HIptr = (instr_item *) new HudLadder( 240, 195, 120, 180 );
185 HIptr = (instr_item *) new hud_card( 130,
190 HUDS_LEFT | HUDS_VERT,
201 case 3: // Radio Altimeter
202 HIptr = (instr_item *) new hud_card( 420,
207 HUDS_LEFT | HUDS_VERT,
217 case 4: // GYRO COMPASS
218 HIptr = (instr_item *) new hud_card( 200,
234 HIptr = (instr_item *) new hud_card( 460,
239 HUDS_RIGHT | HUDS_VERT,
250 HIptr = (instr_item *) new guage_instr( 250, // x
254 get_aileronval, // data source
255 HUDS_BOTTOM | HUDS_NOTEXT,
262 HIptr = (instr_item *) new guage_instr( 170, // x
266 get_elevatorval, // data source
267 HUDS_RIGHT | HUDS_VERT | HUDS_NOTEXT,
268 -100.0, // Scale data
274 HIptr = (instr_item *) new guage_instr( 250, // x
278 get_rudderval, // data source
279 HUDS_TOP | HUDS_NOTEXT,
286 HIptr = (instr_item *) new guage_instr( 100, // x
290 get_throttleval, // data source
291 HUDS_VERT | HUDS_RIGHT | HUDS_NOTEXT,
297 case 10: // Digital KIAS
298 HIptr = (instr_item *) new instr_label ( 110,
314 case 11: // Digital Rate of Climb
315 HIptr = (instr_item *) new instr_label ( 110,
331 case 12: // Roll indication diagnostic
332 HIptr = (instr_item *) new instr_label ( 110,
348 case 13: // Angle of attack diagnostic
349 HIptr = (instr_item *) new instr_label ( 440,
366 HIptr = (instr_item *) new instr_label ( 440,
383 HIptr = (instr_item *) new instr_label ( 440,
400 HIptr = (instr_item *) new instr_label( 440,
417 HIptr = (instr_item *) new instr_label( 440,
434 HIptr = (instr_item *) new instr_label( 440,
452 HIptr = (instr_item *) new instr_label( 10,
469 switch( current_options.get_tris_or_culled() ) {
471 HIptr = (instr_item *) new instr_label( 10,
487 HIptr = (instr_item *) new instr_label( 10,
506 HIptr = (instr_item *) new instr_label( 10,
525 if( HIptr ) { // Anything to install?
526 HUD_deque.insert( HUD_deque.begin(), HIptr);
532 return 0; // For now. Later we may use this for an error code.
535 int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
540 FG_LOG( FG_COCKPIT, FG_INFO, "Initializing current aircraft HUD" );
542 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end());
547 // For now lets just hardcode the hud here.
548 // In the future, hud information has to come from the same place
549 // aircraft information came from.
551 // fgHUDSetTimeMode( hud, NIGHT );
552 // fgHUDSetBrightness( hud, BRT_LIGHT );
559 p = new instr_label( 10, 10, 60, 10,
570 HUD_deque.push_front( p );
572 if ( current_options.get_tris_or_culled() == 0 )
573 p = new instr_label( 10, 25, 90, 10,
585 p = new instr_label( 10, 25, 90, 10,
596 HUD_deque.push_front( p );
598 p = new instr_label( 10, 40, 90, 10,
609 HUD_deque.push_front( p );
611 const int x_pos = 480;
612 p = new instr_label( x_pos, 40, 40, 30,
623 HUD_deque.push_front( p );
625 if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
626 strcpy(units, " ft");
630 p = new instr_label( x_pos, 25, 40, 10,
641 HUD_deque.push_front( p );
643 p = new instr_label( x_pos, 10, 60, 10,
654 HUD_deque.push_front( p );
656 return 0; // For now. Later we may use this for an error code.
659 int global_day_night_switch = DAY;
661 void HUD_brightkey( bool incr_bright )
663 instr_item *pHUDInstr = HUD_deque[0];
664 int brightness = pHUDInstr->get_brightness();
666 if( current_options.get_hud_status() ) {
668 switch (brightness) {
670 current_options.set_hud_status(0);
674 brightness = BRT_LIGHT;
678 brightness = BRT_MEDIUM;
682 brightness = BRT_DARK;
686 brightness = BRT_BLACK;
690 switch (brightness) {
692 brightness = BRT_MEDIUM;
696 brightness = BRT_DARK;
700 brightness = BRT_BLACK;
705 current_options.set_hud_status(0);
710 current_options.set_hud_status(1);
712 if( DAY == global_day_night_switch ) {
713 brightness = BRT_BLACK;
716 brightness = BRT_DARK;
717 global_day_night_switch = DAY;
721 if( NIGHT == global_day_night_switch ) {
722 brightness = BRT_DARK;
725 brightness = BRT_MEDIUM;
726 global_day_night_switch = NIGHT;
730 pHUDInstr->SetBrightness( brightness );
735 // Performs a once around the list of calls to instruments installed in
736 // the HUD object with requests for redraw. Kinda. It will when this is
739 void fgUpdateHUD( void ) {
742 // int day_night_sw = current_aircraft.controls->day_night_switch;
743 int day_night_sw = global_day_night_switch;
744 int hud_displays = HUD_deque.size();
745 instr_item *pHUDInstr;
747 if( !hud_displays ) { // Trust everyone, but ALWAYS cut the cards!
751 pHUDInstr = HUD_deque[0];
752 brightness = pHUDInstr->get_brightness();
753 // brightness = HUD_deque.at(0)->get_brightness();
755 glMatrixMode(GL_PROJECTION);
759 gluOrtho2D(0, 640, 0, 480);
760 glMatrixMode(GL_MODELVIEW);
764 glColor3f(1.0, 1.0, 1.0);
767 glDisable(GL_DEPTH_TEST);
768 glDisable(GL_LIGHTING);
772 deque < instr_item * > :: iterator current = HUD_deque.begin();
773 deque < instr_item * > :: iterator last = HUD_deque.end();
775 for ( ; current != last; ++current ) {
776 pHUDInstr = *current;
778 // for( i = hud_displays; i; --i) { // Draw everything
779 // if( HUD_deque.at(i)->enabled()) {
780 // pHUDInstr = HUD_deque[i - 1];
781 if( pHUDInstr->enabled()) {
782 // We should to respond to a dial instead
783 // or as well to the of time of day. Of
784 // course, we have no dial!
785 if( day_night_sw == DAY) {
786 switch (brightness) {
788 glColor3f (0.1, 0.9, 0.1);
792 glColor3f (0.1, 0.7, 0.0);
796 glColor3f (0.0, 0.5, 0.0);
800 glColor3f( 0.0, 0.0, 0.0);
807 if( day_night_sw == NIGHT) {
808 switch (brightness) {
810 glColor3f (0.9, 0.1, 0.1);
814 glColor3f (0.7, 0.0, 0.1);
819 glColor3f (0.5, 0.0, 0.0);
822 else { // Just in case default
823 glColor3f (0.1, 0.9, 0.1);
826 // fgPrintf( FG_COCKPIT, FG_DEBUG, "HUD Code %d Status %d\n",
827 // hud->code, hud->status );
829 // HUD_deque.at(i)->draw(); // Responsible for broken or fixed variants.
830 // No broken displays honored just now.
834 glEnable(GL_DEPTH_TEST);
835 glEnable(GL_LIGHTING);
836 glMatrixMode(GL_PROJECTION);
838 glMatrixMode(GL_MODELVIEW);
843 // Revision 1.29 1998/12/18 23:35:10 curt
844 // Converted to a simpler frame rate counting method.
846 // Revision 1.28 1998/11/23 21:48:59 curt
847 // Borland portability tweaks.
849 // Revision 1.27 1998/11/06 21:17:47 curt
850 // Converted to new logstream debugging facility. This allows release
851 // builds with no messages at all (and no performance impact) by using
852 // the -DFG_NDEBUG flag.
854 // Revision 1.26 1998/11/03 12:33:11 curt
855 // Display ft or m in mini-hud next to altitude.
857 // Revision 1.25 1998/10/17 01:33:57 curt
860 // Revision 1.24 1998/10/16 23:27:25 curt
863 // Revision 1.23 1998/10/16 00:53:00 curt
864 // Mods to display a bit more info when mini-hud is active.
866 // Revision 1.22 1998/09/29 14:56:31 curt
867 // c++-ified comments.
869 // Revision 1.21 1998/09/29 02:01:07 curt
870 // Added a "rate of climb" indicator.
872 // Revision 1.20 1998/08/24 20:05:16 curt
873 // Added a second minimalistic HUD.
874 // Added code to display the number of triangles rendered.
876 // Revision 1.19 1998/07/30 23:44:05 curt
877 // Tweaks for sgi building.
879 // Revision 1.18 1998/07/20 12:47:55 curt
880 // Replace the hud rendering for loop (which linearly searches the the hud
881 // list to find the entry with the proper position) with a simple linear
882 // traversal using an "iterator."
884 // Revision 1.17 1998/07/13 21:28:02 curt
885 // Converted the aoa scale to a radio altimeter.
887 // Revision 1.16 1998/07/13 21:00:47 curt
888 // Integrated Charlies latest HUD updates.
889 // Wrote access functions for current fgOPTIONS.
891 // Revision 1.15 1998/07/08 14:41:08 curt
892 // Renamed polar3d.h to polar3d.hxx
894 // Revision 1.14 1998/07/06 21:31:20 curt
895 // Removed an extraneous ^M.
897 // Revision 1.13 1998/07/03 13:16:28 curt
898 // Added Charlie Hotchkiss's HUD updates and improvementes.
900 // Revision 1.11 1998/06/05 18:17:10 curt
901 // Added the declaration of memmove needed by the stl which apparently
902 // solaris only defines for cc compilations and not for c++ (__STDC__)
904 // Revision 1.10 1998/05/17 16:58:12 curt
905 // Added a View Frustum Culling ratio display to the hud.
907 // Revision 1.9 1998/05/16 13:04:14 curt
908 // New updates from Charlie Hotchkiss.
910 // Revision 1.8 1998/05/13 18:27:54 curt
911 // Added an fov to hud display.
913 // Revision 1.7 1998/05/11 18:13:11 curt
914 // Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
916 // Revision 1.22 1998/04/18 04:14:02 curt
917 // Moved fg_debug.c to it's own library.
919 // Revision 1.21 1998/04/03 21:55:28 curt
920 // Converting to Gnu autoconf system.
923 // Revision 1.20 1998/03/09 22:48:40 curt
924 // Minor "formatting" tweaks.
926 // Revision 1.19 1998/02/23 20:18:28 curt
927 // Incorporated Michele America's hud changes.
929 // Revision 1.18 1998/02/21 14:53:10 curt
930 // Added Charlie's HUD changes.
932 // Revision 1.17 1998/02/20 00:16:21 curt
933 // Thursday's tweaks.
935 // Revision 1.16 1998/02/19 13:05:49 curt
936 // Incorporated some HUD tweaks from Michelle America.
937 // Tweaked the sky's sunset/rise colors.
938 // Other misc. tweaks.
940 // Revision 1.15 1998/02/16 13:38:39 curt
941 // Integrated changes from Charlie Hotchkiss.
943 // Revision 1.14 1998/02/12 21:59:41 curt
944 // Incorporated code changes contributed by Charlie Hotchkiss
945 // <chotchkiss@namg.us.anritsu.com>
947 // Revision 1.12 1998/02/09 15:07:48 curt
950 // Revision 1.11 1998/02/07 15:29:34 curt
951 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
952 // <chotchkiss@namg.us.anritsu.com>
954 // Revision 1.10 1998/02/03 23:20:14 curt
955 // Lots of little tweaks to fix various consistency problems discovered by
956 // Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
957 // passed arguments along to the real printf(). Also incorporated HUD changes
958 // by Michele America.
960 // Revision 1.9 1998/01/31 00:43:04 curt
961 // Added MetroWorks patches from Carmen Volpe.
963 // Revision 1.8 1998/01/27 00:47:51 curt
964 // Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
965 // system and commandline/config file processing code.
967 // Revision 1.7 1998/01/19 18:40:20 curt
968 // Tons of little changes to clean up the code and to remove fatal errors
969 // when building with the c++ compiler.
971 // Revision 1.6 1997/12/15 23:54:34 curt
972 // Add xgl wrappers for debugging.
973 // Generate terrain normals on the fly.
975 // Revision 1.5 1997/12/10 22:37:39 curt
976 // Prepended "fg" on the name of all global structures that didn't have it yet.
977 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
979 // Revision 1.4 1997/09/23 00:29:32 curt
980 // Tweaks to get things to compile with gcc-win32.
982 // Revision 1.3 1997/09/05 14:17:26 curt
983 // More tweaking with stars.
985 // Revision 1.2 1997/09/04 02:17:30 curt
988 // Revision 1.1 1997/08/29 18:03:22 curt