1 // GLUTkey.cxx -- handle GLUT keyboard events
3 // Written by Curtis Olson, started May 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@me.umn.edu
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 <Aircraft/aircraft.h>
39 #include <Astro/solarsystem.hxx>
40 #include <Astro/sky.hxx>
41 #include <Autopilot/autopilot.hxx>
42 #include <Cockpit/hud.hxx>
43 #include <Debug/fg_debug.h>
45 #include <Include/fg_constants.h>
46 #include <Objects/material.hxx>
48 #include <Time/light.hxx>
49 #include <Weather/weather.h>
51 #include "GLUTkey.hxx"
52 #include "options.hxx"
55 #if defined(FX) && defined(XMESA)
56 # include <GL/xmesa.h>
57 static int fullscreen = 1;
61 // Force an update of the sky and lighting parameters
62 static void local_update_sky_and_lighting_params( void ) {
64 SolarSystem::theSolarSystem->rebuild();
65 cur_light_params.Update();
70 // Handle keyboard events
71 void GLUTkey(unsigned char k, int x, int y) {
79 c = current_aircraft.controls;
80 f = current_aircraft.flight;
85 fgPrintf( FG_INPUT, FG_DEBUG, "Key hit = %d", k);
86 puKeyboard(k, PU_DOWN );
88 if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
89 fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
97 case 19: // Ctrl-S key
98 fgAPToggleAutoThrottle();
100 case 20: // Ctrl-T key
101 fgAPToggleTerrainFollow();
103 case 49: // numeric keypad 1
104 v->goal_view_offset = FG_PI * 0.75;
106 case 50: // numeric keypad 2
107 v->goal_view_offset = FG_PI;
109 case 51: // numeric keypad 3
110 v->goal_view_offset = FG_PI * 1.25;
112 case 52: // numeric keypad 4
113 v->goal_view_offset = FG_PI * 0.50;
115 case 54: // numeric keypad 6
116 v->goal_view_offset = FG_PI * 1.50;
118 case 55: // numeric keypad 7
119 v->goal_view_offset = FG_PI * 0.25;
121 case 56: // numeric keypad 8
122 v->goal_view_offset = 0.00;
124 case 57: // numeric keypad 9
125 v->goal_view_offset = FG_PI * 1.75;
128 // status = current_options.get_hud_status();
129 // current_options.set_hud_status(!status);
130 HUD_brightkey( true );
134 fgHUDInit2(¤t_aircraft);
138 local_update_sky_and_lighting_params();
142 local_update_sky_and_lighting_params();
145 #if defined(FX) && !defined(WIN32)
146 fullscreen = ( !fullscreen );
147 #if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
148 XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW);
153 fov = current_options.get_fov();
155 if ( fov > FG_FOV_MAX ) {
158 current_options.set_fov(fov);
159 v->update_fov = TRUE;
162 tmp = fgWeatherGetVisibility(); // in meters
164 fgWeatherSetVisibility( tmp );
168 fgPrintf( FG_INPUT, FG_DEBUG, "\n");
170 case 50: // numeric keypad 2
173 case 56: // numeric keypad 8
176 case 49: // numeric keypad 1
177 fgElevTrimMove(-0.001);
179 case 55: // numeric keypad 7
180 fgElevTrimMove(0.001);
182 case 52: // numeric keypad 4
183 fgAileronMove(-0.05);
185 case 54: // numeric keypad 6
188 case 48: // numeric keypad Ins
191 case 13: // numeric keypad Enter
194 case 53: // numeric keypad 5
199 case 57: // numeric keypad 9 (Pg Up)
200 fgThrottleMove(0, 0.01);
202 case 51: // numeric keypad 3 (Pg Dn)
203 fgThrottleMove(0, -0.01);
208 b_ret = int( fgBrakeGet() );
209 b_set = double(!b_ret);
213 HUD_brightkey( false );
216 fgHUDInit(¤t_aircraft); // normal HUD
220 local_update_sky_and_lighting_params();
223 t->pause = !t->pause;
224 // printf position and attitude information
225 fgPrintf( FG_INPUT, FG_INFO,
226 "Lon = %.4f Lat = %.4f Altitude = %.1f\n",
227 FG_Longitude * RAD_TO_DEG,
228 FG_Latitude * RAD_TO_DEG,
229 FG_Altitude * FEET_TO_METER);
230 fgPrintf( FG_INPUT, FG_INFO,
231 "Heading = %.2f Roll = %.2f Pitch = %.2f\n",
234 FG_Theta * RAD_TO_DEG);
238 local_update_sky_and_lighting_params();
241 fov = current_options.get_fov();
243 if ( fov < FG_FOV_MIN ) {
246 current_options.set_fov(fov);
247 v->update_fov = TRUE;
250 tmp = fgWeatherGetVisibility(); // in meters
252 fgWeatherSetVisibility( tmp );
255 // if( fg_DebugOutput ) {
256 // fclose( fg_DebugOutput );
258 fgPrintf( FG_INPUT, FG_EXIT,
259 "Program exiting normally at user request.\n");
265 // Handle "special" keyboard events
266 void GLUTspecialkey(int k, int x, int y) {
270 c = current_aircraft.controls;
273 fgPrintf( FG_INPUT, FG_DEBUG, "Special key hit = %d", k);
274 puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN);
276 if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
277 fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
279 case GLUT_KEY_END: // numeric keypad 1
280 v->goal_view_offset = FG_PI * 0.75;
282 case GLUT_KEY_DOWN: // numeric keypad 2
283 v->goal_view_offset = FG_PI;
285 case GLUT_KEY_PAGE_DOWN: // numeric keypad 3
286 v->goal_view_offset = FG_PI * 1.25;
288 case GLUT_KEY_LEFT: // numeric keypad 4
289 v->goal_view_offset = FG_PI * 0.50;
291 case GLUT_KEY_RIGHT: // numeric keypad 6
292 v->goal_view_offset = FG_PI * 1.50;
294 case GLUT_KEY_HOME: // numeric keypad 7
295 v->goal_view_offset = FG_PI * 0.25;
297 case GLUT_KEY_UP: // numeric keypad 8
298 v->goal_view_offset = 0.00;
300 case GLUT_KEY_PAGE_UP: // numeric keypad 9
301 v->goal_view_offset = FG_PI * 1.75;
305 fgPrintf( FG_INPUT, FG_DEBUG, "\n");
307 case GLUT_KEY_F8: // F8 toggles fog ... off fastest nicest...
308 current_options.cycle_fog();
310 if ( current_options.get_fog() == fgOPTIONS::FG_FOG_DISABLED ) {
311 fgPrintf( FG_INPUT, FG_INFO, "Fog disabled\n" );
312 } else if ( current_options.get_fog() ==
313 fgOPTIONS::FG_FOG_FASTEST )
315 fgPrintf( FG_INPUT, FG_INFO,
316 "Fog enabled, hint set to fastest\n" );
317 } else if ( current_options.get_fog() ==
318 fgOPTIONS::FG_FOG_NICEST )
320 fgPrintf( FG_INPUT, FG_INFO,
321 "Fog enabled, hint set to nicest\n" );
325 case GLUT_KEY_F9: // F9 toggles textures on and off...
326 if ( material_mgr.get_textures_loaded() ) {
327 current_options.get_textures() ?
328 current_options.set_textures(false) :
329 current_options.set_textures(true);
330 fgPrintf( FG_INPUT, FG_INFO, "Toggling texture\n" );
332 fgPrintf( FG_INPUT, FG_INFO,
333 "No textures loaded, cannot toggle\n" );
336 case GLUT_KEY_F10: // F10 toggles menu on and off...
337 fgPrintf(FG_INPUT, FG_INFO, "Invoking call back function");
339 setValue ((int) !(hideMenuButton -> getValue() ) );
340 hideMenuButton -> invokeCallback();
350 fgAileronMove(-0.05);
355 case GLUT_KEY_HOME: // numeric keypad 1
356 fgElevTrimMove(0.001);
358 case GLUT_KEY_END: // numeric keypad 7
359 fgElevTrimMove(-0.001);
361 case GLUT_KEY_INSERT: // numeric keypad Ins
364 case 13: // numeric keypad Enter
367 case 53: // numeric keypad 5
372 case GLUT_KEY_PAGE_UP: // numeric keypad 9 (Pg Up)
373 fgThrottleMove(0, 0.01);
375 case GLUT_KEY_PAGE_DOWN: // numeric keypad 3 (Pg Dn)
376 fgThrottleMove(0, -0.01);
384 // Revision 1.27 1998/10/02 12:46:46 curt
385 // Added an "auto throttle"
387 // Revision 1.26 1998/10/01 00:38:04 curt
388 // More altitude hold tweaks.
390 // Revision 1.25 1998/09/29 02:03:36 curt
393 // Revision 1.24 1998/09/26 13:16:44 curt
394 // C++-ified the comments.
396 // Revision 1.23 1998/09/17 18:35:30 curt
397 // Added F8 to toggle fog and F9 to toggle texturing.
399 // Revision 1.22 1998/09/15 04:27:27 curt
400 // Changes for new Astro code.
402 // Revision 1.21 1998/08/29 13:09:25 curt
403 // Changes to event manager from Bernie Bright.
405 // Revision 1.20 1998/08/24 20:11:12 curt
406 // Added i/I to toggle full vs. minimal HUD.
407 // Added a --hud-tris vs --hud-culled option.
408 // Moved options accessor funtions to options.hxx.
410 // Revision 1.19 1998/08/05 00:19:33 curt
411 // Added a local routine to update lighting params every frame when time is
414 // Revision 1.18 1998/07/30 23:48:24 curt
415 // Output position & orientation when pausing.
416 // Eliminated libtool use.
417 // Added options to specify initial position and orientation.
418 // Changed default fov to 55 degrees.
419 // Added command line option to start in paused or unpaused state.
421 // Revision 1.17 1998/07/27 18:41:23 curt
422 // Added a pause command "p"
423 // Fixed some initialization order problems between pui and glut.
424 // Added an --enable/disable-sound option.
426 // Revision 1.16 1998/07/16 17:33:34 curt
427 // "H" / "h" now control hud brightness as well with off being one of the
429 // Better checking for xmesa/fx 3dfx fullscreen/window support for deciding
430 // whether or not to build in the feature.
431 // Translucent menu support.
432 // HAVE_AUDIO_SUPPORT -> ENABLE_AUDIO_SUPPORT
433 // Use fork() / wait() for playing mp3 init music in background under unix.
434 // Changed default tile diameter to 5.
436 // Revision 1.15 1998/07/13 21:01:34 curt
437 // Wrote access functions for current fgOPTIONS.
439 // Revision 1.14 1998/07/06 02:42:02 curt
440 // Added support for switching between fullscreen and window mode for
443 // Added a basic splash screen. Restructured the main loop and top level
444 // initialization routines to do this.
446 // Hacked in some support for playing a startup mp3 sound file while rest
447 // of sim initializes. Currently only works in Unix using the mpg123 player.
448 // Waits for the mpg123 player to finish before initializing internal
451 // Revision 1.13 1998/06/27 16:54:32 curt
452 // Replaced "extern displayInstruments" with a entry in fgOPTIONS.
453 // Don't change the view port when displaying the panel.
455 // Revision 1.12 1998/06/12 14:27:26 curt
456 // Pui -> PUI, Gui -> GUI.
458 // Revision 1.11 1998/06/12 00:57:38 curt
459 // Added support for Pui/Gui.
460 // Converted fog to GL_FOG_EXP2.
461 // Link to static simulator parts.
462 // Update runfg.bat to try to be a little smarter.
464 // Revision 1.10 1998/05/27 02:24:05 curt
465 // View optimizations by Norman Vine.
467 // Revision 1.9 1998/05/16 13:05:21 curt
468 // Added limits to fov.
470 // Revision 1.8 1998/05/13 18:29:56 curt
471 // Added a keyboard binding to dynamically adjust field of view.
472 // Added a command line option to specify fov.
473 // Adjusted terrain color.
474 // Root path info moved to fgOPTIONS.
475 // Added ability to parse options out of a config file.
477 // Revision 1.7 1998/05/07 23:14:14 curt
478 // Added "D" key binding to set autopilot heading.
479 // Made frame rate calculation average out over last 10 frames.
480 // Borland C++ floating point exception workaround.
481 // Added a --tile-radius=n option.
483 // Revision 1.6 1998/04/28 01:20:20 curt
484 // Type-ified fgTIME and fgVIEW.
485 // Added a command line option to disable textures.
487 // Revision 1.5 1998/04/25 22:06:29 curt
488 // Edited cvs log messages in source files ... bad bad bad!
490 // Revision 1.4 1998/04/25 20:24:00 curt
491 // Cleaned up initialization sequence to eliminate interdependencies
492 // between sun position, lighting, and view position. This creates a
493 // valid single pass initialization path.
495 // Revision 1.3 1998/04/24 14:19:29 curt
498 // Revision 1.2 1998/04/24 00:49:17 curt
499 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
500 // Trying out some different option parsing code.
501 // Some code reorganization.
503 // Revision 1.1 1998/04/22 13:25:40 curt
504 // C++ - ifing the code.
505 // Starting a bit of reorganization of lighting code.
507 // Revision 1.33 1998/04/18 04:11:25 curt
508 // Moved fg_debug to it's own library, added zlib support.
510 // Revision 1.32 1998/04/14 02:21:01 curt
511 // Incorporated autopilot heading hold contributed by: Jeff Goeke-Smith
512 // <jgoeke@voyager.net>
514 // Revision 1.31 1998/04/08 23:34:05 curt
515 // Patch from Durk to fix trim reversal with numlock key active.
517 // Revision 1.30 1998/04/03 22:09:02 curt
518 // Converting to Gnu autoconf system.
520 // Revision 1.29 1998/02/07 15:29:40 curt
521 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
522 // <chotchkiss@namg.us.anritsu.com>
524 // Revision 1.28 1998/02/03 23:20:23 curt
525 // Lots of little tweaks to fix various consistency problems discovered by
526 // Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
527 // passed arguments along to the real printf(). Also incorporated HUD changes
528 // by Michele America.
530 // Revision 1.27 1998/01/27 00:47:55 curt
531 // Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
532 // system and commandline/config file processing code.
534 // Revision 1.26 1998/01/19 19:27:07 curt
535 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
536 // This should simplify things tremendously.
538 // Revision 1.25 1998/01/05 18:44:34 curt
539 // Add an option to advance/decrease time from keyboard.
541 // Revision 1.24 1997/12/30 16:36:46 curt
542 // Merged in Durk's changes ...
544 // Revision 1.23 1997/12/15 23:54:44 curt
545 // Add xgl wrappers for debugging.
546 // Generate terrain normals on the fly.
548 // Revision 1.22 1997/12/10 22:37:45 curt
549 // Prepended "fg" on the name of all global structures that didn't have it yet.
550 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
552 // Revision 1.21 1997/08/27 21:32:23 curt
553 // Restructured view calculation code. Added stars.
555 // Revision 1.20 1997/08/27 03:30:13 curt
556 // Changed naming scheme of basic shared structures.
558 // Revision 1.19 1997/08/25 20:27:21 curt
559 // Merged in initial HUD and Joystick code.
561 // Revision 1.18 1997/08/22 21:34:38 curt
562 // Doing a bit of reorganizing and house cleaning.
564 // Revision 1.17 1997/07/19 22:34:02 curt
565 // Moved PI definitions to ../constants.h
566 // Moved random() stuff to ../Utils/ and renamed fg_random()
568 // Revision 1.16 1997/07/18 23:41:24 curt
569 // Tweaks for building with Cygnus Win32 compiler.
571 // Revision 1.15 1997/07/16 20:04:47 curt
572 // Minor tweaks to aid Win32 port.
574 // Revision 1.14 1997/07/12 03:50:20 curt
575 // Added an #include <Windows32/Base.h> to help compiling for Win32
577 // Revision 1.13 1997/06/25 15:39:46 curt
578 // Minor changes to compile with rsxnt/win32.
580 // Revision 1.12 1997/06/21 17:12:52 curt
581 // Capitalized subdirectory names.
583 // Revision 1.11 1997/06/18 04:10:31 curt
584 // A couple more runway tweaks ...
586 // Revision 1.10 1997/06/18 02:21:23 curt
587 // Hacked in a runway
589 // Revision 1.9 1997/06/02 03:40:06 curt
590 // A tiny bit more view tweaking.
592 // Revision 1.8 1997/06/02 03:01:38 curt
593 // Working on views (side, front, back, transitions, etc.)
595 // Revision 1.7 1997/05/31 19:16:25 curt
596 // Elevator trim added.
598 // Revision 1.6 1997/05/31 04:13:52 curt
601 // Continuing work on the LaRCsim flight model integration.
602 // Added some MSFS-like keyboard input handling.
604 // Revision 1.5 1997/05/30 23:26:19 curt
605 // Added elevator/aileron controls.
607 // Revision 1.4 1997/05/27 17:44:31 curt
608 // Renamed & rearranged variables and routines. Added some initial simple
609 // timer/alarm routines so the flight model can be updated on a regular
612 // Revision 1.3 1997/05/23 15:40:25 curt
613 // Added GNU copyright headers.
616 // Revision 1.2 1997/05/23 00:35:12 curt
617 // Trying to get fog to work ...
619 // Revision 1.1 1997/05/21 15:57:50 curt
620 // Renamed due to added GLUT support.
622 // Revision 1.2 1997/05/19 18:22:41 curt
623 // Parameter tweaking ... starting to stub in fog support.
625 // Revision 1.1 1997/05/16 16:05:51 curt