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 <Autopilot/autopilot.h> // Added autopilot.h to list, Jeff Goeke-Smith
42 #include <Cockpit/hud.hxx>
43 #include <Debug/fg_debug.h>
45 #include <Include/fg_constants.h>
47 #include <Weather/weather.h>
49 #include "GLUTkey.hxx"
50 #include "options.hxx"
53 #if defined(FX) && defined(XMESA)
54 # include <GL/xmesa.h>
55 static int fullscreen = 1;
58 /* Handle keyboard events */
59 void GLUTkey(unsigned char k, int x, int y) {
67 c = current_aircraft.controls;
72 fgPrintf( FG_INPUT, FG_DEBUG, "Key hit = %d", k);
73 puKeyboard(k, PU_DOWN );
75 if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
76 fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
78 case 49: /* numeric keypad 1 */
79 v->goal_view_offset = FG_PI * 0.75;
81 case 50: /* numeric keypad 2 */
82 v->goal_view_offset = FG_PI;
84 case 51: /* numeric keypad 3 */
85 v->goal_view_offset = FG_PI * 1.25;
87 case 52: /* numeric keypad 4 */
88 v->goal_view_offset = FG_PI * 0.50;
90 case 54: /* numeric keypad 6 */
91 v->goal_view_offset = FG_PI * 1.50;
93 case 55: /* numeric keypad 7 */
94 v->goal_view_offset = FG_PI * 0.25;
96 case 56: /* numeric keypad 8 */
97 v->goal_view_offset = 0.00;
99 case 57: /* numeric keypad 9 */
100 v->goal_view_offset = FG_PI * 1.75;
103 // status = current_options.get_hud_status();
104 // current_options.set_hud_status(!status);
105 HUD_brightkey( true );
114 #if defined(FX) && !defined(WIN32)
115 fullscreen = ( !fullscreen );
116 #if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
117 XMesaSetFXmode(fullscreen ? XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW);
122 fov = current_options.get_fov();
124 if ( fov > FG_FOV_MAX ) {
127 current_options.set_fov(fov);
128 v->update_fov = TRUE;
131 tmp = fgWeatherGetVisibility(); /* in meters */
133 fgWeatherSetVisibility( tmp );
135 // autopilot additions
143 fgAPSetHeading(AP_CURRENT_HEADING);
147 fgPrintf( FG_INPUT, FG_DEBUG, "\n");
149 case 50: /* numeric keypad 2 */
152 case 56: /* numeric keypad 8 */
155 case 49: /* numeric keypad 1 */
156 fgElevTrimMove(-0.001);
158 case 55: /* numeric keypad 7 */
159 fgElevTrimMove(0.001);
161 case 52: /* numeric keypad 4 */
162 fgAileronMove(-0.05);
164 case 54: /* numeric keypad 6 */
167 case 48: /* numeric keypad Ins */
170 case 13: /* numeric keypad Enter */
173 case 53: /* numeric keypad 5 */
178 case 57: /* numeric keypad 9 (Pg Up) */
179 fgThrottleMove(0, 0.01);
181 case 51: /* numeric keypad 3 (Pg Dn) */
182 fgThrottleMove(0, -0.01);
184 case 104: /* h key */
185 HUD_brightkey( false );
187 case 109: /* m key */
190 case 116: /* t key */
193 case 120: /* X key */
194 fov = current_options.get_fov();
196 if ( fov < FG_FOV_MIN ) {
199 current_options.set_fov(fov);
200 v->update_fov = TRUE;
202 case 122: /* z key */
203 tmp = fgWeatherGetVisibility(); /* in meters */
205 fgWeatherSetVisibility( tmp );
208 // if( fg_DebugOutput ) {
209 // fclose( fg_DebugOutput );
211 fgPrintf( FG_INPUT, FG_EXIT,
212 "Program exiting normally at user request.\n");
218 /* Handle "special" keyboard events */
219 void GLUTspecialkey(int k, int x, int y) {
223 c = current_aircraft.controls;
226 fgPrintf( FG_INPUT, FG_DEBUG, "Special key hit = %d", k);
227 puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN);
229 if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
230 fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
232 case GLUT_KEY_END: /* numeric keypad 1 */
233 v->goal_view_offset = FG_PI * 0.75;
235 case GLUT_KEY_DOWN: /* numeric keypad 2 */
236 v->goal_view_offset = FG_PI;
238 case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 */
239 v->goal_view_offset = FG_PI * 1.25;
241 case GLUT_KEY_LEFT: /* numeric keypad 4 */
242 v->goal_view_offset = FG_PI * 0.50;
244 case GLUT_KEY_RIGHT: /* numeric keypad 6 */
245 v->goal_view_offset = FG_PI * 1.50;
247 case GLUT_KEY_HOME: /* numeric keypad 7 */
248 v->goal_view_offset = FG_PI * 0.25;
250 case GLUT_KEY_UP: /* numeric keypad 8 */
251 v->goal_view_offset = 0.00;
253 case GLUT_KEY_PAGE_UP: /* numeric keypad 9 */
254 v->goal_view_offset = FG_PI * 1.75;
258 fgPrintf( FG_INPUT, FG_DEBUG, "\n");
260 case GLUT_KEY_F10: /* F10 toggles menu on and off... */
261 printf("Invoking call back function");
263 setValue ((int) !(hideMenuButton -> getValue() ) );
264 hideMenuButton -> invokeCallback();
274 fgAileronMove(-0.05);
279 case GLUT_KEY_HOME: /* numeric keypad 1 */
280 fgElevTrimMove(0.001);
282 case GLUT_KEY_END: /* numeric keypad 7 */
283 fgElevTrimMove(-0.001);
285 case GLUT_KEY_INSERT: /* numeric keypad Ins */
288 case 13: /* numeric keypad Enter */
291 case 53: /* numeric keypad 5 */
296 case GLUT_KEY_PAGE_UP: /* numeric keypad 9 (Pg Up) */
297 fgThrottleMove(0, 0.01);
299 case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 (Pg Dn) */
300 fgThrottleMove(0, -0.01);
308 /* Revision 1.16 1998/07/16 17:33:34 curt
309 /* "H" / "h" now control hud brightness as well with off being one of the
311 /* Better checking for xmesa/fx 3dfx fullscreen/window support for deciding
312 /* whether or not to build in the feature.
313 /* Translucent menu support.
314 /* HAVE_AUDIO_SUPPORT -> ENABLE_AUDIO_SUPPORT
315 /* Use fork() / wait() for playing mp3 init music in background under unix.
316 /* Changed default tile diameter to 5.
318 * Revision 1.15 1998/07/13 21:01:34 curt
319 * Wrote access functions for current fgOPTIONS.
321 * Revision 1.14 1998/07/06 02:42:02 curt
322 * Added support for switching between fullscreen and window mode for
325 * Added a basic splash screen. Restructured the main loop and top level
326 * initialization routines to do this.
328 * Hacked in some support for playing a startup mp3 sound file while rest
329 * of sim initializes. Currently only works in Unix using the mpg123 player.
330 * Waits for the mpg123 player to finish before initializing internal
333 * Revision 1.13 1998/06/27 16:54:32 curt
334 * Replaced "extern displayInstruments" with a entry in fgOPTIONS.
335 * Don't change the view port when displaying the panel.
337 * Revision 1.12 1998/06/12 14:27:26 curt
338 * Pui -> PUI, Gui -> GUI.
340 * Revision 1.11 1998/06/12 00:57:38 curt
341 * Added support for Pui/Gui.
342 * Converted fog to GL_FOG_EXP2.
343 * Link to static simulator parts.
344 * Update runfg.bat to try to be a little smarter.
346 * Revision 1.10 1998/05/27 02:24:05 curt
347 * View optimizations by Norman Vine.
349 * Revision 1.9 1998/05/16 13:05:21 curt
350 * Added limits to fov.
352 * Revision 1.8 1998/05/13 18:29:56 curt
353 * Added a keyboard binding to dynamically adjust field of view.
354 * Added a command line option to specify fov.
355 * Adjusted terrain color.
356 * Root path info moved to fgOPTIONS.
357 * Added ability to parse options out of a config file.
359 * Revision 1.7 1998/05/07 23:14:14 curt
360 * Added "D" key binding to set autopilot heading.
361 * Made frame rate calculation average out over last 10 frames.
362 * Borland C++ floating point exception workaround.
363 * Added a --tile-radius=n option.
365 * Revision 1.6 1998/04/28 01:20:20 curt
366 * Type-ified fgTIME and fgVIEW.
367 * Added a command line option to disable textures.
369 * Revision 1.5 1998/04/25 22:06:29 curt
370 * Edited cvs log messages in source files ... bad bad bad!
372 * Revision 1.4 1998/04/25 20:24:00 curt
373 * Cleaned up initialization sequence to eliminate interdependencies
374 * between sun position, lighting, and view position. This creates a
375 * valid single pass initialization path.
377 * Revision 1.3 1998/04/24 14:19:29 curt
380 * Revision 1.2 1998/04/24 00:49:17 curt
381 * Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
382 * Trying out some different option parsing code.
383 * Some code reorganization.
385 * Revision 1.1 1998/04/22 13:25:40 curt
386 * C++ - ifing the code.
387 * Starting a bit of reorganization of lighting code.
389 * Revision 1.33 1998/04/18 04:11:25 curt
390 * Moved fg_debug to it's own library, added zlib support.
392 * Revision 1.32 1998/04/14 02:21:01 curt
393 * Incorporated autopilot heading hold contributed by: Jeff Goeke-Smith
394 * <jgoeke@voyager.net>
396 * Revision 1.31 1998/04/08 23:34:05 curt
397 * Patch from Durk to fix trim reversal with numlock key active.
399 * Revision 1.30 1998/04/03 22:09:02 curt
400 * Converting to Gnu autoconf system.
402 * Revision 1.29 1998/02/07 15:29:40 curt
403 * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
404 * <chotchkiss@namg.us.anritsu.com>
406 * Revision 1.28 1998/02/03 23:20:23 curt
407 * Lots of little tweaks to fix various consistency problems discovered by
408 * Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
409 * passed arguments along to the real printf(). Also incorporated HUD changes
410 * by Michele America.
412 * Revision 1.27 1998/01/27 00:47:55 curt
413 * Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
414 * system and commandline/config file processing code.
416 * Revision 1.26 1998/01/19 19:27:07 curt
417 * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
418 * This should simplify things tremendously.
420 * Revision 1.25 1998/01/05 18:44:34 curt
421 * Add an option to advance/decrease time from keyboard.
423 * Revision 1.24 1997/12/30 16:36:46 curt
424 * Merged in Durk's changes ...
426 * Revision 1.23 1997/12/15 23:54:44 curt
427 * Add xgl wrappers for debugging.
428 * Generate terrain normals on the fly.
430 * Revision 1.22 1997/12/10 22:37:45 curt
431 * Prepended "fg" on the name of all global structures that didn't have it yet.
432 * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
434 * Revision 1.21 1997/08/27 21:32:23 curt
435 * Restructured view calculation code. Added stars.
437 * Revision 1.20 1997/08/27 03:30:13 curt
438 * Changed naming scheme of basic shared structures.
440 * Revision 1.19 1997/08/25 20:27:21 curt
441 * Merged in initial HUD and Joystick code.
443 * Revision 1.18 1997/08/22 21:34:38 curt
444 * Doing a bit of reorganizing and house cleaning.
446 * Revision 1.17 1997/07/19 22:34:02 curt
447 * Moved PI definitions to ../constants.h
448 * Moved random() stuff to ../Utils/ and renamed fg_random()
450 * Revision 1.16 1997/07/18 23:41:24 curt
451 * Tweaks for building with Cygnus Win32 compiler.
453 * Revision 1.15 1997/07/16 20:04:47 curt
454 * Minor tweaks to aid Win32 port.
456 * Revision 1.14 1997/07/12 03:50:20 curt
457 * Added an #include <Windows32/Base.h> to help compiling for Win32
459 * Revision 1.13 1997/06/25 15:39:46 curt
460 * Minor changes to compile with rsxnt/win32.
462 * Revision 1.12 1997/06/21 17:12:52 curt
463 * Capitalized subdirectory names.
465 * Revision 1.11 1997/06/18 04:10:31 curt
466 * A couple more runway tweaks ...
468 * Revision 1.10 1997/06/18 02:21:23 curt
471 * Revision 1.9 1997/06/02 03:40:06 curt
472 * A tiny bit more view tweaking.
474 * Revision 1.8 1997/06/02 03:01:38 curt
475 * Working on views (side, front, back, transitions, etc.)
477 * Revision 1.7 1997/05/31 19:16:25 curt
478 * Elevator trim added.
480 * Revision 1.6 1997/05/31 04:13:52 curt
483 * Continuing work on the LaRCsim flight model integration.
484 * Added some MSFS-like keyboard input handling.
486 * Revision 1.5 1997/05/30 23:26:19 curt
487 * Added elevator/aileron controls.
489 * Revision 1.4 1997/05/27 17:44:31 curt
490 * Renamed & rearranged variables and routines. Added some initial simple
491 * timer/alarm routines so the flight model can be updated on a regular
494 * Revision 1.3 1997/05/23 15:40:25 curt
495 * Added GNU copyright headers.
498 * Revision 1.2 1997/05/23 00:35:12 curt
499 * Trying to get fog to work ...
501 * Revision 1.1 1997/05/21 15:57:50 curt
502 * Renamed due to added GLUT support.
504 * Revision 1.2 1997/05/19 18:22:41 curt
505 * Parameter tweaking ... starting to stub in fog support.
507 * Revision 1.1 1997/05/16 16:05:51 curt