1 // GLUTkey.cxx -- handle GLUT keyboard events
3 // Written by Curtis Olson, started May 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@me.umn.edu
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 #if defined(FX) && defined(XMESA)
42 #include <Debug/logstream.hxx>
43 #include <Aircraft/aircraft.hxx>
44 #include <Astro/solarsystem.hxx>
45 #include <Astro/sky.hxx>
46 #include <Autopilot/autopilot.hxx>
47 #include <Cockpit/hud.hxx>
49 #include <Include/fg_constants.h>
50 #include <Objects/materialmgr.hxx>
52 #include <Time/light.hxx>
53 #include <Weather/weather.hxx>
55 #include "GLUTkey.hxx"
56 #include "options.hxx"
59 // extern void NewAltitude( puObject *cb );
60 // extern void NewHeading( puObject *cb );
62 // Force an update of the sky and lighting parameters
63 static void local_update_sky_and_lighting_params( void ) {
65 SolarSystem::theSolarSystem->rebuild();
66 cur_light_params.Update();
71 // Handle keyboard events
72 void GLUTkey(unsigned char k, int x, int y) {
78 static bool winding_ccw = true;
80 f = current_aircraft.fdm_state;
81 t = FGTime::cur_time_params;
85 FG_LOG( FG_INPUT, FG_DEBUG, "Key hit = " << k );
86 puKeyboard(k, PU_DOWN );
88 if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
89 FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
97 case 18: // Ctrl-R key
99 winding_ccw = !winding_ccw;
101 glFrontFace ( GL_CCW );
103 glFrontFace ( GL_CW );
106 case 19: // Ctrl-S key
107 fgAPToggleAutoThrottle();
109 case 20: // Ctrl-T key
110 fgAPToggleTerrainFollow();
112 case 49: // numeric keypad 1
113 v->set_goal_view_offset( FG_PI * 0.75 );
115 case 50: // numeric keypad 2
116 v->set_goal_view_offset( FG_PI );
118 case 51: // numeric keypad 3
119 v->set_goal_view_offset( FG_PI * 1.25 );
121 case 52: // numeric keypad 4
122 v->set_goal_view_offset( FG_PI * 0.50 );
124 case 54: // numeric keypad 6
125 v->set_goal_view_offset( FG_PI * 1.50 );
127 case 55: // numeric keypad 7
128 v->set_goal_view_offset( FG_PI * 0.25 );
130 case 56: // numeric keypad 8
131 v->set_goal_view_offset( 0.00 );
133 case 57: // numeric keypad 9
134 v->set_goal_view_offset( FG_PI * 1.75 );
137 // status = current_options.get_hud_status();
138 // current_options.set_hud_status(!status);
139 HUD_brightkey( true );
143 fgHUDInit2(¤t_aircraft);
147 local_update_sky_and_lighting_params();
150 current_options.toggle_panel();
153 t->adjust_warp_delta(-30);
154 local_update_sky_and_lighting_params();
157 #if defined(FX) && !defined(WIN32)
158 global_fullscreen = ( !global_fullscreen );
159 # if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
160 XMesaSetFXmode( global_fullscreen ?
161 XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
166 fov = current_options.get_fov();
168 if ( fov > FG_FOV_MAX ) {
171 current_options.set_fov(fov);
172 v->force_update_fov_math();
175 tmp = w->get_visibility(); // in meters
177 w->set_visibility( tmp );
181 FG_LOG( FG_INPUT, FG_DEBUG, "" );
183 case 50: // numeric keypad 2
184 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
185 fgAPAltitudeAdjust( 100 );
187 controls.move_elevator(-0.05);
190 case 56: // numeric keypad 8
191 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
192 fgAPAltitudeAdjust( -100 );
194 controls.move_elevator(0.05);
197 case 49: // numeric keypad 1
198 controls.move_elevator_trim(-0.001);
200 case 55: // numeric keypad 7
201 controls.move_elevator_trim(0.001);
203 case 52: // numeric keypad 4
204 controls.move_aileron(-0.05);
206 case 54: // numeric keypad 6
207 controls.move_aileron(0.05);
209 case 48: // numeric keypad Ins
210 if( fgAPHeadingEnabled() ) {
211 fgAPHeadingAdjust( -1 );
213 controls.move_rudder(-0.05);
216 case 13: // numeric keypad Enter
217 if( fgAPHeadingEnabled() ) {
218 fgAPHeadingAdjust( 1 );
220 controls.move_rudder(0.05);
223 case 53: // numeric keypad 5
224 controls.set_aileron(0.0);
225 controls.set_elevator(0.0);
226 controls.set_rudder(0.0);
228 case 57: // numeric keypad 9 (Pg Up)
229 if( fgAPAutoThrottleEnabled() ) {
230 fgAPAutoThrottleAdjust( 5 );
232 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
235 case 51: // numeric keypad 3 (Pg Dn)
236 if( fgAPAutoThrottleEnabled() ) {
237 fgAPAutoThrottleAdjust( -5 );
239 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );
245 b_ret = int( controls.get_brake( 0 ) );
246 b_set = double(!b_ret);
247 controls.set_brake( FGControls::ALL_WHEELS, b_set);
250 HUD_brightkey( false );
253 fgHUDInit(¤t_aircraft); // normal HUD
256 t->adjust_warp (+60);
257 local_update_sky_and_lighting_params();
260 t->togglePauseMode();
261 // printf position and attitude information
262 FG_LOG( FG_INPUT, FG_INFO,
263 "Lon = " << f->get_Longitude() * RAD_TO_DEG
264 << " Lat = " << f->get_Latitude() * RAD_TO_DEG
265 << " Altitude = " << f->get_Altitude() * FEET_TO_METER );
266 FG_LOG( FG_INPUT, FG_INFO,
267 "Heading = " << f->get_Psi() * RAD_TO_DEG
268 << " Roll = " << f->get_Phi() * RAD_TO_DEG
269 << " Pitch = " << f->get_Theta() * RAD_TO_DEG );
272 t->adjust_warp_delta (+30);
273 local_update_sky_and_lighting_params();
276 fov = current_options.get_fov();
278 if ( fov < FG_FOV_MIN ) {
281 current_options.set_fov(fov);
282 v->force_update_fov_math();
285 tmp = w->get_visibility(); // in meters
287 w->set_visibility( tmp );
290 // if( fg_DebugOutput ) {
291 // fclose( fg_DebugOutput );
293 FG_LOG( FG_INPUT, FG_ALERT,
294 "Program exiting normally at user request." );
302 // Handle "special" keyboard events
303 void GLUTspecialkey(int k, int x, int y) {
308 FG_LOG( FG_INPUT, FG_DEBUG, "Special key hit = " << k );
309 puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN);
311 if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
312 FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
314 case GLUT_KEY_END: // numeric keypad 1
315 v->set_goal_view_offset( FG_PI * 0.75 );
317 case GLUT_KEY_DOWN: // numeric keypad 2
318 v->set_goal_view_offset( FG_PI );
320 case GLUT_KEY_PAGE_DOWN: // numeric keypad 3
321 v->set_goal_view_offset( FG_PI * 1.25 );
323 case GLUT_KEY_LEFT: // numeric keypad 4
324 v->set_goal_view_offset( FG_PI * 0.50 );
326 case GLUT_KEY_RIGHT: // numeric keypad 6
327 v->set_goal_view_offset( FG_PI * 1.50 );
329 case GLUT_KEY_HOME: // numeric keypad 7
330 v->set_goal_view_offset( FG_PI * 0.25 );
332 case GLUT_KEY_UP: // numeric keypad 8
333 v->set_goal_view_offset( 0.00 );
335 case GLUT_KEY_PAGE_UP: // numeric keypad 9
336 v->set_goal_view_offset( FG_PI * 1.75 );
340 FG_LOG( FG_INPUT, FG_DEBUG, "" );
342 case GLUT_KEY_F8: // F8 toggles fog ... off fastest nicest...
343 current_options.cycle_fog();
345 if ( current_options.get_fog() == fgOPTIONS::FG_FOG_DISABLED ) {
346 FG_LOG( FG_INPUT, FG_INFO, "Fog disabled" );
347 } else if ( current_options.get_fog() ==
348 fgOPTIONS::FG_FOG_FASTEST )
350 FG_LOG( FG_INPUT, FG_INFO,
351 "Fog enabled, hint set to fastest" );
352 } else if ( current_options.get_fog() ==
353 fgOPTIONS::FG_FOG_NICEST )
355 FG_LOG( FG_INPUT, FG_INFO,
356 "Fog enabled, hint set to nicest" );
360 case GLUT_KEY_F9: // F9 toggles textures on and off...
361 if ( material_mgr.loaded() ) {
362 current_options.get_textures() ?
363 current_options.set_textures(false) :
364 current_options.set_textures(true);
365 FG_LOG( FG_INPUT, FG_INFO, "Toggling texture" );
367 FG_LOG( FG_INPUT, FG_INFO,
368 "No textures loaded, cannot toggle" );
371 case GLUT_KEY_F10: // F10 toggles menu on and off...
372 FG_LOG(FG_INPUT, FG_INFO, "Invoking call back function");
375 case GLUT_KEY_F11: // F11 Altitude Dialog.
376 FG_LOG(FG_INPUT, FG_INFO, "Invoking Altitude call back function");
377 // NewAltitude( NULL );
380 case GLUT_KEY_F12: // F12 Heading Dialog...
381 FG_LOG(FG_INPUT, FG_INFO, "Invoking Heading call back function");
382 // NewHeading( NULL );
385 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
386 fgAPAltitudeAdjust( -100 );
388 controls.move_elevator(0.05);
392 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
393 fgAPAltitudeAdjust( 100 );
395 controls.move_elevator(-0.05);
399 controls.move_aileron(-0.05);
402 controls.move_aileron(0.05);
404 case GLUT_KEY_HOME: // numeric keypad 1
405 controls.move_elevator_trim(0.001);
407 case GLUT_KEY_END: // numeric keypad 7
408 controls.move_elevator_trim(-0.001);
410 case GLUT_KEY_INSERT: // numeric keypad Ins
411 if( fgAPHeadingEnabled() ) {
412 fgAPHeadingAdjust( -1 );
414 controls.move_rudder(-0.05);
417 case 13: // numeric keypad Enter
418 if( fgAPHeadingEnabled() ) {
419 fgAPHeadingAdjust( 1 );
421 controls.move_rudder(0.05);
424 case 53: // numeric keypad 5
425 controls.set_aileron(0.0);
426 controls.set_elevator(0.0);
427 controls.set_rudder(0.0);
429 case GLUT_KEY_PAGE_UP: // numeric keypad 9 (Pg Up)
430 if( fgAPAutoThrottleEnabled() ) {
431 fgAPAutoThrottleAdjust( 5 );
433 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
436 case GLUT_KEY_PAGE_DOWN: // numeric keypad 3 (Pg Dn)
437 if( fgAPAutoThrottleEnabled() ) {
438 fgAPAutoThrottleAdjust( -5 );
440 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );