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 <Scenery/tilemgr.hxx>
53 #include <Objects/materialmgr.hxx>
54 #include <Time/fg_time.hxx>
55 #include <Time/light.hxx>
58 # include <WeatherCM/FGLocalWeatherDatabase.h>
60 # include <Weather/weather.hxx>
63 #include "keyboard.hxx"
64 #include "options.hxx"
67 extern void NewAltitude( puObject *cb );
68 extern void NewHeading( puObject *cb );
70 // Force an update of the sky and lighting parameters
71 static void local_update_sky_and_lighting_params( void ) {
73 SolarSystem::theSolarSystem->rebuild();
74 cur_light_params.Update();
79 // Handle keyboard events
80 void GLUTkey(unsigned char k, int x, int y) {
85 static bool winding_ccw = true;
88 f = current_aircraft.fdm_state;
89 t = FGTime::cur_time_params;
92 FG_LOG( FG_INPUT, FG_DEBUG, "Key hit = " << k );
93 if ( puKeyboard(k, PU_DOWN) ) {
97 if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
98 FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
100 case 1: // Ctrl-A key
101 fgAPToggleAltitude();
103 case 8: // Ctrl-H key
106 case 18: // Ctrl-R key
108 winding_ccw = !winding_ccw;
110 glFrontFace ( GL_CCW );
112 glFrontFace ( GL_CW );
115 case 19: // Ctrl-S key
116 fgAPToggleAutoThrottle();
118 case 20: // Ctrl-T key
119 fgAPToggleTerrainFollow();
121 case 49: // numeric keypad 1
122 v->set_goal_view_offset( FG_PI * 0.75 );
124 case 50: // numeric keypad 2
125 v->set_goal_view_offset( FG_PI );
127 case 51: // numeric keypad 3
128 v->set_goal_view_offset( FG_PI * 1.25 );
130 case 52: // numeric keypad 4
131 v->set_goal_view_offset( FG_PI * 0.50 );
133 case 54: // numeric keypad 6
134 v->set_goal_view_offset( FG_PI * 1.50 );
136 case 55: // numeric keypad 7
137 v->set_goal_view_offset( FG_PI * 0.25 );
139 case 56: // numeric keypad 8
140 v->set_goal_view_offset( 0.00 );
142 case 57: // numeric keypad 9
143 v->set_goal_view_offset( FG_PI * 1.75 );
146 speed = current_options.get_speed_up();
151 current_options.set_speed_up( speed );
154 // status = current_options.get_hud_status();
155 // current_options.set_hud_status(!status);
156 HUD_brightkey( true );
160 fgHUDInit2(¤t_aircraft);
164 local_update_sky_and_lighting_params();
167 current_options.toggle_panel();
170 t->adjust_warp_delta(-30);
171 local_update_sky_and_lighting_params();
174 #if defined(FX) && !defined(WIN32)
175 global_fullscreen = ( !global_fullscreen );
176 # if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
177 XMesaSetFXmode( global_fullscreen ?
178 XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
183 fov = current_options.get_fov();
185 if ( fov > FG_FOV_MAX ) {
188 current_options.set_fov(fov);
189 v->force_update_fov_math();
192 #ifdef FG_NEW_WEATHER
193 tmp = WeatherDatabase->getWeatherVisibility();
195 WeatherDatabase->setWeatherVisibility( tmp );
197 tmp = current_weather.get_visibility(); // in meters
199 current_weather.set_visibility( tmp );
204 FG_LOG( FG_INPUT, FG_DEBUG, "" );
206 case 50: // numeric keypad 2
207 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
208 fgAPAltitudeAdjust( 100 );
210 controls.move_elevator(-0.05);
213 case 56: // numeric keypad 8
214 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
215 fgAPAltitudeAdjust( -100 );
217 controls.move_elevator(0.05);
220 case 49: // numeric keypad 1
221 controls.move_elevator_trim(-0.001);
223 case 55: // numeric keypad 7
224 controls.move_elevator_trim(0.001);
226 case 52: // numeric keypad 4
227 controls.move_aileron(-0.05);
229 case 54: // numeric keypad 6
230 controls.move_aileron(0.05);
232 case 48: // numeric keypad Ins
233 if( fgAPHeadingEnabled() ) {
234 fgAPHeadingAdjust( -1 );
236 controls.move_rudder(-0.05);
239 case 13: // numeric keypad Enter
240 if( fgAPHeadingEnabled() ) {
241 fgAPHeadingAdjust( 1 );
243 controls.move_rudder(0.05);
246 case 53: // numeric keypad 5
247 controls.set_aileron(0.0);
248 controls.set_elevator(0.0);
249 controls.set_rudder(0.0);
251 case 57: // numeric keypad 9 (Pg Up)
252 if( fgAPAutoThrottleEnabled() ) {
253 fgAPAutoThrottleAdjust( 5 );
255 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
258 case 51: // numeric keypad 3 (Pg Dn)
259 if( fgAPAutoThrottleEnabled() ) {
260 fgAPAutoThrottleAdjust( -5 );
262 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );
266 speed = current_options.get_speed_up();
268 current_options.set_speed_up( speed );
273 b_ret = int( controls.get_brake( 0 ) );
274 b_set = double(!b_ret);
275 controls.set_brake( FGControls::ALL_WHEELS, b_set);
278 HUD_brightkey( false );
281 fgHUDInit(¤t_aircraft); // normal HUD
284 t->adjust_warp (+60);
285 local_update_sky_and_lighting_params();
288 t->togglePauseMode();
289 // printf position and attitude information
290 FG_LOG( FG_INPUT, FG_INFO,
291 "Lon = " << f->get_Longitude() * RAD_TO_DEG
292 << " Lat = " << f->get_Latitude() * RAD_TO_DEG
293 << " Altitude = " << f->get_Altitude() * FEET_TO_METER );
294 FG_LOG( FG_INPUT, FG_INFO,
295 "Heading = " << f->get_Psi() * RAD_TO_DEG
296 << " Roll = " << f->get_Phi() * RAD_TO_DEG
297 << " Pitch = " << f->get_Theta() * RAD_TO_DEG );
300 t->adjust_warp_delta (+30);
301 local_update_sky_and_lighting_params();
304 current_options.cycle_view_mode();
307 fov = current_options.get_fov();
309 if ( fov < FG_FOV_MIN ) {
312 current_options.set_fov(fov);
313 v->force_update_fov_math();
316 #ifdef FG_NEW_WEATHER
317 tmp = WeatherDatabase->getWeatherVisibility();
319 WeatherDatabase->setWeatherVisibility( tmp );
321 tmp = current_weather.get_visibility(); // in meters
323 current_weather.set_visibility( tmp );
327 // if( fg_DebugOutput ) {
328 // fclose( fg_DebugOutput );
330 FG_LOG( FG_INPUT, FG_ALERT,
331 "Program exiting normally at user request." );
339 // Handle "special" keyboard events
340 void GLUTspecialkey(int k, int x, int y) {
345 FG_LOG( FG_INPUT, FG_DEBUG, "Special key hit = " << k );
347 if ( puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN) ) {
351 if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
352 FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
354 case GLUT_KEY_END: // numeric keypad 1
355 v->set_goal_view_offset( FG_PI * 0.75 );
357 case GLUT_KEY_DOWN: // numeric keypad 2
358 v->set_goal_view_offset( FG_PI );
360 case GLUT_KEY_PAGE_DOWN: // numeric keypad 3
361 v->set_goal_view_offset( FG_PI * 1.25 );
363 case GLUT_KEY_LEFT: // numeric keypad 4
364 v->set_goal_view_offset( FG_PI * 0.50 );
366 case GLUT_KEY_RIGHT: // numeric keypad 6
367 v->set_goal_view_offset( FG_PI * 1.50 );
369 case GLUT_KEY_HOME: // numeric keypad 7
370 v->set_goal_view_offset( FG_PI * 0.25 );
372 case GLUT_KEY_UP: // numeric keypad 8
373 v->set_goal_view_offset( 0.00 );
375 case GLUT_KEY_PAGE_UP: // numeric keypad 9
376 v->set_goal_view_offset( FG_PI * 1.75 );
380 FG_LOG( FG_INPUT, FG_DEBUG, "" );
382 case GLUT_KEY_F2: // F2 Reload Tile Cache...
385 FG_LOG(FG_INPUT, FG_INFO, "ReIniting TileCache");
386 FGTime *t = FGTime::cur_time_params;
387 if( (toggle_pause = !t->getPause()) )
388 t->togglePauseMode();
390 if( global_tile_mgr.init() ) {
391 // Load the local scenery data
392 global_tile_mgr.update();
394 FG_LOG( FG_GENERAL, FG_ALERT,
395 "Error in Tile Manager initialization!" );
400 t->togglePauseMode();
403 case GLUT_KEY_F6: // F6 toggles Autopilot target location
404 fgAPToggleWayPoint();
406 case GLUT_KEY_F8: // F8 toggles fog ... off fastest nicest...
407 current_options.cycle_fog();
409 if ( current_options.get_fog() == fgOPTIONS::FG_FOG_DISABLED ) {
410 FG_LOG( FG_INPUT, FG_INFO, "Fog disabled" );
411 } else if ( current_options.get_fog() ==
412 fgOPTIONS::FG_FOG_FASTEST )
414 FG_LOG( FG_INPUT, FG_INFO,
415 "Fog enabled, hint set to fastest" );
416 } else if ( current_options.get_fog() ==
417 fgOPTIONS::FG_FOG_NICEST )
419 FG_LOG( FG_INPUT, FG_INFO,
420 "Fog enabled, hint set to nicest" );
424 case GLUT_KEY_F9: // F9 toggles textures on and off...
425 if ( material_mgr.loaded() ) {
426 if (current_options.get_textures()) {
427 current_options.set_textures(false);
428 glDisable(GL_TEXTURE_2D);
429 ssgOverrideTexture(true);
431 current_options.set_textures(true);
432 glEnable(GL_TEXTURE_2D);
433 ssgOverrideTexture(false);
435 FG_LOG( FG_INPUT, FG_INFO, "Toggling texture" );
437 FG_LOG( FG_INPUT, FG_INFO,
438 "No textures loaded, cannot toggle" );
441 case GLUT_KEY_F10: // F10 toggles menu on and off...
442 FG_LOG(FG_INPUT, FG_INFO, "Invoking call back function");
445 case GLUT_KEY_F11: // F11 Altitude Dialog.
446 FG_LOG(FG_INPUT, FG_INFO, "Invoking Altitude call back function");
449 case GLUT_KEY_F12: // F12 Heading Dialog...
450 FG_LOG(FG_INPUT, FG_INFO, "Invoking Heading call back function");
454 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
455 fgAPAltitudeAdjust( -100 );
457 controls.move_elevator(0.05);
461 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
462 fgAPAltitudeAdjust( 100 );
464 controls.move_elevator(-0.05);
468 controls.move_aileron(-0.05);
471 controls.move_aileron(0.05);
473 case GLUT_KEY_HOME: // numeric keypad 1
474 controls.move_elevator_trim(0.001);
476 case GLUT_KEY_END: // numeric keypad 7
477 controls.move_elevator_trim(-0.001);
479 case GLUT_KEY_INSERT: // numeric keypad Ins
480 if( fgAPHeadingEnabled() ) {
481 fgAPHeadingAdjust( -1 );
483 controls.move_rudder(-0.05);
486 case 13: // numeric keypad Enter
487 if( fgAPHeadingEnabled() ) {
488 fgAPHeadingAdjust( 1 );
490 controls.move_rudder(0.05);
493 case 53: // numeric keypad 5
494 controls.set_aileron(0.0);
495 controls.set_elevator(0.0);
496 controls.set_rudder(0.0);
498 case GLUT_KEY_PAGE_UP: // numeric keypad 9 (Pg Up)
499 if( fgAPAutoThrottleEnabled() ) {
500 fgAPAutoThrottleAdjust( 5 );
502 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
505 case GLUT_KEY_PAGE_DOWN: // numeric keypad 3 (Pg Dn)
506 if( fgAPAutoThrottleEnabled() ) {
507 fgAPAutoThrottleAdjust( -5 );
509 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );