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