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