1 // keyboard.cxx -- handle GLUT keyboard events
3 // Written by Curtis Olson, started May 1997.
5 // Copyright (C) 1997 - 1999 Curtis L. Olson - curt@flightgear.org
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 <pu.h> // plib include
44 #include <Debug/logstream.hxx>
45 #include <Aircraft/aircraft.hxx>
46 #include <Astro/solarsystem.hxx>
47 #include <Astro/sky.hxx>
48 #include <Autopilot/autopilot.hxx>
49 #include <Cockpit/hud.hxx>
51 #include <Include/fg_constants.h>
52 #include <Misc/fgpath.hxx>
53 #include <Scenery/tilemgr.hxx>
54 #include <Objects/materialmgr.hxx>
55 #include <Time/fg_time.hxx>
56 #include <Time/light.hxx>
58 #ifndef FG_OLD_WEATHER
59 # include <WeatherCM/FGLocalWeatherDatabase.h>
61 # include <Weather/weather.hxx>
64 #include "keyboard.hxx"
65 #include "options.hxx"
68 extern void NewAltitude( puObject *cb );
69 extern void NewHeading( puObject *cb );
71 // Force an update of the sky and lighting parameters
72 static void local_update_sky_and_lighting_params( void ) {
74 SolarSystem::theSolarSystem->rebuild();
75 cur_light_params.Update();
80 // Handle keyboard events
81 void GLUTkey(unsigned char k, int x, int y) {
86 static bool winding_ccw = true;
89 f = current_aircraft.fdm_state;
90 t = FGTime::cur_time_params;
93 FG_LOG( FG_INPUT, FG_DEBUG, "Key hit = " << k );
94 if ( puKeyboard(k, PU_DOWN) ) {
98 if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
99 FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
101 case 1: // Ctrl-A key
102 fgAPToggleAltitude();
104 case 8: // Ctrl-H key
107 case 18: // Ctrl-R key
109 winding_ccw = !winding_ccw;
111 glFrontFace ( GL_CCW );
113 glFrontFace ( GL_CW );
116 case 19: // Ctrl-S key
117 fgAPToggleAutoThrottle();
119 case 20: // Ctrl-T key
120 fgAPToggleTerrainFollow();
122 case 49: // numeric keypad 1
123 v->set_goal_view_offset( FG_PI * 0.75 );
125 case 50: // numeric keypad 2
126 v->set_goal_view_offset( FG_PI );
128 case 51: // numeric keypad 3
129 v->set_goal_view_offset( FG_PI * 1.25 );
131 case 52: // numeric keypad 4
132 v->set_goal_view_offset( FG_PI * 0.50 );
134 case 54: // numeric keypad 6
135 v->set_goal_view_offset( FG_PI * 1.50 );
137 case 55: // numeric keypad 7
138 v->set_goal_view_offset( FG_PI * 0.25 );
140 case 56: // numeric keypad 8
141 v->set_goal_view_offset( 0.00 );
143 case 57: // numeric keypad 9
144 v->set_goal_view_offset( FG_PI * 1.75 );
147 speed = current_options.get_speed_up();
152 current_options.set_speed_up( speed );
155 // status = current_options.get_hud_status();
156 // current_options.set_hud_status(!status);
157 HUD_brightkey( true );
161 fgHUDInit2(¤t_aircraft);
165 local_update_sky_and_lighting_params();
168 current_options.toggle_panel();
171 t->adjust_warp_delta(-30);
172 local_update_sky_and_lighting_params();
175 #if defined(FX) && !defined(WIN32)
176 global_fullscreen = ( !global_fullscreen );
177 # if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
178 XMesaSetFXmode( global_fullscreen ?
179 XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
184 fov = current_options.get_fov();
186 if ( fov > FG_FOV_MAX ) {
189 current_options.set_fov(fov);
190 v->force_update_fov_math();
193 #ifndef FG_OLD_WEATHER
194 tmp = WeatherDatabase->getWeatherVisibility();
196 WeatherDatabase->setWeatherVisibility( tmp );
198 tmp = current_weather.get_visibility(); // in meters
200 current_weather.set_visibility( tmp );
205 FG_LOG( FG_INPUT, FG_DEBUG, "" );
207 case 50: // numeric keypad 2
208 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
209 fgAPAltitudeAdjust( 100 );
211 controls.move_elevator(-0.05);
214 case 56: // numeric keypad 8
215 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
216 fgAPAltitudeAdjust( -100 );
218 controls.move_elevator(0.05);
221 case 49: // numeric keypad 1
222 controls.move_elevator_trim(-0.001);
224 case 55: // numeric keypad 7
225 controls.move_elevator_trim(0.001);
227 case 52: // numeric keypad 4
228 controls.move_aileron(-0.05);
230 case 54: // numeric keypad 6
231 controls.move_aileron(0.05);
233 case 48: // numeric keypad Ins
234 if( fgAPHeadingEnabled() ) {
235 fgAPHeadingAdjust( -1 );
237 controls.move_rudder(-0.05);
240 case 13: // numeric keypad Enter
241 if( fgAPHeadingEnabled() ) {
242 fgAPHeadingAdjust( 1 );
244 controls.move_rudder(0.05);
247 case 53: // numeric keypad 5
248 controls.set_aileron(0.0);
249 controls.set_elevator(0.0);
250 controls.set_rudder(0.0);
252 case 57: // numeric keypad 9 (Pg Up)
253 if( fgAPAutoThrottleEnabled() ) {
254 fgAPAutoThrottleAdjust( 5 );
256 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
259 case 51: // numeric keypad 3 (Pg Dn)
260 if( fgAPAutoThrottleEnabled() ) {
261 fgAPAutoThrottleAdjust( -5 );
263 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );
267 controls.move_flaps(-0.34);
268 FG_LOG( FG_INPUT, FG_INFO,
269 "Set flaps to " << controls.get_flaps() );
272 controls.move_flaps(0.34);
273 FG_LOG( FG_INPUT, FG_INFO,
274 "Set flaps to " << controls.get_flaps() );
277 speed = current_options.get_speed_up();
279 current_options.set_speed_up( speed );
284 b_ret = int( controls.get_brake( 0 ) );
285 b_set = double(!b_ret);
286 controls.set_brake( FGControls::ALL_WHEELS, b_set);
289 HUD_brightkey( false );
292 fgHUDInit(¤t_aircraft); // normal HUD
295 t->adjust_warp (+60);
296 local_update_sky_and_lighting_params();
299 t->togglePauseMode();
302 FGBucket p( f->get_Longitude() * RAD_TO_DEG,
303 f->get_Latitude() * RAD_TO_DEG );
304 FGPath tile_path( current_options.get_fg_root() );
305 tile_path.append( "Scenery" );
306 tile_path.append( p.gen_base_path() );
307 tile_path.append( p.gen_index_str() );
309 // printf position and attitude information
310 FG_LOG( FG_INPUT, FG_INFO,
311 "Lon = " << f->get_Longitude() * RAD_TO_DEG
312 << " Lat = " << f->get_Latitude() * RAD_TO_DEG
313 << " Altitude = " << f->get_Altitude() * FEET_TO_METER
315 FG_LOG( FG_INPUT, FG_INFO,
316 "Heading = " << f->get_Psi() * RAD_TO_DEG
317 << " Roll = " << f->get_Phi() * RAD_TO_DEG
318 << " Pitch = " << f->get_Theta() * RAD_TO_DEG );
319 FG_LOG( FG_INPUT, FG_INFO, tile_path.c_str());
323 t->adjust_warp_delta (+30);
324 local_update_sky_and_lighting_params();
327 current_options.cycle_view_mode();
330 fov = current_options.get_fov();
332 if ( fov < FG_FOV_MIN ) {
335 current_options.set_fov(fov);
336 v->force_update_fov_math();
339 #ifndef FG_OLD_WEATHER
340 tmp = WeatherDatabase->getWeatherVisibility();
342 WeatherDatabase->setWeatherVisibility( tmp );
344 tmp = current_weather.get_visibility(); // in meters
346 current_weather.set_visibility( tmp );
350 // if( fg_DebugOutput ) {
351 // fclose( fg_DebugOutput );
353 FG_LOG( FG_INPUT, FG_ALERT,
354 "Program exiting normally at user request." );
362 // Handle "special" keyboard events
363 void GLUTspecialkey(int k, int x, int y) {
368 FG_LOG( FG_INPUT, FG_DEBUG, "Special key hit = " << k );
370 if ( puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN) ) {
374 if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
375 FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
377 case GLUT_KEY_END: // numeric keypad 1
378 v->set_goal_view_offset( FG_PI * 0.75 );
380 case GLUT_KEY_DOWN: // numeric keypad 2
381 v->set_goal_view_offset( FG_PI );
383 case GLUT_KEY_PAGE_DOWN: // numeric keypad 3
384 v->set_goal_view_offset( FG_PI * 1.25 );
386 case GLUT_KEY_LEFT: // numeric keypad 4
387 v->set_goal_view_offset( FG_PI * 0.50 );
389 case GLUT_KEY_RIGHT: // numeric keypad 6
390 v->set_goal_view_offset( FG_PI * 1.50 );
392 case GLUT_KEY_HOME: // numeric keypad 7
393 v->set_goal_view_offset( FG_PI * 0.25 );
395 case GLUT_KEY_UP: // numeric keypad 8
396 v->set_goal_view_offset( 0.00 );
398 case GLUT_KEY_PAGE_UP: // numeric keypad 9
399 v->set_goal_view_offset( FG_PI * 1.75 );
403 FG_LOG( FG_INPUT, FG_DEBUG, "" );
405 case GLUT_KEY_F2: // F2 Reload Tile Cache...
408 FG_LOG(FG_INPUT, FG_INFO, "ReIniting TileCache");
409 FGTime *t = FGTime::cur_time_params;
410 if( (toggle_pause = !t->getPause()) )
411 t->togglePauseMode();
413 if( global_tile_mgr.init() ) {
414 // Load the local scenery data
415 global_tile_mgr.update();
417 FG_LOG( FG_GENERAL, FG_ALERT,
418 "Error in Tile Manager initialization!" );
423 t->togglePauseMode();
426 case GLUT_KEY_F3: // F2 Take a screen shot
429 case GLUT_KEY_F6: // F6 toggles Autopilot target location
430 fgAPToggleWayPoint();
432 case GLUT_KEY_F8: // F8 toggles fog ... off fastest nicest...
433 current_options.cycle_fog();
435 if ( current_options.get_fog() == fgOPTIONS::FG_FOG_DISABLED ) {
436 FG_LOG( FG_INPUT, FG_INFO, "Fog disabled" );
437 } else if ( current_options.get_fog() ==
438 fgOPTIONS::FG_FOG_FASTEST )
440 FG_LOG( FG_INPUT, FG_INFO,
441 "Fog enabled, hint set to fastest" );
442 } else if ( current_options.get_fog() ==
443 fgOPTIONS::FG_FOG_NICEST )
445 FG_LOG( FG_INPUT, FG_INFO,
446 "Fog enabled, hint set to nicest" );
450 case GLUT_KEY_F9: // F9 toggles textures on and off...
451 if ( material_mgr.loaded() ) {
452 if (current_options.get_textures()) {
453 current_options.set_textures(false);
454 glDisable(GL_TEXTURE_2D);
455 ssgOverrideTexture(true);
457 current_options.set_textures(true);
458 glEnable(GL_TEXTURE_2D);
459 ssgOverrideTexture(false);
461 FG_LOG( FG_INPUT, FG_INFO, "Toggling texture" );
463 FG_LOG( FG_INPUT, FG_INFO,
464 "No textures loaded, cannot toggle" );
467 case GLUT_KEY_F10: // F10 toggles menu on and off...
468 FG_LOG(FG_INPUT, FG_INFO, "Invoking call back function");
471 case GLUT_KEY_F11: // F11 Altitude Dialog.
472 FG_LOG(FG_INPUT, FG_INFO, "Invoking Altitude call back function");
475 case GLUT_KEY_F12: // F12 Heading Dialog...
476 FG_LOG(FG_INPUT, FG_INFO, "Invoking Heading call back function");
480 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
481 fgAPAltitudeAdjust( -100 );
483 controls.move_elevator(0.05);
487 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
488 fgAPAltitudeAdjust( 100 );
490 controls.move_elevator(-0.05);
494 controls.move_aileron(-0.05);
497 controls.move_aileron(0.05);
499 case GLUT_KEY_HOME: // numeric keypad 1
500 controls.move_elevator_trim(0.001);
502 case GLUT_KEY_END: // numeric keypad 7
503 controls.move_elevator_trim(-0.001);
505 case GLUT_KEY_INSERT: // numeric keypad Ins
506 if( fgAPHeadingEnabled() ) {
507 fgAPHeadingAdjust( -1 );
509 controls.move_rudder(-0.05);
512 case 13: // numeric keypad Enter
513 if( fgAPHeadingEnabled() ) {
514 fgAPHeadingAdjust( 1 );
516 controls.move_rudder(0.05);
519 case 53: // numeric keypad 5
520 controls.set_aileron(0.0);
521 controls.set_elevator(0.0);
522 controls.set_rudder(0.0);
524 case GLUT_KEY_PAGE_UP: // numeric keypad 9 (Pg Up)
525 if( fgAPAutoThrottleEnabled() ) {
526 fgAPAutoThrottleAdjust( 5 );
528 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
531 case GLUT_KEY_PAGE_DOWN: // numeric keypad 3 (Pg Dn)
532 if( fgAPAutoThrottleEnabled() ) {
533 fgAPAutoThrottleAdjust( -5 );
535 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );