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