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