]> git.mxchange.org Git - flightgear.git/blob - Main/GLUTkey.cxx
Added a pause command "p"
[flightgear.git] / Main / GLUTkey.cxx
1 /**************************************************************************
2  * GLUTkey.c -- handle GLUT keyboard events
3  *
4  * Written by Curtis Olson, started May 1997.
5  *
6  * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
7  *
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.
12  *
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.
17  *
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.
21  *
22  * $Id$
23  * (Log is kept at end of this file)
24  **************************************************************************/
25
26
27 #ifdef HAVE_CONFIG_H
28 #  include <config.h>
29 #endif
30
31 #ifdef HAVE_WINDOWS_H
32 #  include <windows.h>                     
33 #endif
34
35 #include <GL/glut.h>
36 #include <XGL/xgl.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39
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>
44 #include <GUI/gui.h>
45 #include <Include/fg_constants.h>
46 #include <PUI/pu.h>
47 #include <Weather/weather.h>
48
49 #include "GLUTkey.hxx"
50 #include "options.hxx"
51 #include "views.hxx"
52
53 #if defined(FX) && defined(XMESA)
54 #  include <GL/xmesa.h>
55    static int fullscreen = 1;
56 #endif
57
58 /* Handle keyboard events */
59 void GLUTkey(unsigned char k, int x, int y) {
60     fgCONTROLS *c;
61     fgTIME *t;
62     fgVIEW *v;
63     struct fgWEATHER *w;
64     float fov, tmp;
65     int status;
66
67     c = current_aircraft.controls;
68     t = &cur_time_params;
69     v = &current_view;
70     w = &current_weather;
71
72     fgPrintf( FG_INPUT, FG_DEBUG, "Key hit = %d", k);
73     puKeyboard(k, PU_DOWN );
74
75     if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
76         fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
77         switch (k) {
78         case 49: /* numeric keypad 1 */
79             v->goal_view_offset = FG_PI * 0.75;
80             return;
81         case 50: /* numeric keypad 2 */
82             v->goal_view_offset = FG_PI;
83             return;
84         case 51: /* numeric keypad 3 */
85             v->goal_view_offset = FG_PI * 1.25;
86             return;
87         case 52: /* numeric keypad 4 */
88             v->goal_view_offset = FG_PI * 0.50;
89             return;
90         case 54: /* numeric keypad 6 */
91             v->goal_view_offset = FG_PI * 1.50;
92             return;
93         case 55: /* numeric keypad 7 */
94             v->goal_view_offset = FG_PI * 0.25;
95             return;
96         case 56: /* numeric keypad 8 */
97             v->goal_view_offset = 0.00;
98             return;
99         case 57: /* numeric keypad 9 */
100             v->goal_view_offset = FG_PI * 1.75;
101             return;
102         case 72: /* H key */
103             // status = current_options.get_hud_status();
104             // current_options.set_hud_status(!status);
105             HUD_brightkey( true );
106             return;
107         case 77: /* M key */
108             t->warp -= 60;
109             return;
110         case 84: /* T key */
111             t->warp_delta -= 30;
112             return;
113         case 87: /* W key */
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);
118 #endif
119 #endif
120             return;
121         case 88: /* X key */
122             fov = current_options.get_fov();
123             fov *= 1.05;
124             if ( fov > FG_FOV_MAX ) {
125                 fov = FG_FOV_MAX;
126             }
127             current_options.set_fov(fov);
128             v->update_fov = TRUE;
129             return;
130         case 90: /* Z key */
131             tmp = fgWeatherGetVisibility();   /* in meters */
132             tmp /= 1.10;
133             fgWeatherSetVisibility( tmp );
134             return;
135         // autopilot additions
136         case 65: /* A key */
137                 fgAPSetMode(1);
138                 return;
139         case 83: /* S key */
140                 fgAPSetMode(0);
141                 return;
142         case 68: /* D key */
143                 fgAPSetHeading(AP_CURRENT_HEADING);
144                 return;
145         }
146     } else {
147         fgPrintf( FG_INPUT, FG_DEBUG, "\n");
148         switch (k) {
149         case 50: /* numeric keypad 2 */
150             fgElevMove(-0.05);
151             return;
152         case 56: /* numeric keypad 8 */
153             fgElevMove(0.05);
154             return;
155         case 49: /* numeric keypad 1 */
156             fgElevTrimMove(-0.001);
157             return;
158         case 55: /* numeric keypad 7 */
159             fgElevTrimMove(0.001);
160             return;
161         case 52: /* numeric keypad 4 */
162             fgAileronMove(-0.05);
163             return;
164         case 54: /* numeric keypad 6 */
165             fgAileronMove(0.05);
166             return;
167         case 48: /* numeric keypad Ins */
168             fgRudderMove(-0.05);
169             return;
170         case 13: /* numeric keypad Enter */
171             fgRudderMove(0.05);
172             return;
173         case 53: /* numeric keypad 5 */
174             fgAileronSet(0.0);
175             fgElevSet(0.0);
176             fgRudderSet(0.0);
177             return;
178         case 57: /* numeric keypad 9 (Pg Up) */
179             fgThrottleMove(0, 0.01);
180             return;
181         case 51: /* numeric keypad 3 (Pg Dn) */
182             fgThrottleMove(0, -0.01);
183             return;
184         case 104: /* h key */
185             HUD_brightkey( false );
186             return;
187         case 109: /* m key */
188             t->warp += 60;
189             return;
190         case 112: /* p key */
191             t->pause = !t->pause;
192             return;
193         case 116: /* t key */
194             t->warp_delta += 30;
195             return;
196         case 120: /* X key */
197             fov = current_options.get_fov();
198             fov /= 1.05;
199             if ( fov < FG_FOV_MIN ) {
200                 fov = FG_FOV_MIN;
201             }
202             current_options.set_fov(fov);
203             v->update_fov = TRUE;
204             return;
205         case 122: /* z key */
206             tmp = fgWeatherGetVisibility();   /* in meters */
207             tmp *= 1.10;
208             fgWeatherSetVisibility( tmp );
209             return;
210         case 27: /* ESC */
211             // if( fg_DebugOutput ) {
212             //   fclose( fg_DebugOutput );
213             // }
214             fgPrintf( FG_INPUT, FG_EXIT, 
215                       "Program exiting normally at user request.\n");
216         }
217     }
218 }
219
220
221 /* Handle "special" keyboard events */
222 void GLUTspecialkey(int k, int x, int y) {
223     fgCONTROLS *c;
224     fgVIEW *v;
225
226     c = current_aircraft.controls;
227     v = &current_view;
228
229     fgPrintf( FG_INPUT, FG_DEBUG, "Special key hit = %d", k);
230     puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN);
231
232     if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
233         fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
234         switch (k) {
235         case GLUT_KEY_END: /* numeric keypad 1 */
236             v->goal_view_offset = FG_PI * 0.75;
237             return;
238         case GLUT_KEY_DOWN: /* numeric keypad 2 */
239             v->goal_view_offset = FG_PI;
240             return;
241         case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 */
242             v->goal_view_offset = FG_PI * 1.25;
243             return;
244         case GLUT_KEY_LEFT: /* numeric keypad 4 */
245             v->goal_view_offset = FG_PI * 0.50;
246             return;
247         case GLUT_KEY_RIGHT: /* numeric keypad 6 */
248             v->goal_view_offset = FG_PI * 1.50;
249             return;
250         case GLUT_KEY_HOME: /* numeric keypad 7 */
251             v->goal_view_offset = FG_PI * 0.25;
252             return;
253         case GLUT_KEY_UP: /* numeric keypad 8 */
254             v->goal_view_offset = 0.00;
255             return;
256         case GLUT_KEY_PAGE_UP: /* numeric keypad 9 */
257             v->goal_view_offset = FG_PI * 1.75;
258             return;
259         }
260     } else {
261         fgPrintf( FG_INPUT, FG_DEBUG, "\n");
262         switch (k) {
263         case GLUT_KEY_F10: /* F10 toggles menu on and off... */
264             printf("Invoking call back function");
265             hideMenuButton -> 
266                 setValue ((int) !(hideMenuButton -> getValue() ) );
267             hideMenuButton -> invokeCallback();
268             //exit(1);
269             return;
270         case GLUT_KEY_UP:
271             fgElevMove(0.05);
272             return;
273         case GLUT_KEY_DOWN:
274             fgElevMove(-0.05);
275             return;
276         case GLUT_KEY_LEFT:
277             fgAileronMove(-0.05);
278             return;
279         case GLUT_KEY_RIGHT:
280             fgAileronMove(0.05);
281             return;
282         case GLUT_KEY_HOME: /* numeric keypad 1 */
283             fgElevTrimMove(0.001);
284             return;
285         case GLUT_KEY_END: /* numeric keypad 7 */
286             fgElevTrimMove(-0.001);
287             return;
288         case GLUT_KEY_INSERT: /* numeric keypad Ins */
289             fgRudderMove(-0.05);
290             return;
291         case 13: /* numeric keypad Enter */
292             fgRudderMove(0.05);
293             return;
294         case 53: /* numeric keypad 5 */
295             fgAileronSet(0.0);
296             fgElevSet(0.0);
297             fgRudderSet(0.0);
298             return;
299         case GLUT_KEY_PAGE_UP: /* numeric keypad 9 (Pg Up) */
300             fgThrottleMove(0, 0.01);
301             return;
302         case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 (Pg Dn) */
303             fgThrottleMove(0, -0.01);
304             return;
305         }
306     }
307 }
308
309
310 /* $Log$
311 /* Revision 1.17  1998/07/27 18:41:23  curt
312 /* Added a pause command "p"
313 /* Fixed some initialization order problems between pui and glut.
314 /* Added an --enable/disable-sound option.
315 /*
316  * Revision 1.16  1998/07/16 17:33:34  curt
317  * "H" / "h" now control hud brightness as well with off being one of the
318  *   states.
319  * Better checking for xmesa/fx 3dfx fullscreen/window support for deciding
320  *   whether or not to build in the feature.
321  * Translucent menu support.
322  * HAVE_AUDIO_SUPPORT -> ENABLE_AUDIO_SUPPORT
323  * Use fork() / wait() for playing mp3 init music in background under unix.
324  * Changed default tile diameter to 5.
325  *
326  * Revision 1.15  1998/07/13 21:01:34  curt
327  * Wrote access functions for current fgOPTIONS.
328  *
329  * Revision 1.14  1998/07/06 02:42:02  curt
330  * Added support for switching between fullscreen and window mode for
331  * Mesa/3dfx/glide.
332  *
333  * Added a basic splash screen.  Restructured the main loop and top level
334  * initialization routines to do this.
335  *
336  * Hacked in some support for playing a startup mp3 sound file while rest
337  * of sim initializes.  Currently only works in Unix using the mpg123 player.
338  * Waits for the mpg123 player to finish before initializing internal
339  * sound drivers.
340  *
341  * Revision 1.13  1998/06/27 16:54:32  curt
342  * Replaced "extern displayInstruments" with a entry in fgOPTIONS.
343  * Don't change the view port when displaying the panel.
344  *
345  * Revision 1.12  1998/06/12 14:27:26  curt
346  * Pui -> PUI, Gui -> GUI.
347  *
348  * Revision 1.11  1998/06/12 00:57:38  curt
349  * Added support for Pui/Gui.
350  * Converted fog to GL_FOG_EXP2.
351  * Link to static simulator parts.
352  * Update runfg.bat to try to be a little smarter.
353  *
354  * Revision 1.10  1998/05/27 02:24:05  curt
355  * View optimizations by Norman Vine.
356  *
357  * Revision 1.9  1998/05/16 13:05:21  curt
358  * Added limits to fov.
359  *
360  * Revision 1.8  1998/05/13 18:29:56  curt
361  * Added a keyboard binding to dynamically adjust field of view.
362  * Added a command line option to specify fov.
363  * Adjusted terrain color.
364  * Root path info moved to fgOPTIONS.
365  * Added ability to parse options out of a config file.
366  *
367  * Revision 1.7  1998/05/07 23:14:14  curt
368  * Added "D" key binding to set autopilot heading.
369  * Made frame rate calculation average out over last 10 frames.
370  * Borland C++ floating point exception workaround.
371  * Added a --tile-radius=n option.
372  *
373  * Revision 1.6  1998/04/28 01:20:20  curt
374  * Type-ified fgTIME and fgVIEW.
375  * Added a command line option to disable textures.
376  *
377  * Revision 1.5  1998/04/25 22:06:29  curt
378  * Edited cvs log messages in source files ... bad bad bad!
379  *
380  * Revision 1.4  1998/04/25 20:24:00  curt
381  * Cleaned up initialization sequence to eliminate interdependencies
382  * between sun position, lighting, and view position.  This creates a
383  * valid single pass initialization path.
384  *
385  * Revision 1.3  1998/04/24 14:19:29  curt
386  * Fog tweaks.
387  *
388  * Revision 1.2  1998/04/24 00:49:17  curt
389  * Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
390  * Trying out some different option parsing code.
391  * Some code reorganization.
392  *
393  * Revision 1.1  1998/04/22 13:25:40  curt
394  * C++ - ifing the code.
395  * Starting a bit of reorganization of lighting code.
396  *
397  * Revision 1.33  1998/04/18 04:11:25  curt
398  * Moved fg_debug to it's own library, added zlib support.
399  *
400  * Revision 1.32  1998/04/14 02:21:01  curt
401  * Incorporated autopilot heading hold contributed by:  Jeff Goeke-Smith
402  * <jgoeke@voyager.net>
403  *
404  * Revision 1.31  1998/04/08 23:34:05  curt
405  * Patch from Durk to fix trim reversal with numlock key active.
406  *
407  * Revision 1.30  1998/04/03 22:09:02  curt
408  * Converting to Gnu autoconf system.
409  *
410  * Revision 1.29  1998/02/07 15:29:40  curt
411  * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
412  * <chotchkiss@namg.us.anritsu.com>
413  *
414  * Revision 1.28  1998/02/03 23:20:23  curt
415  * Lots of little tweaks to fix various consistency problems discovered by
416  * Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
417  * passed arguments along to the real printf().  Also incorporated HUD changes
418  * by Michele America.
419  *
420  * Revision 1.27  1998/01/27 00:47:55  curt
421  * Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
422  * system and commandline/config file processing code.
423  *
424  * Revision 1.26  1998/01/19 19:27:07  curt
425  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
426  * This should simplify things tremendously.
427  *
428  * Revision 1.25  1998/01/05 18:44:34  curt
429  * Add an option to advance/decrease time from keyboard.
430  *
431  * Revision 1.24  1997/12/30 16:36:46  curt
432  * Merged in Durk's changes ...
433  *
434  * Revision 1.23  1997/12/15 23:54:44  curt
435  * Add xgl wrappers for debugging.
436  * Generate terrain normals on the fly.
437  *
438  * Revision 1.22  1997/12/10 22:37:45  curt
439  * Prepended "fg" on the name of all global structures that didn't have it yet.
440  * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
441  *
442  * Revision 1.21  1997/08/27 21:32:23  curt
443  * Restructured view calculation code.  Added stars.
444  *
445  * Revision 1.20  1997/08/27 03:30:13  curt
446  * Changed naming scheme of basic shared structures.
447  *
448  * Revision 1.19  1997/08/25 20:27:21  curt
449  * Merged in initial HUD and Joystick code.
450  *
451  * Revision 1.18  1997/08/22 21:34:38  curt
452  * Doing a bit of reorganizing and house cleaning.
453  *
454  * Revision 1.17  1997/07/19 22:34:02  curt
455  * Moved PI definitions to ../constants.h
456  * Moved random() stuff to ../Utils/ and renamed fg_random()
457  *
458  * Revision 1.16  1997/07/18 23:41:24  curt
459  * Tweaks for building with Cygnus Win32 compiler.
460  *
461  * Revision 1.15  1997/07/16 20:04:47  curt
462  * Minor tweaks to aid Win32 port.
463  *
464  * Revision 1.14  1997/07/12 03:50:20  curt
465  * Added an #include <Windows32/Base.h> to help compiling for Win32
466  *
467  * Revision 1.13  1997/06/25 15:39:46  curt
468  * Minor changes to compile with rsxnt/win32.
469  *
470  * Revision 1.12  1997/06/21 17:12:52  curt
471  * Capitalized subdirectory names.
472  *
473  * Revision 1.11  1997/06/18 04:10:31  curt
474  * A couple more runway tweaks ...
475  *
476  * Revision 1.10  1997/06/18 02:21:23  curt
477  * Hacked in a runway
478  *
479  * Revision 1.9  1997/06/02 03:40:06  curt
480  * A tiny bit more view tweaking.
481  *
482  * Revision 1.8  1997/06/02 03:01:38  curt
483  * Working on views (side, front, back, transitions, etc.)
484  *
485  * Revision 1.7  1997/05/31 19:16:25  curt
486  * Elevator trim added.
487  *
488  * Revision 1.6  1997/05/31 04:13:52  curt
489  * WE CAN NOW FLY!!!
490  *
491  * Continuing work on the LaRCsim flight model integration.
492  * Added some MSFS-like keyboard input handling.
493  *
494  * Revision 1.5  1997/05/30 23:26:19  curt
495  * Added elevator/aileron controls.
496  *
497  * Revision 1.4  1997/05/27 17:44:31  curt
498  * Renamed & rearranged variables and routines.   Added some initial simple
499  * timer/alarm routines so the flight model can be updated on a regular 
500  * interval.
501  *
502  * Revision 1.3  1997/05/23 15:40:25  curt
503  * Added GNU copyright headers.
504  * Fog now works!
505  *
506  * Revision 1.2  1997/05/23 00:35:12  curt
507  * Trying to get fog to work ...
508  *
509  * Revision 1.1  1997/05/21 15:57:50  curt
510  * Renamed due to added GLUT support.
511  *
512  * Revision 1.2  1997/05/19 18:22:41  curt
513  * Parameter tweaking ... starting to stub in fog support.
514  *
515  * Revision 1.1  1997/05/16 16:05:51  curt
516  * Initial revision.
517  *
518  */