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