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 **************************************************************************/
38 #include <Main/GLUTkey.h>
39 #include <Main/fg_debug.h>
40 #include <Main/views.h>
42 #include <Include/fg_constants.h>
44 #include <Aircraft/aircraft.h>
45 #include <Weather/weather.h>
48 extern int show_hud; /* HUD state */
49 extern int displayInstruments;
52 /* Handle keyboard events */
53 void GLUTkey(unsigned char k, int x, int y) {
59 c = current_aircraft.controls;
64 fgPrintf( FG_INPUT, FG_DEBUG, "Key hit = %d", k);
66 if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
67 fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
69 case 49: /* numeric keypad 1 */
70 v->goal_view_offset = FG_PI * 0.75;
72 case 50: /* numeric keypad 2 */
73 v->goal_view_offset = FG_PI;
75 case 51: /* numeric keypad 3 */
76 v->goal_view_offset = FG_PI * 1.25;
78 case 52: /* numeric keypad 4 */
79 v->goal_view_offset = FG_PI * 0.50;
81 case 54: /* numeric keypad 6 */
82 v->goal_view_offset = FG_PI * 1.50;
84 case 55: /* numeric keypad 7 */
85 v->goal_view_offset = FG_PI * 0.25;
87 case 56: /* numeric keypad 8 */
88 v->goal_view_offset = 0.00;
90 case 57: /* numeric keypad 9 */
91 v->goal_view_offset = FG_PI * 1.75;
103 displayInstruments = !displayInstruments;
106 w->visibility /= 1.10;
107 xglFogf(GL_FOG_END, w->visibility);
108 fgPrintf( FG_INPUT, FG_DEBUG, "Fog density = %.4f\n", w->visibility);
112 fgPrintf( FG_INPUT, FG_DEBUG, "\n");
114 case 50: /* numeric keypad 2 */
117 case 56: /* numeric keypad 8 */
120 case 49: /* numeric keypad 1 */
121 fgElevTrimMove(-0.001);
123 case 55: /* numeric keypad 7 */
124 fgElevTrimMove(0.001);
126 case 52: /* numeric keypad 4 */
127 fgAileronMove(-0.05);
129 case 54: /* numeric keypad 6 */
132 case 48: /* numeric keypad Ins */
135 case 13: /* numeric keypad Enter */
138 case 53: /* numeric keypad 5 */
143 case 57: /* numeric keypad 9 (Pg Up) */
144 fgThrottleMove(0, 0.01);
146 case 51: /* numeric keypad 3 (Pg Dn) */
147 fgThrottleMove(0, -0.01);
149 case 109: /* m key */
152 case 116: /* t key */
155 case 122: /* z key */
156 w->visibility *= 1.10;
157 xglFogf(GL_FOG_END, w->visibility);
158 fgPrintf( FG_INPUT, FG_DEBUG, "Fog density = %.4f\n", w->visibility);
168 /* Handle "special" keyboard events */
169 void GLUTspecialkey(int k, int x, int y) {
173 c = current_aircraft.controls;
176 fgPrintf( FG_INPUT, FG_DEBUG, "Special key hit = %d", k);
178 if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
179 fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
181 case GLUT_KEY_END: /* numeric keypad 1 */
182 v->goal_view_offset = FG_PI * 0.75;
184 case GLUT_KEY_DOWN: /* numeric keypad 2 */
185 v->goal_view_offset = FG_PI;
187 case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 */
188 v->goal_view_offset = FG_PI * 1.25;
190 case GLUT_KEY_LEFT: /* numeric keypad 4 */
191 v->goal_view_offset = FG_PI * 0.50;
193 case GLUT_KEY_RIGHT: /* numeric keypad 6 */
194 v->goal_view_offset = FG_PI * 1.50;
196 case GLUT_KEY_HOME: /* numeric keypad 7 */
197 v->goal_view_offset = FG_PI * 0.25;
199 case GLUT_KEY_UP: /* numeric keypad 8 */
200 v->goal_view_offset = 0.00;
202 case GLUT_KEY_PAGE_UP: /* numeric keypad 9 */
203 v->goal_view_offset = FG_PI * 1.75;
207 fgPrintf( FG_INPUT, FG_DEBUG, "\n");
216 fgAileronMove(-0.05);
221 case GLUT_KEY_HOME: /* numeric keypad 1 */
222 fgElevTrimMove(0.001);
224 case GLUT_KEY_END: /* numeric keypad 7 */
225 fgElevTrimMove(-0.001);
227 case GLUT_KEY_INSERT: /* numeric keypad Ins */
230 case 13: /* numeric keypad Enter */
233 case 53: /* numeric keypad 5 */
238 case GLUT_KEY_PAGE_UP: /* numeric keypad 9 (Pg Up) */
239 fgThrottleMove(0, 0.01);
241 case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 (Pg Dn) */
242 fgThrottleMove(0, -0.01);
250 /* Revision 1.31 1998/04/08 23:34:05 curt
251 /* Patch from Durk to fix trim reversal with numlock key active.
253 * Revision 1.30 1998/04/03 22:09:02 curt
254 * Converting to Gnu autoconf system.
256 * Revision 1.29 1998/02/07 15:29:40 curt
257 * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
258 * <chotchkiss@namg.us.anritsu.com>
260 * Revision 1.28 1998/02/03 23:20:23 curt
261 * Lots of little tweaks to fix various consistency problems discovered by
262 * Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
263 * passed arguments along to the real printf(). Also incorporated HUD changes
264 * by Michele America.
266 * Revision 1.27 1998/01/27 00:47:55 curt
267 * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
268 * system and commandline/config file processing code.
270 * Revision 1.26 1998/01/19 19:27:07 curt
271 * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
272 * This should simplify things tremendously.
274 * Revision 1.25 1998/01/05 18:44:34 curt
275 * Add an option to advance/decrease time from keyboard.
277 * Revision 1.24 1997/12/30 16:36:46 curt
278 * Merged in Durk's changes ...
280 * Revision 1.23 1997/12/15 23:54:44 curt
281 * Add xgl wrappers for debugging.
282 * Generate terrain normals on the fly.
284 * Revision 1.22 1997/12/10 22:37:45 curt
285 * Prepended "fg" on the name of all global structures that didn't have it yet.
286 * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
288 * Revision 1.21 1997/08/27 21:32:23 curt
289 * Restructured view calculation code. Added stars.
291 * Revision 1.20 1997/08/27 03:30:13 curt
292 * Changed naming scheme of basic shared structures.
294 * Revision 1.19 1997/08/25 20:27:21 curt
295 * Merged in initial HUD and Joystick code.
297 * Revision 1.18 1997/08/22 21:34:38 curt
298 * Doing a bit of reorganizing and house cleaning.
300 * Revision 1.17 1997/07/19 22:34:02 curt
301 * Moved PI definitions to ../constants.h
302 * Moved random() stuff to ../Utils/ and renamed fg_random()
304 * Revision 1.16 1997/07/18 23:41:24 curt
305 * Tweaks for building with Cygnus Win32 compiler.
307 * Revision 1.15 1997/07/16 20:04:47 curt
308 * Minor tweaks to aid Win32 port.
310 * Revision 1.14 1997/07/12 03:50:20 curt
311 * Added an #include <Windows32/Base.h> to help compiling for Win32
313 * Revision 1.13 1997/06/25 15:39:46 curt
314 * Minor changes to compile with rsxnt/win32.
316 * Revision 1.12 1997/06/21 17:12:52 curt
317 * Capitalized subdirectory names.
319 * Revision 1.11 1997/06/18 04:10:31 curt
320 * A couple more runway tweaks ...
322 * Revision 1.10 1997/06/18 02:21:23 curt
325 * Revision 1.9 1997/06/02 03:40:06 curt
326 * A tiny bit more view tweaking.
328 * Revision 1.8 1997/06/02 03:01:38 curt
329 * Working on views (side, front, back, transitions, etc.)
331 * Revision 1.7 1997/05/31 19:16:25 curt
332 * Elevator trim added.
334 * Revision 1.6 1997/05/31 04:13:52 curt
337 * Continuing work on the LaRCsim flight model integration.
338 * Added some MSFS-like keyboard input handling.
340 * Revision 1.5 1997/05/30 23:26:19 curt
341 * Added elevator/aileron controls.
343 * Revision 1.4 1997/05/27 17:44:31 curt
344 * Renamed & rearranged variables and routines. Added some initial simple
345 * timer/alarm routines so the flight model can be updated on a regular interval.
347 * Revision 1.3 1997/05/23 15:40:25 curt
348 * Added GNU copyright headers.
351 * Revision 1.2 1997/05/23 00:35:12 curt
352 * Trying to get fog to work ...
354 * Revision 1.1 1997/05/21 15:57:50 curt
355 * Renamed due to added GLUT support.
357 * Revision 1.2 1997/05/19 18:22:41 curt
358 * Parameter tweaking ... starting to stub in fog support.
360 * Revision 1.1 1997/05/16 16:05:51 curt