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