+#elif defined( ENABLE_GLUT_JOYSTICK )
+
+// Do we want these user settable ??
+static float joy_scale = 1./1000;
+
+// play with following to get your desired sensitivity
+static int x_dead_zone = 50;
+static int y_dead_zone = 2*x_dead_zone;
+
+// Joystick support using glut -- William Riley -- riley@technologist.com
+
+// Joystick fixed values for calibration and scaling
+static float joy_x_max = joy_scale;
+static float joy_y_max = joy_scale;
+
+static int joy_z_min = 1000, /* joy_z_ctr=0, */ joy_z_max = -1000;
+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)
+{
+ float 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 > -x_dead_zone && js_x < x_dead_zone) {
+ joy_x = 0.0;
+ } else {
+ joy_x = js_x * joy_scale;
+ }
+
+ if( js_y > -y_dead_zone && js_y < y_dead_zone) {
+ joy_y = 0.0;
+ } else {
+ joy_y = js_y * joy_scale;
+ }
+
+ if( js_z >= joy_z_dead_min && js_z <= joy_z_dead_max ) {
+ joy_z = 0.0;
+ }
+ joy_z = (float)js_z / (float)(joy_z_max - joy_z_min);
+ 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::ALL_ENGINES, joy_z );
+}
+
+#endif // ENABLE_GLUT_JOYSTICK
+