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