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