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