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