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