1 /**************************************************************************
2 * GLUTkey.c -- handle GLUT keyboard events
4 * Written by Curtis Olson, started May 1997.
6 * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * (Log is kept at end of this file)
24 **************************************************************************/
40 #include <Aircraft/aircraft.h>
41 // #include <Astro/orbits.hxx>
42 // #include <Astro/sun.hxx>
43 #include <Astro/solarsystem.hxx>
44 #include <Astro/sky.hxx>
45 #include <Autopilot/autopilot.h> // Added autopilot.h to list, Jeff Goeke-Smith
46 #include <Cockpit/hud.hxx>
47 #include <Debug/fg_debug.h>
49 #include <Include/fg_constants.h>
51 #include <Time/light.hxx>
52 #include <Weather/weather.h>
54 #include "GLUTkey.hxx"
55 #include "options.hxx"
58 #if defined(FX) && defined(XMESA)
59 # include <GL/xmesa.h>
60 static int fullscreen = 1;
64 // Force an update of the sky and lighting parameters
65 static void local_update_sky_and_lighting_params( void ) {
67 SolarSystem::theSolarSystem->rebuild();
68 cur_light_params.Update();
73 /* Handle keyboard events */
74 void GLUTkey(unsigned char k, int x, int y) {
83 c = current_aircraft.controls;
84 f = current_aircraft.flight;
89 fgPrintf( FG_INPUT, FG_DEBUG, "Key hit = %d", k);
90 puKeyboard(k, PU_DOWN );
92 if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
93 fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
95 case 49: /* numeric keypad 1 */
96 v->goal_view_offset = FG_PI * 0.75;
98 case 50: /* numeric keypad 2 */
99 v->goal_view_offset = FG_PI;
101 case 51: /* numeric keypad 3 */
102 v->goal_view_offset = FG_PI * 1.25;
104 case 52: /* numeric keypad 4 */
105 v->goal_view_offset = FG_PI * 0.50;
107 case 54: /* numeric keypad 6 */
108 v->goal_view_offset = FG_PI * 1.50;
110 case 55: /* numeric keypad 7 */
111 v->goal_view_offset = FG_PI * 0.25;
113 case 56: /* numeric keypad 8 */
114 v->goal_view_offset = 0.00;
116 case 57: /* numeric keypad 9 */
117 v->goal_view_offset = FG_PI * 1.75;
120 // status = current_options.get_hud_status();
121 // current_options.set_hud_status(!status);
122 HUD_brightkey( true );
126 fgHUDInit2(¤t_aircraft);
130 local_update_sky_and_lighting_params();
134 local_update_sky_and_lighting_params();
137 #if defined(FX) && !defined(WIN32)
138 fullscreen = ( !fullscreen );
139 #if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
140 XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW);
145 fov = current_options.get_fov();
147 if ( fov > FG_FOV_MAX ) {
150 current_options.set_fov(fov);
151 v->update_fov = TRUE;
154 tmp = fgWeatherGetVisibility(); /* in meters */
156 fgWeatherSetVisibility( tmp );
158 // autopilot additions
166 fgAPSetHeading(AP_CURRENT_HEADING);
170 fgPrintf( FG_INPUT, FG_DEBUG, "\n");
172 case 50: /* numeric keypad 2 */
175 case 56: /* numeric keypad 8 */
178 case 49: /* numeric keypad 1 */
179 fgElevTrimMove(-0.001);
181 case 55: /* numeric keypad 7 */
182 fgElevTrimMove(0.001);
184 case 52: /* numeric keypad 4 */
185 fgAileronMove(-0.05);
187 case 54: /* numeric keypad 6 */
190 case 48: /* numeric keypad Ins */
193 case 13: /* numeric keypad Enter */
196 case 53: /* numeric keypad 5 */
201 case 57: /* numeric keypad 9 (Pg Up) */
202 fgThrottleMove(0, 0.01);
204 case 51: /* numeric keypad 3 (Pg Dn) */
205 fgThrottleMove(0, -0.01);
207 case 104: /* h key */
208 HUD_brightkey( false );
210 case 105: /* i key */
211 fgHUDInit(¤t_aircraft); // normal HUD
213 case 109: /* m key */
215 local_update_sky_and_lighting_params();
217 case 112: /* p key */
218 t->pause = !t->pause;
219 // printf position and attitude information
220 fgPrintf( FG_INPUT, FG_INFO,
221 "Lon = %.4f Lat = %.4f Altitude = %.1f\n",
222 FG_Longitude * RAD_TO_DEG,
223 FG_Latitude * RAD_TO_DEG,
224 FG_Altitude * FEET_TO_METER);
225 fgPrintf( FG_INPUT, FG_INFO,
226 "Heading = %.2f Roll = %.2f Pitch = %.2f\n",
229 FG_Theta * RAD_TO_DEG);
231 case 116: /* t key */
233 local_update_sky_and_lighting_params();
235 case 120: /* X key */
236 fov = current_options.get_fov();
238 if ( fov < FG_FOV_MIN ) {
241 current_options.set_fov(fov);
242 v->update_fov = TRUE;
244 case 122: /* z key */
245 tmp = fgWeatherGetVisibility(); /* in meters */
247 fgWeatherSetVisibility( tmp );
250 // if( fg_DebugOutput ) {
251 // fclose( fg_DebugOutput );
253 fgPrintf( FG_INPUT, FG_EXIT,
254 "Program exiting normally at user request.\n");
260 /* Handle "special" keyboard events */
261 void GLUTspecialkey(int k, int x, int y) {
265 c = current_aircraft.controls;
268 fgPrintf( FG_INPUT, FG_DEBUG, "Special key hit = %d", k);
269 puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN);
271 if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
272 fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
274 case GLUT_KEY_END: /* numeric keypad 1 */
275 v->goal_view_offset = FG_PI * 0.75;
277 case GLUT_KEY_DOWN: /* numeric keypad 2 */
278 v->goal_view_offset = FG_PI;
280 case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 */
281 v->goal_view_offset = FG_PI * 1.25;
283 case GLUT_KEY_LEFT: /* numeric keypad 4 */
284 v->goal_view_offset = FG_PI * 0.50;
286 case GLUT_KEY_RIGHT: /* numeric keypad 6 */
287 v->goal_view_offset = FG_PI * 1.50;
289 case GLUT_KEY_HOME: /* numeric keypad 7 */
290 v->goal_view_offset = FG_PI * 0.25;
292 case GLUT_KEY_UP: /* numeric keypad 8 */
293 v->goal_view_offset = 0.00;
295 case GLUT_KEY_PAGE_UP: /* numeric keypad 9 */
296 v->goal_view_offset = FG_PI * 1.75;
300 fgPrintf( FG_INPUT, FG_DEBUG, "\n");
302 case GLUT_KEY_F10: /* F10 toggles menu on and off... */
303 printf("Invoking call back function");
305 setValue ((int) !(hideMenuButton -> getValue() ) );
306 hideMenuButton -> invokeCallback();
316 fgAileronMove(-0.05);
321 case GLUT_KEY_HOME: /* numeric keypad 1 */
322 fgElevTrimMove(0.001);
324 case GLUT_KEY_END: /* numeric keypad 7 */
325 fgElevTrimMove(-0.001);
327 case GLUT_KEY_INSERT: /* numeric keypad Ins */
330 case 13: /* numeric keypad Enter */
333 case 53: /* numeric keypad 5 */
338 case GLUT_KEY_PAGE_UP: /* numeric keypad 9 (Pg Up) */
339 fgThrottleMove(0, 0.01);
341 case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 (Pg Dn) */
342 fgThrottleMove(0, -0.01);
350 /* Revision 1.22 1998/09/15 04:27:27 curt
351 /* Changes for new Astro code.
353 * Revision 1.21 1998/08/29 13:09:25 curt
354 * Changes to event manager from Bernie Bright.
356 * Revision 1.20 1998/08/24 20:11:12 curt
357 * Added i/I to toggle full vs. minimal HUD.
358 * Added a --hud-tris vs --hud-culled option.
359 * Moved options accessor funtions to options.hxx.
361 * Revision 1.19 1998/08/05 00:19:33 curt
362 * Added a local routine to update lighting params every frame when time is
365 * Revision 1.18 1998/07/30 23:48:24 curt
366 * Output position & orientation when pausing.
367 * Eliminated libtool use.
368 * Added options to specify initial position and orientation.
369 * Changed default fov to 55 degrees.
370 * Added command line option to start in paused or unpaused state.
372 * Revision 1.17 1998/07/27 18:41:23 curt
373 * Added a pause command "p"
374 * Fixed some initialization order problems between pui and glut.
375 * Added an --enable/disable-sound option.
377 * Revision 1.16 1998/07/16 17:33:34 curt
378 * "H" / "h" now control hud brightness as well with off being one of the
380 * Better checking for xmesa/fx 3dfx fullscreen/window support for deciding
381 * whether or not to build in the feature.
382 * Translucent menu support.
383 * HAVE_AUDIO_SUPPORT -> ENABLE_AUDIO_SUPPORT
384 * Use fork() / wait() for playing mp3 init music in background under unix.
385 * Changed default tile diameter to 5.
387 * Revision 1.15 1998/07/13 21:01:34 curt
388 * Wrote access functions for current fgOPTIONS.
390 * Revision 1.14 1998/07/06 02:42:02 curt
391 * Added support for switching between fullscreen and window mode for
394 * Added a basic splash screen. Restructured the main loop and top level
395 * initialization routines to do this.
397 * Hacked in some support for playing a startup mp3 sound file while rest
398 * of sim initializes. Currently only works in Unix using the mpg123 player.
399 * Waits for the mpg123 player to finish before initializing internal
402 * Revision 1.13 1998/06/27 16:54:32 curt
403 * Replaced "extern displayInstruments" with a entry in fgOPTIONS.
404 * Don't change the view port when displaying the panel.
406 * Revision 1.12 1998/06/12 14:27:26 curt
407 * Pui -> PUI, Gui -> GUI.
409 * Revision 1.11 1998/06/12 00:57:38 curt
410 * Added support for Pui/Gui.
411 * Converted fog to GL_FOG_EXP2.
412 * Link to static simulator parts.
413 * Update runfg.bat to try to be a little smarter.
415 * Revision 1.10 1998/05/27 02:24:05 curt
416 * View optimizations by Norman Vine.
418 * Revision 1.9 1998/05/16 13:05:21 curt
419 * Added limits to fov.
421 * Revision 1.8 1998/05/13 18:29:56 curt
422 * Added a keyboard binding to dynamically adjust field of view.
423 * Added a command line option to specify fov.
424 * Adjusted terrain color.
425 * Root path info moved to fgOPTIONS.
426 * Added ability to parse options out of a config file.
428 * Revision 1.7 1998/05/07 23:14:14 curt
429 * Added "D" key binding to set autopilot heading.
430 * Made frame rate calculation average out over last 10 frames.
431 * Borland C++ floating point exception workaround.
432 * Added a --tile-radius=n option.
434 * Revision 1.6 1998/04/28 01:20:20 curt
435 * Type-ified fgTIME and fgVIEW.
436 * Added a command line option to disable textures.
438 * Revision 1.5 1998/04/25 22:06:29 curt
439 * Edited cvs log messages in source files ... bad bad bad!
441 * Revision 1.4 1998/04/25 20:24:00 curt
442 * Cleaned up initialization sequence to eliminate interdependencies
443 * between sun position, lighting, and view position. This creates a
444 * valid single pass initialization path.
446 * Revision 1.3 1998/04/24 14:19:29 curt
449 * Revision 1.2 1998/04/24 00:49:17 curt
450 * Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
451 * Trying out some different option parsing code.
452 * Some code reorganization.
454 * Revision 1.1 1998/04/22 13:25:40 curt
455 * C++ - ifing the code.
456 * Starting a bit of reorganization of lighting code.
458 * Revision 1.33 1998/04/18 04:11:25 curt
459 * Moved fg_debug to it's own library, added zlib support.
461 * Revision 1.32 1998/04/14 02:21:01 curt
462 * Incorporated autopilot heading hold contributed by: Jeff Goeke-Smith
463 * <jgoeke@voyager.net>
465 * Revision 1.31 1998/04/08 23:34:05 curt
466 * Patch from Durk to fix trim reversal with numlock key active.
468 * Revision 1.30 1998/04/03 22:09:02 curt
469 * Converting to Gnu autoconf system.
471 * Revision 1.29 1998/02/07 15:29:40 curt
472 * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
473 * <chotchkiss@namg.us.anritsu.com>
475 * Revision 1.28 1998/02/03 23:20:23 curt
476 * Lots of little tweaks to fix various consistency problems discovered by
477 * Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
478 * passed arguments along to the real printf(). Also incorporated HUD changes
479 * by Michele America.
481 * Revision 1.27 1998/01/27 00:47:55 curt
482 * Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
483 * system and commandline/config file processing code.
485 * Revision 1.26 1998/01/19 19:27:07 curt
486 * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
487 * This should simplify things tremendously.
489 * Revision 1.25 1998/01/05 18:44:34 curt
490 * Add an option to advance/decrease time from keyboard.
492 * Revision 1.24 1997/12/30 16:36:46 curt
493 * Merged in Durk's changes ...
495 * Revision 1.23 1997/12/15 23:54:44 curt
496 * Add xgl wrappers for debugging.
497 * Generate terrain normals on the fly.
499 * Revision 1.22 1997/12/10 22:37:45 curt
500 * Prepended "fg" on the name of all global structures that didn't have it yet.
501 * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
503 * Revision 1.21 1997/08/27 21:32:23 curt
504 * Restructured view calculation code. Added stars.
506 * Revision 1.20 1997/08/27 03:30:13 curt
507 * Changed naming scheme of basic shared structures.
509 * Revision 1.19 1997/08/25 20:27:21 curt
510 * Merged in initial HUD and Joystick code.
512 * Revision 1.18 1997/08/22 21:34:38 curt
513 * Doing a bit of reorganizing and house cleaning.
515 * Revision 1.17 1997/07/19 22:34:02 curt
516 * Moved PI definitions to ../constants.h
517 * Moved random() stuff to ../Utils/ and renamed fg_random()
519 * Revision 1.16 1997/07/18 23:41:24 curt
520 * Tweaks for building with Cygnus Win32 compiler.
522 * Revision 1.15 1997/07/16 20:04:47 curt
523 * Minor tweaks to aid Win32 port.
525 * Revision 1.14 1997/07/12 03:50:20 curt
526 * Added an #include <Windows32/Base.h> to help compiling for Win32
528 * Revision 1.13 1997/06/25 15:39:46 curt
529 * Minor changes to compile with rsxnt/win32.
531 * Revision 1.12 1997/06/21 17:12:52 curt
532 * Capitalized subdirectory names.
534 * Revision 1.11 1997/06/18 04:10:31 curt
535 * A couple more runway tweaks ...
537 * Revision 1.10 1997/06/18 02:21:23 curt
540 * Revision 1.9 1997/06/02 03:40:06 curt
541 * A tiny bit more view tweaking.
543 * Revision 1.8 1997/06/02 03:01:38 curt
544 * Working on views (side, front, back, transitions, etc.)
546 * Revision 1.7 1997/05/31 19:16:25 curt
547 * Elevator trim added.
549 * Revision 1.6 1997/05/31 04:13:52 curt
552 * Continuing work on the LaRCsim flight model integration.
553 * Added some MSFS-like keyboard input handling.
555 * Revision 1.5 1997/05/30 23:26:19 curt
556 * Added elevator/aileron controls.
558 * Revision 1.4 1997/05/27 17:44:31 curt
559 * Renamed & rearranged variables and routines. Added some initial simple
560 * timer/alarm routines so the flight model can be updated on a regular
563 * Revision 1.3 1997/05/23 15:40:25 curt
564 * Added GNU copyright headers.
567 * Revision 1.2 1997/05/23 00:35:12 curt
568 * Trying to get fog to work ...
570 * Revision 1.1 1997/05/21 15:57:50 curt
571 * Renamed due to added GLUT support.
573 * Revision 1.2 1997/05/19 18:22:41 curt
574 * Parameter tweaking ... starting to stub in fog support.
576 * Revision 1.1 1997/05/16 16:05:51 curt