]> git.mxchange.org Git - flightgear.git/blob - Main/GLUTkey.cxx
C++ - ifing the code.
[flightgear.git] / Main / GLUTkey.cxx
1 /**************************************************************************
2  * GLUTkey.c -- handle GLUT 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 <config.h>
28
29 #ifdef HAVE_WINDOWS_H
30 #  include <windows.h>                     
31 #endif
32
33 #include <GL/glut.h>
34 #include <XGL/xgl.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37
38 #include <Aircraft/aircraft.h>
39 #include <Autopilot/autopilot.h> // Added autopilot.h to list, Jeff Goeke-Smith
40 #include <Debug/fg_debug.h>
41 #include <Include/fg_constants.h>
42 #include <Weather/weather.h>
43
44 #include "GLUTkey.hxx"
45 #include "views.hxx"
46
47
48 extern int show_hud;             /* HUD state */
49 extern int displayInstruments;
50
51
52 /* Handle keyboard events */
53 void GLUTkey(unsigned char k, int x, int y) {
54     fgCONTROLS *c;
55     struct fgTIME *t;
56     struct fgVIEW *v;
57     struct fgWEATHER *w;
58
59     c = current_aircraft.controls;
60     t = &cur_time_params;
61     v = &current_view;
62     w = &current_weather;
63
64     fgPrintf( FG_INPUT, FG_DEBUG, "Key hit = %d", k);
65
66     if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
67         fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
68         switch (k) {
69         case 49: /* numeric keypad 1 */
70             v->goal_view_offset = FG_PI * 0.75;
71             return;
72         case 50: /* numeric keypad 2 */
73             v->goal_view_offset = FG_PI;
74             return;
75         case 51: /* numeric keypad 3 */
76             v->goal_view_offset = FG_PI * 1.25;
77             return;
78         case 52: /* numeric keypad 4 */
79             v->goal_view_offset = FG_PI * 0.50;
80             return;
81         case 54: /* numeric keypad 6 */
82             v->goal_view_offset = FG_PI * 1.50;
83             return;
84         case 55: /* numeric keypad 7 */
85             v->goal_view_offset = FG_PI * 0.25;
86             return;
87         case 56: /* numeric keypad 8 */
88             v->goal_view_offset = 0.00;
89             return;
90         case 57: /* numeric keypad 9 */
91             v->goal_view_offset = FG_PI * 1.75;
92             return;
93         case 72: /* H key */
94             show_hud = !show_hud;
95             return;
96         case 77: /* M key */
97             t->warp -= 60;
98             return;
99         case 84: /* T key */
100             t->warp_delta -= 30;
101             return;
102         case 87: /* W key */
103             displayInstruments = !displayInstruments;
104             return;
105         case 90: /* Z key */
106             w->visibility /= 1.10;
107             xglFogf(GL_FOG_END, w->visibility);
108             fgPrintf( FG_INPUT, FG_DEBUG, 
109                       "Fog density = %.4f\n", w->visibility );
110             return;
111         // autopilot additions
112         case 65: /* A key */
113                 fgAPSetMode(1);
114                 return;
115         case 83: /* S key */
116                 fgAPSetMode(0);
117                 return;
118                 
119         }
120     } else {
121         fgPrintf( FG_INPUT, FG_DEBUG, "\n");
122         switch (k) {
123         case 50: /* numeric keypad 2 */
124             fgElevMove(-0.05);
125             return;
126         case 56: /* numeric keypad 8 */
127             fgElevMove(0.05);
128             return;
129         case 49: /* numeric keypad 1 */
130             fgElevTrimMove(-0.001);
131             return;
132         case 55: /* numeric keypad 7 */
133             fgElevTrimMove(0.001);
134             return;
135         case 52: /* numeric keypad 4 */
136             fgAileronMove(-0.05);
137             return;
138         case 54: /* numeric keypad 6 */
139             fgAileronMove(0.05);
140             return;
141         case 48: /* numeric keypad Ins */
142             fgRudderMove(-0.05);
143             return;
144         case 13: /* numeric keypad Enter */
145             fgRudderMove(0.05);
146             return;
147         case 53: /* numeric keypad 5 */
148             fgAileronSet(0.0);
149             fgElevSet(0.0);
150             fgRudderSet(0.0);
151             return;
152         case 57: /* numeric keypad 9 (Pg Up) */
153             fgThrottleMove(0, 0.01);
154             return;
155         case 51: /* numeric keypad 3 (Pg Dn) */
156             fgThrottleMove(0, -0.01);
157             return;
158         case 109: /* m key */
159             t->warp += 60;
160             return;
161         case 116: /* t key */
162             t->warp_delta += 30;
163             return;
164         case 122: /* z key */
165             w->visibility *= 1.10;
166             xglFogf(GL_FOG_END, w->visibility);
167             fgPrintf( FG_INPUT, FG_DEBUG, "Fog density = %.4f\n", w->visibility);
168             return;
169         case 27: /* ESC */
170             exit(0);
171         }
172     }
173
174 }
175
176
177 /* Handle "special" keyboard events */
178 void GLUTspecialkey(int k, int x, int y) {
179     fgCONTROLS *c;
180     struct fgVIEW *v;
181
182     c = current_aircraft.controls;
183     v = &current_view;
184
185     fgPrintf( FG_INPUT, FG_DEBUG, "Special key hit = %d", k);
186
187     if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
188         fgPrintf( FG_INPUT, FG_DEBUG, " SHIFTED\n");
189         switch (k) {
190         case GLUT_KEY_END: /* numeric keypad 1 */
191             v->goal_view_offset = FG_PI * 0.75;
192             return;
193         case GLUT_KEY_DOWN: /* numeric keypad 2 */
194             v->goal_view_offset = FG_PI;
195             return;
196         case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 */
197             v->goal_view_offset = FG_PI * 1.25;
198             return;
199         case GLUT_KEY_LEFT: /* numeric keypad 4 */
200             v->goal_view_offset = FG_PI * 0.50;
201             return;
202         case GLUT_KEY_RIGHT: /* numeric keypad 6 */
203             v->goal_view_offset = FG_PI * 1.50;
204             return;
205         case GLUT_KEY_HOME: /* numeric keypad 7 */
206             v->goal_view_offset = FG_PI * 0.25;
207             return;
208         case GLUT_KEY_UP: /* numeric keypad 8 */
209             v->goal_view_offset = 0.00;
210             return;
211         case GLUT_KEY_PAGE_UP: /* numeric keypad 9 */
212             v->goal_view_offset = FG_PI * 1.75;
213             return;
214         }
215     } else {
216         fgPrintf( FG_INPUT, FG_DEBUG, "\n");
217         switch (k) {
218         case GLUT_KEY_UP:
219             fgElevMove(0.05);
220             return;
221         case GLUT_KEY_DOWN:
222             fgElevMove(-0.05);
223             return;
224         case GLUT_KEY_LEFT:
225             fgAileronMove(-0.05);
226             return;
227         case GLUT_KEY_RIGHT:
228             fgAileronMove(0.05);
229             return;
230         case GLUT_KEY_HOME: /* numeric keypad 1 */
231             fgElevTrimMove(0.001);
232             return;
233         case GLUT_KEY_END: /* numeric keypad 7 */
234             fgElevTrimMove(-0.001);
235             return;
236         case GLUT_KEY_INSERT: /* numeric keypad Ins */
237             fgRudderMove(-0.05);
238             return;
239         case 13: /* numeric keypad Enter */
240             fgRudderMove(0.05);
241             return;
242         case 53: /* numeric keypad 5 */
243             fgAileronSet(0.0);
244             fgElevSet(0.0);
245             fgRudderSet(0.0);
246             return;
247         case GLUT_KEY_PAGE_UP: /* numeric keypad 9 (Pg Up) */
248             fgThrottleMove(0, 0.01);
249             return;
250         case GLUT_KEY_PAGE_DOWN: /* numeric keypad 3 (Pg Dn) */
251             fgThrottleMove(0, -0.01);
252             return;
253         }
254     }
255 }
256
257
258 /* $Log$
259 /* Revision 1.1  1998/04/22 13:25:40  curt
260 /* C++ - ifing the code.
261 /* Starting a bit of reorganization of lighting code.
262 /*
263  * Revision 1.33  1998/04/18 04:11:25  curt
264  * Moved fg_debug to it's own library, added zlib support.
265  *
266  * Revision 1.32  1998/04/14 02:21:01  curt
267  * Incorporated autopilot heading hold contributed by:  Jeff Goeke-Smith
268  * <jgoeke@voyager.net>
269  *
270  * Revision 1.31  1998/04/08 23:34:05  curt
271  * Patch from Durk to fix trim reversal with numlock key active.
272  *
273  * Revision 1.30  1998/04/03 22:09:02  curt
274  * Converting to Gnu autoconf system.
275  *
276  * Revision 1.29  1998/02/07 15:29:40  curt
277  * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
278  * <chotchkiss@namg.us.anritsu.com>
279  *
280  * Revision 1.28  1998/02/03 23:20:23  curt
281  * Lots of little tweaks to fix various consistency problems discovered by
282  * Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
283  * passed arguments along to the real printf().  Also incorporated HUD changes
284  * by Michele America.
285  *
286  * Revision 1.27  1998/01/27 00:47:55  curt
287  * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
288  * system and commandline/config file processing code.
289  *
290  * Revision 1.26  1998/01/19 19:27:07  curt
291  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
292  * This should simplify things tremendously.
293  *
294  * Revision 1.25  1998/01/05 18:44:34  curt
295  * Add an option to advance/decrease time from keyboard.
296  *
297  * Revision 1.24  1997/12/30 16:36:46  curt
298  * Merged in Durk's changes ...
299  *
300  * Revision 1.23  1997/12/15 23:54:44  curt
301  * Add xgl wrappers for debugging.
302  * Generate terrain normals on the fly.
303  *
304  * Revision 1.22  1997/12/10 22:37:45  curt
305  * Prepended "fg" on the name of all global structures that didn't have it yet.
306  * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
307  *
308  * Revision 1.21  1997/08/27 21:32:23  curt
309  * Restructured view calculation code.  Added stars.
310  *
311  * Revision 1.20  1997/08/27 03:30:13  curt
312  * Changed naming scheme of basic shared structures.
313  *
314  * Revision 1.19  1997/08/25 20:27:21  curt
315  * Merged in initial HUD and Joystick code.
316  *
317  * Revision 1.18  1997/08/22 21:34:38  curt
318  * Doing a bit of reorganizing and house cleaning.
319  *
320  * Revision 1.17  1997/07/19 22:34:02  curt
321  * Moved PI definitions to ../constants.h
322  * Moved random() stuff to ../Utils/ and renamed fg_random()
323  *
324  * Revision 1.16  1997/07/18 23:41:24  curt
325  * Tweaks for building with Cygnus Win32 compiler.
326  *
327  * Revision 1.15  1997/07/16 20:04:47  curt
328  * Minor tweaks to aid Win32 port.
329  *
330  * Revision 1.14  1997/07/12 03:50:20  curt
331  * Added an #include <Windows32/Base.h> to help compiling for Win32
332  *
333  * Revision 1.13  1997/06/25 15:39:46  curt
334  * Minor changes to compile with rsxnt/win32.
335  *
336  * Revision 1.12  1997/06/21 17:12:52  curt
337  * Capitalized subdirectory names.
338  *
339  * Revision 1.11  1997/06/18 04:10:31  curt
340  * A couple more runway tweaks ...
341  *
342  * Revision 1.10  1997/06/18 02:21:23  curt
343  * Hacked in a runway
344  *
345  * Revision 1.9  1997/06/02 03:40:06  curt
346  * A tiny bit more view tweaking.
347  *
348  * Revision 1.8  1997/06/02 03:01:38  curt
349  * Working on views (side, front, back, transitions, etc.)
350  *
351  * Revision 1.7  1997/05/31 19:16:25  curt
352  * Elevator trim added.
353  *
354  * Revision 1.6  1997/05/31 04:13:52  curt
355  * WE CAN NOW FLY!!!
356  *
357  * Continuing work on the LaRCsim flight model integration.
358  * Added some MSFS-like keyboard input handling.
359  *
360  * Revision 1.5  1997/05/30 23:26:19  curt
361  * Added elevator/aileron controls.
362  *
363  * Revision 1.4  1997/05/27 17:44:31  curt
364  * Renamed & rearranged variables and routines.   Added some initial simple
365  * timer/alarm routines so the flight model can be updated on a regular interval.
366  *
367  * Revision 1.3  1997/05/23 15:40:25  curt
368  * Added GNU copyright headers.
369  * Fog now works!
370  *
371  * Revision 1.2  1997/05/23 00:35:12  curt
372  * Trying to get fog to work ...
373  *
374  * Revision 1.1  1997/05/21 15:57:50  curt
375  * Renamed due to added GLUT support.
376  *
377  * Revision 1.2  1997/05/19 18:22:41  curt
378  * Parameter tweaking ... starting to stub in fog support.
379  *
380  * Revision 1.1  1997/05/16 16:05:51  curt
381  * Initial revision.
382  *
383  */