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