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