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 <Debug/fg_debug.h>
43 #include <Include/fg_constants.h>
44 #include <Weather/weather.h>
46 #include "GLUTkey.hxx"
47 #include "options.hxx"
51 extern int displayInstruments;
54 /* Handle keyboard events */
55 void GLUTkey(unsigned char k, int x, int y) {
62 c = current_aircraft.controls;
68 fgPrintf( FG_INPUT, FG_DEBUG, "Key hit = %d", k);
70 if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
71 fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
73 case 49: /* numeric keypad 1 */
74 v->goal_view_offset = FG_PI * 0.75;
76 case 50: /* numeric keypad 2 */
77 v->goal_view_offset = FG_PI;
79 case 51: /* numeric keypad 3 */
80 v->goal_view_offset = FG_PI * 1.25;
82 case 52: /* numeric keypad 4 */
83 v->goal_view_offset = FG_PI * 0.50;
85 case 54: /* numeric keypad 6 */
86 v->goal_view_offset = FG_PI * 1.50;
88 case 55: /* numeric keypad 7 */
89 v->goal_view_offset = FG_PI * 0.25;
91 case 56: /* numeric keypad 8 */
92 v->goal_view_offset = 0.00;
94 case 57: /* numeric keypad 9 */
95 v->goal_view_offset = FG_PI * 1.75;
98 o->hud_status = !(o->hud_status);
107 displayInstruments = !displayInstruments;
111 if ( o->fov > FG_FOV_MAX ) {
114 v->update_fov = TRUE;
117 w->visibility /= 1.10;
118 xglFogf (GL_FOG_START, w->visibility / 1000000.0 );
119 xglFogf(GL_FOG_END, w->visibility);
120 fgPrintf( FG_INPUT, FG_DEBUG,
121 "Fog density = %.4f\n", w->visibility );
123 // autopilot additions
131 fgAPSetHeading(AP_CURRENT_HEADING);
135 fgPrintf( FG_INPUT, FG_DEBUG, "\n");
137 case 50: /* numeric keypad 2 */
140 case 56: /* numeric keypad 8 */
143 case 49: /* numeric keypad 1 */
144 fgElevTrimMove(-0.001);
146 case 55: /* numeric keypad 7 */
147 fgElevTrimMove(0.001);
149 case 52: /* numeric keypad 4 */
150 fgAileronMove(-0.05);
152 case 54: /* numeric keypad 6 */
155 case 48: /* numeric keypad Ins */
158 case 13: /* numeric keypad Enter */
161 case 53: /* numeric keypad 5 */
166 case 57: /* numeric keypad 9 (Pg Up) */
167 fgThrottleMove(0, 0.01);
169 case 51: /* numeric keypad 3 (Pg Dn) */
170 fgThrottleMove(0, -0.01);
172 case 109: /* m key */
175 case 116: /* t key */
178 case 120: /* X key */
180 if ( o->fov < FG_FOV_MIN ) {
183 v->update_fov = TRUE;
185 case 122: /* z key */
186 w->visibility *= 1.10;
187 xglFogf (GL_FOG_START, w->visibility / 1000000.0 );
188 xglFogf(GL_FOG_END, w->visibility);
189 fgPrintf( FG_INPUT, FG_DEBUG,
190 "Fog density = %.4f\n", w->visibility);
193 // if( fg_DebugOutput ) {
194 // fclose( fg_DebugOutput );
196 fgPrintf( FG_INPUT, FG_EXIT,
197 "Program exiting normally at user request.\n");
203 /* Handle "special" keyboard events */
204 void GLUTspecialkey(int k, int x, int y) {
208 c = current_aircraft.controls;
211 fgPrintf( FG_INPUT, FG_DEBUG, "Special key hit = %d", k);
213 if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
214 fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
216 case GLUT_KEY_END: /* numeric keypad 1 */
217 v->goal_view_offset = FG_PI * 0.75;
219 case GLUT_KEY_DOWN: /* numeric keypad 2 */
220 v->goal_view_offset = FG_PI;
222 case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 */
223 v->goal_view_offset = FG_PI * 1.25;
225 case GLUT_KEY_LEFT: /* numeric keypad 4 */
226 v->goal_view_offset = FG_PI * 0.50;
228 case GLUT_KEY_RIGHT: /* numeric keypad 6 */
229 v->goal_view_offset = FG_PI * 1.50;
231 case GLUT_KEY_HOME: /* numeric keypad 7 */
232 v->goal_view_offset = FG_PI * 0.25;
234 case GLUT_KEY_UP: /* numeric keypad 8 */
235 v->goal_view_offset = 0.00;
237 case GLUT_KEY_PAGE_UP: /* numeric keypad 9 */
238 v->goal_view_offset = FG_PI * 1.75;
242 fgPrintf( FG_INPUT, FG_DEBUG, "\n");
251 fgAileronMove(-0.05);
256 case GLUT_KEY_HOME: /* numeric keypad 1 */
257 fgElevTrimMove(0.001);
259 case GLUT_KEY_END: /* numeric keypad 7 */
260 fgElevTrimMove(-0.001);
262 case GLUT_KEY_INSERT: /* numeric keypad Ins */
265 case 13: /* numeric keypad Enter */
268 case 53: /* numeric keypad 5 */
273 case GLUT_KEY_PAGE_UP: /* numeric keypad 9 (Pg Up) */
274 fgThrottleMove(0, 0.01);
276 case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 (Pg Dn) */
277 fgThrottleMove(0, -0.01);
285 /* Revision 1.10 1998/05/27 02:24:05 curt
286 /* View optimizations by Norman Vine.
288 * Revision 1.9 1998/05/16 13:05:21 curt
289 * Added limits to fov.
291 * Revision 1.8 1998/05/13 18:29:56 curt
292 * Added a keyboard binding to dynamically adjust field of view.
293 * Added a command line option to specify fov.
294 * Adjusted terrain color.
295 * Root path info moved to fgOPTIONS.
296 * Added ability to parse options out of a config file.
298 * Revision 1.7 1998/05/07 23:14:14 curt
299 * Added "D" key binding to set autopilot heading.
300 * Made frame rate calculation average out over last 10 frames.
301 * Borland C++ floating point exception workaround.
302 * Added a --tile-radius=n option.
304 * Revision 1.6 1998/04/28 01:20:20 curt
305 * Type-ified fgTIME and fgVIEW.
306 * Added a command line option to disable textures.
308 * Revision 1.5 1998/04/25 22:06:29 curt
309 * Edited cvs log messages in source files ... bad bad bad!
311 * Revision 1.4 1998/04/25 20:24:00 curt
312 * Cleaned up initialization sequence to eliminate interdependencies
313 * between sun position, lighting, and view position. This creates a
314 * valid single pass initialization path.
316 * Revision 1.3 1998/04/24 14:19:29 curt
319 * Revision 1.2 1998/04/24 00:49:17 curt
320 * Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
321 * Trying out some different option parsing code.
322 * Some code reorganization.
324 * Revision 1.1 1998/04/22 13:25:40 curt
325 * C++ - ifing the code.
326 * Starting a bit of reorganization of lighting code.
328 * Revision 1.33 1998/04/18 04:11:25 curt
329 * Moved fg_debug to it's own library, added zlib support.
331 * Revision 1.32 1998/04/14 02:21:01 curt
332 * Incorporated autopilot heading hold contributed by: Jeff Goeke-Smith
333 * <jgoeke@voyager.net>
335 * Revision 1.31 1998/04/08 23:34:05 curt
336 * Patch from Durk to fix trim reversal with numlock key active.
338 * Revision 1.30 1998/04/03 22:09:02 curt
339 * Converting to Gnu autoconf system.
341 * Revision 1.29 1998/02/07 15:29:40 curt
342 * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
343 * <chotchkiss@namg.us.anritsu.com>
345 * Revision 1.28 1998/02/03 23:20:23 curt
346 * Lots of little tweaks to fix various consistency problems discovered by
347 * Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
348 * passed arguments along to the real printf(). Also incorporated HUD changes
349 * by Michele America.
351 * Revision 1.27 1998/01/27 00:47:55 curt
352 * Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
353 * system and commandline/config file processing code.
355 * Revision 1.26 1998/01/19 19:27:07 curt
356 * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
357 * This should simplify things tremendously.
359 * Revision 1.25 1998/01/05 18:44:34 curt
360 * Add an option to advance/decrease time from keyboard.
362 * Revision 1.24 1997/12/30 16:36:46 curt
363 * Merged in Durk's changes ...
365 * Revision 1.23 1997/12/15 23:54:44 curt
366 * Add xgl wrappers for debugging.
367 * Generate terrain normals on the fly.
369 * Revision 1.22 1997/12/10 22:37:45 curt
370 * Prepended "fg" on the name of all global structures that didn't have it yet.
371 * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
373 * Revision 1.21 1997/08/27 21:32:23 curt
374 * Restructured view calculation code. Added stars.
376 * Revision 1.20 1997/08/27 03:30:13 curt
377 * Changed naming scheme of basic shared structures.
379 * Revision 1.19 1997/08/25 20:27:21 curt
380 * Merged in initial HUD and Joystick code.
382 * Revision 1.18 1997/08/22 21:34:38 curt
383 * Doing a bit of reorganizing and house cleaning.
385 * Revision 1.17 1997/07/19 22:34:02 curt
386 * Moved PI definitions to ../constants.h
387 * Moved random() stuff to ../Utils/ and renamed fg_random()
389 * Revision 1.16 1997/07/18 23:41:24 curt
390 * Tweaks for building with Cygnus Win32 compiler.
392 * Revision 1.15 1997/07/16 20:04:47 curt
393 * Minor tweaks to aid Win32 port.
395 * Revision 1.14 1997/07/12 03:50:20 curt
396 * Added an #include <Windows32/Base.h> to help compiling for Win32
398 * Revision 1.13 1997/06/25 15:39:46 curt
399 * Minor changes to compile with rsxnt/win32.
401 * Revision 1.12 1997/06/21 17:12:52 curt
402 * Capitalized subdirectory names.
404 * Revision 1.11 1997/06/18 04:10:31 curt
405 * A couple more runway tweaks ...
407 * Revision 1.10 1997/06/18 02:21:23 curt
410 * Revision 1.9 1997/06/02 03:40:06 curt
411 * A tiny bit more view tweaking.
413 * Revision 1.8 1997/06/02 03:01:38 curt
414 * Working on views (side, front, back, transitions, etc.)
416 * Revision 1.7 1997/05/31 19:16:25 curt
417 * Elevator trim added.
419 * Revision 1.6 1997/05/31 04:13:52 curt
422 * Continuing work on the LaRCsim flight model integration.
423 * Added some MSFS-like keyboard input handling.
425 * Revision 1.5 1997/05/30 23:26:19 curt
426 * Added elevator/aileron controls.
428 * Revision 1.4 1997/05/27 17:44:31 curt
429 * Renamed & rearranged variables and routines. Added some initial simple
430 * timer/alarm routines so the flight model can be updated on a regular
433 * Revision 1.3 1997/05/23 15:40:25 curt
434 * Added GNU copyright headers.
437 * Revision 1.2 1997/05/23 00:35:12 curt
438 * Trying to get fog to work ...
440 * Revision 1.1 1997/05/21 15:57:50 curt
441 * Renamed due to added GLUT support.
443 * Revision 1.2 1997/05/19 18:22:41 curt
444 * Parameter tweaking ... starting to stub in fog support.
446 * Revision 1.1 1997/05/16 16:05:51 curt