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