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 ) {
116 w->visibility /= 1.10;
117 xglFogf (GL_FOG_START, w->visibility / 1000000.0 );
118 xglFogf(GL_FOG_END, w->visibility);
119 fgPrintf( FG_INPUT, FG_DEBUG,
120 "Fog density = %.4f\n", w->visibility );
122 // autopilot additions
130 fgAPSetHeading(AP_CURRENT_HEADING);
134 fgPrintf( FG_INPUT, FG_DEBUG, "\n");
136 case 50: /* numeric keypad 2 */
139 case 56: /* numeric keypad 8 */
142 case 49: /* numeric keypad 1 */
143 fgElevTrimMove(-0.001);
145 case 55: /* numeric keypad 7 */
146 fgElevTrimMove(0.001);
148 case 52: /* numeric keypad 4 */
149 fgAileronMove(-0.05);
151 case 54: /* numeric keypad 6 */
154 case 48: /* numeric keypad Ins */
157 case 13: /* numeric keypad Enter */
160 case 53: /* numeric keypad 5 */
165 case 57: /* numeric keypad 9 (Pg Up) */
166 fgThrottleMove(0, 0.01);
168 case 51: /* numeric keypad 3 (Pg Dn) */
169 fgThrottleMove(0, -0.01);
171 case 109: /* m key */
174 case 116: /* t key */
177 case 120: /* X key */
179 if ( o->fov < FG_FOV_MIN ) {
183 case 122: /* z key */
184 w->visibility *= 1.10;
185 xglFogf (GL_FOG_START, w->visibility / 1000000.0 );
186 xglFogf(GL_FOG_END, w->visibility);
187 fgPrintf( FG_INPUT, FG_DEBUG,
188 "Fog density = %.4f\n", w->visibility);
191 // if( fg_DebugOutput ) {
192 // fclose( fg_DebugOutput );
194 fgPrintf( FG_INPUT, FG_EXIT,
195 "Program exiting normally at user request.\n");
201 /* Handle "special" keyboard events */
202 void GLUTspecialkey(int k, int x, int y) {
206 c = current_aircraft.controls;
209 fgPrintf( FG_INPUT, FG_DEBUG, "Special key hit = %d", k);
211 if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
212 fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
214 case GLUT_KEY_END: /* numeric keypad 1 */
215 v->goal_view_offset = FG_PI * 0.75;
217 case GLUT_KEY_DOWN: /* numeric keypad 2 */
218 v->goal_view_offset = FG_PI;
220 case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 */
221 v->goal_view_offset = FG_PI * 1.25;
223 case GLUT_KEY_LEFT: /* numeric keypad 4 */
224 v->goal_view_offset = FG_PI * 0.50;
226 case GLUT_KEY_RIGHT: /* numeric keypad 6 */
227 v->goal_view_offset = FG_PI * 1.50;
229 case GLUT_KEY_HOME: /* numeric keypad 7 */
230 v->goal_view_offset = FG_PI * 0.25;
232 case GLUT_KEY_UP: /* numeric keypad 8 */
233 v->goal_view_offset = 0.00;
235 case GLUT_KEY_PAGE_UP: /* numeric keypad 9 */
236 v->goal_view_offset = FG_PI * 1.75;
240 fgPrintf( FG_INPUT, FG_DEBUG, "\n");
249 fgAileronMove(-0.05);
254 case GLUT_KEY_HOME: /* numeric keypad 1 */
255 fgElevTrimMove(0.001);
257 case GLUT_KEY_END: /* numeric keypad 7 */
258 fgElevTrimMove(-0.001);
260 case GLUT_KEY_INSERT: /* numeric keypad Ins */
263 case 13: /* numeric keypad Enter */
266 case 53: /* numeric keypad 5 */
271 case GLUT_KEY_PAGE_UP: /* numeric keypad 9 (Pg Up) */
272 fgThrottleMove(0, 0.01);
274 case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 (Pg Dn) */
275 fgThrottleMove(0, -0.01);
283 /* Revision 1.9 1998/05/16 13:05:21 curt
284 /* Added limits to fov.
286 * Revision 1.8 1998/05/13 18:29:56 curt
287 * Added a keyboard binding to dynamically adjust field of view.
288 * Added a command line option to specify fov.
289 * Adjusted terrain color.
290 * Root path info moved to fgOPTIONS.
291 * Added ability to parse options out of a config file.
293 * Revision 1.7 1998/05/07 23:14:14 curt
294 * Added "D" key binding to set autopilot heading.
295 * Made frame rate calculation average out over last 10 frames.
296 * Borland C++ floating point exception workaround.
297 * Added a --tile-radius=n option.
299 * Revision 1.6 1998/04/28 01:20:20 curt
300 * Type-ified fgTIME and fgVIEW.
301 * Added a command line option to disable textures.
303 * Revision 1.5 1998/04/25 22:06:29 curt
304 * Edited cvs log messages in source files ... bad bad bad!
306 * Revision 1.4 1998/04/25 20:24:00 curt
307 * Cleaned up initialization sequence to eliminate interdependencies
308 * between sun position, lighting, and view position. This creates a
309 * valid single pass initialization path.
311 * Revision 1.3 1998/04/24 14:19:29 curt
314 * Revision 1.2 1998/04/24 00:49:17 curt
315 * Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
316 * Trying out some different option parsing code.
317 * Some code reorganization.
319 * Revision 1.1 1998/04/22 13:25:40 curt
320 * C++ - ifing the code.
321 * Starting a bit of reorganization of lighting code.
323 * Revision 1.33 1998/04/18 04:11:25 curt
324 * Moved fg_debug to it's own library, added zlib support.
326 * Revision 1.32 1998/04/14 02:21:01 curt
327 * Incorporated autopilot heading hold contributed by: Jeff Goeke-Smith
328 * <jgoeke@voyager.net>
330 * Revision 1.31 1998/04/08 23:34:05 curt
331 * Patch from Durk to fix trim reversal with numlock key active.
333 * Revision 1.30 1998/04/03 22:09:02 curt
334 * Converting to Gnu autoconf system.
336 * Revision 1.29 1998/02/07 15:29:40 curt
337 * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
338 * <chotchkiss@namg.us.anritsu.com>
340 * Revision 1.28 1998/02/03 23:20:23 curt
341 * Lots of little tweaks to fix various consistency problems discovered by
342 * Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
343 * passed arguments along to the real printf(). Also incorporated HUD changes
344 * by Michele America.
346 * Revision 1.27 1998/01/27 00:47:55 curt
347 * Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
348 * system and commandline/config file processing code.
350 * Revision 1.26 1998/01/19 19:27:07 curt
351 * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
352 * This should simplify things tremendously.
354 * Revision 1.25 1998/01/05 18:44:34 curt
355 * Add an option to advance/decrease time from keyboard.
357 * Revision 1.24 1997/12/30 16:36:46 curt
358 * Merged in Durk's changes ...
360 * Revision 1.23 1997/12/15 23:54:44 curt
361 * Add xgl wrappers for debugging.
362 * Generate terrain normals on the fly.
364 * Revision 1.22 1997/12/10 22:37:45 curt
365 * Prepended "fg" on the name of all global structures that didn't have it yet.
366 * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
368 * Revision 1.21 1997/08/27 21:32:23 curt
369 * Restructured view calculation code. Added stars.
371 * Revision 1.20 1997/08/27 03:30:13 curt
372 * Changed naming scheme of basic shared structures.
374 * Revision 1.19 1997/08/25 20:27:21 curt
375 * Merged in initial HUD and Joystick code.
377 * Revision 1.18 1997/08/22 21:34:38 curt
378 * Doing a bit of reorganizing and house cleaning.
380 * Revision 1.17 1997/07/19 22:34:02 curt
381 * Moved PI definitions to ../constants.h
382 * Moved random() stuff to ../Utils/ and renamed fg_random()
384 * Revision 1.16 1997/07/18 23:41:24 curt
385 * Tweaks for building with Cygnus Win32 compiler.
387 * Revision 1.15 1997/07/16 20:04:47 curt
388 * Minor tweaks to aid Win32 port.
390 * Revision 1.14 1997/07/12 03:50:20 curt
391 * Added an #include <Windows32/Base.h> to help compiling for Win32
393 * Revision 1.13 1997/06/25 15:39:46 curt
394 * Minor changes to compile with rsxnt/win32.
396 * Revision 1.12 1997/06/21 17:12:52 curt
397 * Capitalized subdirectory names.
399 * Revision 1.11 1997/06/18 04:10:31 curt
400 * A couple more runway tweaks ...
402 * Revision 1.10 1997/06/18 02:21:23 curt
405 * Revision 1.9 1997/06/02 03:40:06 curt
406 * A tiny bit more view tweaking.
408 * Revision 1.8 1997/06/02 03:01:38 curt
409 * Working on views (side, front, back, transitions, etc.)
411 * Revision 1.7 1997/05/31 19:16:25 curt
412 * Elevator trim added.
414 * Revision 1.6 1997/05/31 04:13:52 curt
417 * Continuing work on the LaRCsim flight model integration.
418 * Added some MSFS-like keyboard input handling.
420 * Revision 1.5 1997/05/30 23:26:19 curt
421 * Added elevator/aileron controls.
423 * Revision 1.4 1997/05/27 17:44:31 curt
424 * Renamed & rearranged variables and routines. Added some initial simple
425 * timer/alarm routines so the flight model can be updated on a regular
428 * Revision 1.3 1997/05/23 15:40:25 curt
429 * Added GNU copyright headers.
432 * Revision 1.2 1997/05/23 00:35:12 curt
433 * Trying to get fog to work ...
435 * Revision 1.1 1997/05/21 15:57:50 curt
436 * Renamed due to added GLUT support.
438 * Revision 1.2 1997/05/19 18:22:41 curt
439 * Parameter tweaking ... starting to stub in fog support.
441 * Revision 1.1 1997/05/16 16:05:51 curt