]> git.mxchange.org Git - flightgear.git/blob - Main/GLUTkey.c
4c451f1e6eb90a78ca3d2b384ccd225f00cc467c
[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 <math.h>
28 #include <stdio.h>
29
30 #include <GL/glut.h>
31
32 #include "GLUTkey.h"
33 #include "../Aircraft/aircraft.h"
34
35 extern double fogDensity;
36 extern double goal_view_offset;
37
38 /* Handle keyboard events */
39 void GLUTkey(unsigned char k, int x, int y) {
40     struct control_params *c;
41
42     c = &current_aircraft.controls;
43
44     printf("Key hit = %d\n", k);
45
46     if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
47         switch (k) {
48         case 49: /* numeric keypad 1 */
49             goal_view_offset = M_PI * 0.75;
50             return;
51         case 50: /* numeric keypad 2 */
52             goal_view_offset = M_PI;
53             return;
54         case 51: /* numeric keypad 3 */
55             goal_view_offset = M_PI * 1.25;
56             return;
57         case 52: /* numeric keypad 4 */
58             goal_view_offset = M_PI * 0.50;
59             return;
60         case 54: /* numeric keypad 6 */
61             goal_view_offset = M_PI * 1.50;
62             return;
63         case 55: /* numeric keypad 7 */
64             goal_view_offset = M_PI * 0.25;
65             return;
66         case 56: /* numeric keypad 8 */
67             goal_view_offset = 0.00;
68             return;
69         case 57: /* numeric keypad 9 */
70             goal_view_offset = M_PI * 1.75;
71             return;
72         }
73     } else {
74         switch (k) {
75         case 50: /* numeric keypad 2 */
76             fgElevMove(-0.05);
77             return;
78         case 56: /* numeric keypad 8 */
79             fgElevMove(0.05);
80             return;
81         case 49: /* numeric keypad 1 */
82             fgElevTrimMove(-0.001);
83             return;
84         case 55: /* numeric keypad 7 */
85             fgElevTrimMove(0.001);
86             return;
87         case 52: /* numeric keypad 4 */
88             fgAileronMove(-0.05);
89             return;
90         case 54: /* numeric keypad 6 */
91             fgAileronMove(0.05);
92             return;
93         case 48: /* numeric keypad Ins */
94             fgRudderMove(-0.05);
95             return;
96         case 13: /* numeric keypad Enter */
97             fgRudderMove(0.05);
98             return;
99         case 53: /* numeric keypad 5 */
100             fgAileronSet(0.0);
101             fgElevSet(0.0);
102             fgRudderSet(0.0);
103             return;
104         case 57: /* numeric keypad 9 (Pg Up) */
105             fgThrottleMove(0, 0.01);
106             return;
107         case 51: /* numeric keypad 3 (Pg Dn) */
108             fgThrottleMove(0, -0.01);
109             return;
110         case 122:
111             fogDensity *= 1.10;
112             glFogf(GL_FOG_END, fogDensity);
113             printf("Fog density = %.4f\n", fogDensity);
114             return;
115         case 90:
116             fogDensity /= 1.10;
117             glFogf(GL_FOG_END, fogDensity);
118             printf("Fog density = %.4f\n", fogDensity);
119             return;
120         case 27: /* ESC */
121             exit(0);
122         }
123     }
124
125 }
126
127
128 /* Handle "special" keyboard events */
129 void GLUTspecialkey(int k, int x, int y) {
130     struct control_params *c;
131
132     c = &current_aircraft.controls;
133
134     printf("Special key hit = %d\n", k);
135
136     switch (k) {
137     case GLUT_KEY_UP:
138         fgElevMove(0.05);
139         return;
140     case GLUT_KEY_DOWN:
141         fgElevMove(-0.05);
142         return;
143     case GLUT_KEY_LEFT:
144         fgAileronMove(-0.05);
145         return;
146     case GLUT_KEY_RIGHT:
147         fgAileronMove(0.05);
148         return;
149     }
150
151 }
152
153
154 /* $Log$
155 /* Revision 1.12  1997/06/21 17:12:52  curt
156 /* Capitalized subdirectory names.
157 /*
158  * Revision 1.11  1997/06/18 04:10:31  curt
159  * A couple more runway tweaks ...
160  *
161  * Revision 1.10  1997/06/18 02:21:23  curt
162  * Hacked in a runway
163  *
164  * Revision 1.9  1997/06/02 03:40:06  curt
165  * A tiny bit more view tweaking.
166  *
167  * Revision 1.8  1997/06/02 03:01:38  curt
168  * Working on views (side, front, back, transitions, etc.)
169  *
170  * Revision 1.7  1997/05/31 19:16:25  curt
171  * Elevator trim added.
172  *
173  * Revision 1.6  1997/05/31 04:13:52  curt
174  * WE CAN NOW FLY!!!
175  *
176  * Continuing work on the LaRCsim flight model integration.
177  * Added some MSFS-like keyboard input handling.
178  *
179  * Revision 1.5  1997/05/30 23:26:19  curt
180  * Added elevator/aileron controls.
181  *
182  * Revision 1.4  1997/05/27 17:44:31  curt
183  * Renamed & rearranged variables and routines.   Added some initial simple
184  * timer/alarm routines so the flight model can be updated on a regular interval.
185  *
186  * Revision 1.3  1997/05/23 15:40:25  curt
187  * Added GNU copyright headers.
188  * Fog now works!
189  *
190  * Revision 1.2  1997/05/23 00:35:12  curt
191  * Trying to get fog to work ...
192  *
193  * Revision 1.1  1997/05/21 15:57:50  curt
194  * Renamed due to added GLUT support.
195  *
196  * Revision 1.2  1997/05/19 18:22:41  curt
197  * Parameter tweaking ... starting to stub in fog support.
198  *
199  * Revision 1.1  1997/05/16 16:05:51  curt
200  * Initial revision.
201  *
202  */