diff --git a/Cockpit/hud_guag.cxx b/Cockpit/hud_guag.cxx index 9665f2ca5..caee47951 100644 --- a/Cockpit/hud_guag.cxx +++ b/Cockpit/hud_guag.cxx @@ -77,7 +77,7 @@ void guage_instr :: draw (void) int marker_xs, marker_xe; int marker_ys, marker_ye; int text_x, text_y; - register i; + int i; char TextScale[80]; bool condition; int disp_val; diff --git a/Joystick/Makefile.am b/Joystick/Makefile.am index 6e2d09c7b..30eebce85 100644 --- a/Joystick/Makefile.am +++ b/Joystick/Makefile.am @@ -1,3 +1,9 @@ +if ENABLE_LINUX_JOYSTICK +DEFS += -DENABLE_LINUX_JOYSTICK +else +DEFS += -DENABLE_GLUT_JOYSTICK +endif + EXTRA_DIST = js.cxx noinst_LIBRARIES = libJoystick.a diff --git a/Joystick/joystick.cxx b/Joystick/joystick.cxx index a95f971cf..c0068f561 100644 --- a/Joystick/joystick.cxx +++ b/Joystick/joystick.cxx @@ -22,19 +22,91 @@ // (Log is kept at end of this file) +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifdef HAVE_WINDOWS_H +# include +#endif + #include #include -#include + +#if defined( ENABLE_LINUX_JOYSTICK ) +# include +#elif defined( ENABLE_GLUT_JOYSTICK ) +# include +# include +#endif + #include "joystick.hxx" -// joystick classes -static jsJoystick *js0; -static jsJoystick *js1; +#if defined( ENABLE_LINUX_JOYSTICK ) -// these will hold the values of the axes -static float *js_ax0, *js_ax1; + // joystick classes + static jsJoystick *js0; + static jsJoystick *js1; + + // these will hold the values of the axes + static float *js_ax0, *js_ax1; + +#elif defined( ENABLE_GLUT_JOYSTICK ) + + // Joystick support using glut -- William Riley -- riley@technologist.com + + // Joystick fixed values for calibration and scaling + static int joy_x_min=1000, /* joy_x_ctr=0, */ joy_x_max=-1000; + static int joy_y_min=1000, /* joy_y_ctr=0, */ joy_y_max=-1000; + static int joy_z_min=1000, /* joy_z_ctr=0, */ joy_z_max=-1000; + static int joy_x_dead_min=100, joy_x_dead_max=-100; + static int joy_y_dead_min=100, joy_y_dead_max=-100; + static int joy_z_dead_min=100, joy_z_dead_max=-100; + +#else +# error port me: no joystick support +#endif + + + +#if defined( ENABLE_GLUT_JOYSTICK ) + +// Function called by glutJoystickFunc(), adjusts read values and +// passes them to the necessary aircraft control functions +void joystick(unsigned int buttonMask, int js_x, int js_y, int js_z) +{ + double joy_x, joy_y, joy_z; + // adjust the values to fgfs's scale and allow a 'dead zone' to + // reduce jitter code adapted from joystick.c by Michele + // F. America - nomimarketing@mail.telepac.pt + if( js_x >= joy_x_dead_min && js_x <= joy_x_dead_max ) { + joy_x = 0.0; + } else { + joy_x = (double)js_x/(double)(joy_x_max-joy_x_min); + } + if( js_y >= joy_y_dead_min && js_y <= joy_y_dead_max ) { + joy_y = 0.0; + } else { + joy_y = (double)js_y/(double)(joy_y_max-joy_y_min); + } + if( js_z >= joy_z_dead_min && js_z <= joy_z_dead_max ) { + joy_z = 0.0; + } else { + joy_z = (double)js_z/(double)(joy_z_max-joy_z_min); + } + // Scale the values up for full range of motion + joy_x *= 2.0; + joy_y *= 2.0; + joy_z = (((joy_z*2.0)+1.0)/2); + // Pass the values to the control routines + controls.set_elevator( joy_y ); + controls.set_aileron( -joy_x ); + controls.set_throttle( fgCONTROLS::FG_ALL_ENGINES, joy_z ); +} + +#endif // ENABLE_GLUT_JOYSTICK // Initialize the joystick(s) @@ -42,6 +114,8 @@ int fgJoystickInit( void ) { fgPrintf( FG_INPUT, FG_INFO, "Initializing joystick\n"); +#if defined( ENABLE_LINUX_JOYSTICK ) + js0 = new jsJoystick ( 0 ); js1 = new jsJoystick ( 1 ); @@ -80,10 +154,20 @@ int fgJoystickInit( void ) { return 0; } +#elif defined( ENABLE_GLUT_JOYSTICK ) + + glutJoystickFunc(joystick, 100); + +#else +# error port me: no joystick support +#endif + return 1; } +#if defined( ENABLE_LINUX_JOYSTICK ) + // update the control parameters based on joystick intput int fgJoystickRead( void ) { int b; @@ -103,8 +187,13 @@ int fgJoystickRead( void ) { return 1; } +#endif // ENABLE_LINUX_JOYSTICK + // $Log$ +// Revision 1.4 1998/10/27 02:14:32 curt +// Changes to support GLUT joystick routines as fall back. +// // Revision 1.3 1998/10/25 14:08:44 curt // Turned "struct fgCONTROLS" into a class, with inlined accessor functions. // diff --git a/Joystick/joystick.hxx b/Joystick/joystick.hxx index 6a47e0d09..23bebedc6 100644 --- a/Joystick/joystick.hxx +++ b/Joystick/joystick.hxx @@ -34,14 +34,19 @@ // Initialize the joystick(s) int fgJoystickInit( void ); -// update the control parameters based on joystick intput -int fgJoystickRead( void ); +#if defined( ENABLE_LINUX_JOYSTICK ) + // update the control parameters based on joystick intput + int fgJoystickRead( void ); +#endif // ENABLE_LINUX_JOYSTICK #endif // _JOYSTICK_HXX // $Log$ +// Revision 1.3 1998/10/27 02:14:33 curt +// Changes to support GLUT joystick routines as fall back. +// // Revision 1.2 1998/10/25 10:56:27 curt // Completely rewritten to use Steve Baker's joystick interface class. // diff --git a/Main/GLUTmain.cxx b/Main/GLUTmain.cxx index d7f420e59..c7e17ccee 100644 --- a/Main/GLUTmain.cxx +++ b/Main/GLUTmain.cxx @@ -64,11 +64,7 @@ #include #include #include - -#ifdef ENABLE_JOYSTICK_SUPPORT -# include -#endif - +#include #include #include #include @@ -511,9 +507,13 @@ static void fgMainLoop( void ) { // update "time" fgTimeUpdate(f, t); -#ifdef ENABLE_JOYSTICK_SUPPORT +#if defined( ENABLE_LINUX_JOYSTICK ) // Read joystick and update control settings fgJoystickRead(); +#elif defined( ENABLE_GLUT_JOYSTICK ) + // Glut joystick support works by feeding a joystick handler + // function to glut. This is taken care of once in the joystick + // init routine and we don't have to worry about it again. #endif // Get elapsed time for this past frame @@ -892,6 +892,9 @@ int main( int argc, char **argv ) { // $Log$ +// Revision 1.62 1998/10/27 02:14:35 curt +// Changes to support GLUT joystick routines as fall back. +// // Revision 1.61 1998/10/25 14:08:47 curt // Turned "struct fgCONTROLS" into a class, with inlined accessor functions. // diff --git a/Main/Makefile.am b/Main/Makefile.am index c3d91ab59..5dd3c634a 100644 --- a/Main/Makefile.am +++ b/Main/Makefile.am @@ -13,11 +13,10 @@ if ENABLE_WIN32_AUDIO LIBS += -lwinmm endif -if ENABLE_JOYSTICK_SUPPORT -DEFS += -DENABLE_JOYSTICK_SUPPORT -JOYSTICK_LIBS = $(top_builddir)/Simulator/Joystick/libJoystick.a +if ENABLE_LINUX_JOYSTICK +DEFS += -DENABLE_LINUX_JOYSTICK else -JOYSTICK_LIBS = +DEFS += -DENABLE_GLUT_JOYSTICK endif if ENABLE_XMESA_FX @@ -53,7 +52,8 @@ fgfs_LDADD = \ $(top_builddir)/Simulator/Objects/libObjects.a \ $(top_builddir)/Simulator/Time/libTime.a \ $(top_builddir)/Simulator/Weather/libWeather.a \ - $(JOYSTICK_LIBS) $(AUDIO_LIBS) \ + $(top_builddir)/Simulator/Joystick/libJoystick.a \ + $(AUDIO_LIBS) \ $(top_builddir)/Lib/Math/libMath.a \ $(top_builddir)/Lib/Bucket/libBucket.a \ $(top_builddir)/Lib/Debug/libDebug.a \ diff --git a/Main/fg_init.cxx b/Main/fg_init.cxx index 2f26d080f..8b91b21d1 100644 --- a/Main/fg_init.cxx +++ b/Main/fg_init.cxx @@ -50,11 +50,7 @@ #include #include #include - -#ifdef ENABLE_JOYSTICK_SUPPORT -# include -#endif - +#include #include #include #include @@ -349,14 +345,12 @@ int fgInitSubsystems( void ) FG_Altitude * FEET_TO_METER); // end of thing that I just stuck in that I should probably move -#ifdef ENABLE_JOYSTICK_SUPPORT // Joystick support if ( fgJoystickInit() ) { // Joystick initialized ok. } else { fgPrintf( FG_GENERAL, FG_ALERT, "Error in Joystick initialization!\n" ); } -#endif // Autopilot init added here, by Jeff Goeke-Smith fgAPInit(¤t_aircraft); @@ -368,6 +362,9 @@ int fgInitSubsystems( void ) // $Log$ +// Revision 1.46 1998/10/27 02:14:38 curt +// Changes to support GLUT joystick routines as fall back. +// // Revision 1.45 1998/10/25 10:57:21 curt // Changes to use the new joystick library if it is available. // diff --git a/Simulator/Makefile.am b/Simulator/Makefile.am index fad76f883..ed862d745 100644 --- a/Simulator/Makefile.am +++ b/Simulator/Makefile.am @@ -1,9 +1,3 @@ -if ENABLE_JOYSTICK_SUPPORT -JOYSTICK_DIRS = Joystick -else -JOYSTICK_DIRS = -endif - SUBDIRS = \ Aircraft \ Airports \ @@ -13,7 +7,7 @@ SUBDIRS = \ Controls \ Flight \ GUI \ - $(JOYSTICK_DIRS) \ + Joystick \ Objects \ Scenery \ Time \