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