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