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/sky.hxx>
44 #include <Autopilot/autopilot.h> // Added autopilot.h to list, Jeff Goeke-Smith
45 #include <Cockpit/hud.hxx>
46 #include <Debug/fg_debug.h>
48 #include <Include/fg_constants.h>
50 #include <Time/light.hxx>
51 #include <Weather/weather.h>
53 #include "GLUTkey.hxx"
54 #include "options.hxx"
57 #if defined(FX) && defined(XMESA)
58 # include <GL/xmesa.h>
59 static int fullscreen = 1;
63 // Force an update of the sky and lighting parameters
64 static void local_update_sky_and_lighting_params( void ) {
71 /* Handle keyboard events */
72 void GLUTkey(unsigned char k, int x, int y) {
81 c = current_aircraft.controls;
82 f = current_aircraft.flight;
87 fgPrintf( FG_INPUT, FG_DEBUG, "Key hit = %d", k);
88 puKeyboard(k, PU_DOWN );
90 if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
91 fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
93 case 49: /* numeric keypad 1 */
94 v->goal_view_offset = FG_PI * 0.75;
96 case 50: /* numeric keypad 2 */
97 v->goal_view_offset = FG_PI;
99 case 51: /* numeric keypad 3 */
100 v->goal_view_offset = FG_PI * 1.25;
102 case 52: /* numeric keypad 4 */
103 v->goal_view_offset = FG_PI * 0.50;
105 case 54: /* numeric keypad 6 */
106 v->goal_view_offset = FG_PI * 1.50;
108 case 55: /* numeric keypad 7 */
109 v->goal_view_offset = FG_PI * 0.25;
111 case 56: /* numeric keypad 8 */
112 v->goal_view_offset = 0.00;
114 case 57: /* numeric keypad 9 */
115 v->goal_view_offset = FG_PI * 1.75;
118 // status = current_options.get_hud_status();
119 // current_options.set_hud_status(!status);
120 HUD_brightkey( true );
124 fgHUDInit2(¤t_aircraft);
128 local_update_sky_and_lighting_params();
132 local_update_sky_and_lighting_params();
135 #if defined(FX) && !defined(WIN32)
136 fullscreen = ( !fullscreen );
137 #if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
138 XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW);
143 fov = current_options.get_fov();
145 if ( fov > FG_FOV_MAX ) {
148 current_options.set_fov(fov);
149 v->update_fov = TRUE;
152 tmp = fgWeatherGetVisibility(); /* in meters */
154 fgWeatherSetVisibility( tmp );
156 // autopilot additions
164 fgAPSetHeading(AP_CURRENT_HEADING);
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);
205 case 104: /* h key */
206 HUD_brightkey( false );
208 case 105: /* i key */
209 fgHUDInit(¤t_aircraft); // normal HUD
211 case 109: /* m key */
213 local_update_sky_and_lighting_params();
215 case 112: /* p key */
216 t->pause = !t->pause;
217 // printf position and attitude information
218 fgPrintf( FG_INPUT, FG_INFO,
219 "Lon = %.4f Lat = %.4f Altitude = %.1f\n",
220 FG_Longitude * RAD_TO_DEG,
221 FG_Latitude * RAD_TO_DEG,
222 FG_Altitude * FEET_TO_METER);
223 fgPrintf( FG_INPUT, FG_INFO,
224 "Heading = %.2f Roll = %.2f Pitch = %.2f\n",
227 FG_Theta * RAD_TO_DEG);
229 case 116: /* t key */
231 local_update_sky_and_lighting_params();
233 case 120: /* X key */
234 fov = current_options.get_fov();
236 if ( fov < FG_FOV_MIN ) {
239 current_options.set_fov(fov);
240 v->update_fov = TRUE;
242 case 122: /* z key */
243 tmp = fgWeatherGetVisibility(); /* in meters */
245 fgWeatherSetVisibility( tmp );
248 // if( fg_DebugOutput ) {
249 // fclose( fg_DebugOutput );
251 fgPrintf( FG_INPUT, FG_EXIT,
252 "Program exiting normally at user request.\n");
258 /* Handle "special" keyboard events */
259 void GLUTspecialkey(int k, int x, int y) {
263 c = current_aircraft.controls;
266 fgPrintf( FG_INPUT, FG_DEBUG, "Special key hit = %d", k);
267 puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN);
269 if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
270 fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
272 case GLUT_KEY_END: /* numeric keypad 1 */
273 v->goal_view_offset = FG_PI * 0.75;
275 case GLUT_KEY_DOWN: /* numeric keypad 2 */
276 v->goal_view_offset = FG_PI;
278 case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 */
279 v->goal_view_offset = FG_PI * 1.25;
281 case GLUT_KEY_LEFT: /* numeric keypad 4 */
282 v->goal_view_offset = FG_PI * 0.50;
284 case GLUT_KEY_RIGHT: /* numeric keypad 6 */
285 v->goal_view_offset = FG_PI * 1.50;
287 case GLUT_KEY_HOME: /* numeric keypad 7 */
288 v->goal_view_offset = FG_PI * 0.25;
290 case GLUT_KEY_UP: /* numeric keypad 8 */
291 v->goal_view_offset = 0.00;
293 case GLUT_KEY_PAGE_UP: /* numeric keypad 9 */
294 v->goal_view_offset = FG_PI * 1.75;
298 fgPrintf( FG_INPUT, FG_DEBUG, "\n");
300 case GLUT_KEY_F10: /* F10 toggles menu on and off... */
301 printf("Invoking call back function");
303 setValue ((int) !(hideMenuButton -> getValue() ) );
304 hideMenuButton -> invokeCallback();
314 fgAileronMove(-0.05);
319 case GLUT_KEY_HOME: /* numeric keypad 1 */
320 fgElevTrimMove(0.001);
322 case GLUT_KEY_END: /* numeric keypad 7 */
323 fgElevTrimMove(-0.001);
325 case GLUT_KEY_INSERT: /* numeric keypad Ins */
328 case 13: /* numeric keypad Enter */
331 case 53: /* numeric keypad 5 */
336 case GLUT_KEY_PAGE_UP: /* numeric keypad 9 (Pg Up) */
337 fgThrottleMove(0, 0.01);
339 case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 (Pg Dn) */
340 fgThrottleMove(0, -0.01);
348 /* Revision 1.20 1998/08/24 20:11:12 curt
349 /* Added i/I to toggle full vs. minimal HUD.
350 /* Added a --hud-tris vs --hud-culled option.
351 /* Moved options accessor funtions to options.hxx.
353 * Revision 1.19 1998/08/05 00:19:33 curt
354 * Added a local routine to update lighting params every frame when time is
357 * Revision 1.18 1998/07/30 23:48:24 curt
358 * Output position & orientation when pausing.
359 * Eliminated libtool use.
360 * Added options to specify initial position and orientation.
361 * Changed default fov to 55 degrees.
362 * Added command line option to start in paused or unpaused state.
364 * Revision 1.17 1998/07/27 18:41:23 curt
365 * Added a pause command "p"
366 * Fixed some initialization order problems between pui and glut.
367 * Added an --enable/disable-sound option.
369 * Revision 1.16 1998/07/16 17:33:34 curt
370 * "H" / "h" now control hud brightness as well with off being one of the
372 * Better checking for xmesa/fx 3dfx fullscreen/window support for deciding
373 * whether or not to build in the feature.
374 * Translucent menu support.
375 * HAVE_AUDIO_SUPPORT -> ENABLE_AUDIO_SUPPORT
376 * Use fork() / wait() for playing mp3 init music in background under unix.
377 * Changed default tile diameter to 5.
379 * Revision 1.15 1998/07/13 21:01:34 curt
380 * Wrote access functions for current fgOPTIONS.
382 * Revision 1.14 1998/07/06 02:42:02 curt
383 * Added support for switching between fullscreen and window mode for
386 * Added a basic splash screen. Restructured the main loop and top level
387 * initialization routines to do this.
389 * Hacked in some support for playing a startup mp3 sound file while rest
390 * of sim initializes. Currently only works in Unix using the mpg123 player.
391 * Waits for the mpg123 player to finish before initializing internal
394 * Revision 1.13 1998/06/27 16:54:32 curt
395 * Replaced "extern displayInstruments" with a entry in fgOPTIONS.
396 * Don't change the view port when displaying the panel.
398 * Revision 1.12 1998/06/12 14:27:26 curt
399 * Pui -> PUI, Gui -> GUI.
401 * Revision 1.11 1998/06/12 00:57:38 curt
402 * Added support for Pui/Gui.
403 * Converted fog to GL_FOG_EXP2.
404 * Link to static simulator parts.
405 * Update runfg.bat to try to be a little smarter.
407 * Revision 1.10 1998/05/27 02:24:05 curt
408 * View optimizations by Norman Vine.
410 * Revision 1.9 1998/05/16 13:05:21 curt
411 * Added limits to fov.
413 * Revision 1.8 1998/05/13 18:29:56 curt
414 * Added a keyboard binding to dynamically adjust field of view.
415 * Added a command line option to specify fov.
416 * Adjusted terrain color.
417 * Root path info moved to fgOPTIONS.
418 * Added ability to parse options out of a config file.
420 * Revision 1.7 1998/05/07 23:14:14 curt
421 * Added "D" key binding to set autopilot heading.
422 * Made frame rate calculation average out over last 10 frames.
423 * Borland C++ floating point exception workaround.
424 * Added a --tile-radius=n option.
426 * Revision 1.6 1998/04/28 01:20:20 curt
427 * Type-ified fgTIME and fgVIEW.
428 * Added a command line option to disable textures.
430 * Revision 1.5 1998/04/25 22:06:29 curt
431 * Edited cvs log messages in source files ... bad bad bad!
433 * Revision 1.4 1998/04/25 20:24:00 curt
434 * Cleaned up initialization sequence to eliminate interdependencies
435 * between sun position, lighting, and view position. This creates a
436 * valid single pass initialization path.
438 * Revision 1.3 1998/04/24 14:19:29 curt
441 * Revision 1.2 1998/04/24 00:49:17 curt
442 * Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
443 * Trying out some different option parsing code.
444 * Some code reorganization.
446 * Revision 1.1 1998/04/22 13:25:40 curt
447 * C++ - ifing the code.
448 * Starting a bit of reorganization of lighting code.
450 * Revision 1.33 1998/04/18 04:11:25 curt
451 * Moved fg_debug to it's own library, added zlib support.
453 * Revision 1.32 1998/04/14 02:21:01 curt
454 * Incorporated autopilot heading hold contributed by: Jeff Goeke-Smith
455 * <jgoeke@voyager.net>
457 * Revision 1.31 1998/04/08 23:34:05 curt
458 * Patch from Durk to fix trim reversal with numlock key active.
460 * Revision 1.30 1998/04/03 22:09:02 curt
461 * Converting to Gnu autoconf system.
463 * Revision 1.29 1998/02/07 15:29:40 curt
464 * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
465 * <chotchkiss@namg.us.anritsu.com>
467 * Revision 1.28 1998/02/03 23:20:23 curt
468 * Lots of little tweaks to fix various consistency problems discovered by
469 * Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
470 * passed arguments along to the real printf(). Also incorporated HUD changes
471 * by Michele America.
473 * Revision 1.27 1998/01/27 00:47:55 curt
474 * Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
475 * system and commandline/config file processing code.
477 * Revision 1.26 1998/01/19 19:27:07 curt
478 * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
479 * This should simplify things tremendously.
481 * Revision 1.25 1998/01/05 18:44:34 curt
482 * Add an option to advance/decrease time from keyboard.
484 * Revision 1.24 1997/12/30 16:36:46 curt
485 * Merged in Durk's changes ...
487 * Revision 1.23 1997/12/15 23:54:44 curt
488 * Add xgl wrappers for debugging.
489 * Generate terrain normals on the fly.
491 * Revision 1.22 1997/12/10 22:37:45 curt
492 * Prepended "fg" on the name of all global structures that didn't have it yet.
493 * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
495 * Revision 1.21 1997/08/27 21:32:23 curt
496 * Restructured view calculation code. Added stars.
498 * Revision 1.20 1997/08/27 03:30:13 curt
499 * Changed naming scheme of basic shared structures.
501 * Revision 1.19 1997/08/25 20:27:21 curt
502 * Merged in initial HUD and Joystick code.
504 * Revision 1.18 1997/08/22 21:34:38 curt
505 * Doing a bit of reorganizing and house cleaning.
507 * Revision 1.17 1997/07/19 22:34:02 curt
508 * Moved PI definitions to ../constants.h
509 * Moved random() stuff to ../Utils/ and renamed fg_random()
511 * Revision 1.16 1997/07/18 23:41:24 curt
512 * Tweaks for building with Cygnus Win32 compiler.
514 * Revision 1.15 1997/07/16 20:04:47 curt
515 * Minor tweaks to aid Win32 port.
517 * Revision 1.14 1997/07/12 03:50:20 curt
518 * Added an #include <Windows32/Base.h> to help compiling for Win32
520 * Revision 1.13 1997/06/25 15:39:46 curt
521 * Minor changes to compile with rsxnt/win32.
523 * Revision 1.12 1997/06/21 17:12:52 curt
524 * Capitalized subdirectory names.
526 * Revision 1.11 1997/06/18 04:10:31 curt
527 * A couple more runway tweaks ...
529 * Revision 1.10 1997/06/18 02:21:23 curt
532 * Revision 1.9 1997/06/02 03:40:06 curt
533 * A tiny bit more view tweaking.
535 * Revision 1.8 1997/06/02 03:01:38 curt
536 * Working on views (side, front, back, transitions, etc.)
538 * Revision 1.7 1997/05/31 19:16:25 curt
539 * Elevator trim added.
541 * Revision 1.6 1997/05/31 04:13:52 curt
544 * Continuing work on the LaRCsim flight model integration.
545 * Added some MSFS-like keyboard input handling.
547 * Revision 1.5 1997/05/30 23:26:19 curt
548 * Added elevator/aileron controls.
550 * Revision 1.4 1997/05/27 17:44:31 curt
551 * Renamed & rearranged variables and routines. Added some initial simple
552 * timer/alarm routines so the flight model can be updated on a regular
555 * Revision 1.3 1997/05/23 15:40:25 curt
556 * Added GNU copyright headers.
559 * Revision 1.2 1997/05/23 00:35:12 curt
560 * Trying to get fog to work ...
562 * Revision 1.1 1997/05/21 15:57:50 curt
563 * Renamed due to added GLUT support.
565 * Revision 1.2 1997/05/19 18:22:41 curt
566 * Parameter tweaking ... starting to stub in fog support.
568 * Revision 1.1 1997/05/16 16:05:51 curt