]> git.mxchange.org Git - flightgear.git/commitdiff
Changes to support GLUT joystick routines as fall back.
authorcurt <curt>
Tue, 27 Oct 1998 02:14:21 +0000 (02:14 +0000)
committercurt <curt>
Tue, 27 Oct 1998 02:14:21 +0000 (02:14 +0000)
Cockpit/hud_guag.cxx
Joystick/Makefile.am
Joystick/joystick.cxx
Joystick/joystick.hxx
Main/GLUTmain.cxx
Main/Makefile.am
Main/fg_init.cxx
Simulator/Makefile.am

index 9665f2ca518b3e1a00d85352400bba24e98f63a9..caee4795132657845091b4995d15394af670a675 100644 (file)
@@ -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;
index 6e2d09c7b3f565e94548a0d50c2fb090842b1f09..30eebce8599fbb6d407df87151350d308a8db838 100644 (file)
@@ -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
index a95f971cf77288fe3c2c5ccb10ca50f171f44865..c0068f5616388da3f6b1c812df3534b9098ba920 100644 (file)
 // (Log is kept at end of this file)
 
 
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#ifdef HAVE_WINDOWS_H
+#  include <windows.h>                     
+#endif
+
 #include <Aircraft/aircraft.hxx>
 #include <Debug/fg_debug.h>
-#include <Joystick/js.hxx>
+
+#if defined( ENABLE_LINUX_JOYSTICK )
+#  include <Joystick/js.hxx>
+#elif defined( ENABLE_GLUT_JOYSTICK )
+#  include <GL/glut.h>
+#  include <XGL/xgl.h>
+#endif
+
 
 #include "joystick.hxx"
 
 
-// joystick classes
-static jsJoystick *js0;
-static jsJoystick *js1;
+#if defined( ENABLE_LINUX_JOYSTICK )
+
+    // 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 )
 
-// these will hold the values of the axes
-static float *js_ax0, *js_ax1;
+    // 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.
 //
index 6a47e0d0935df9a884e3e2ddecdffa3bb09ad21a..23bebedc634f58746564b3f427d6fb9f39c81894 100644 (file)
 // 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.
 //
index d7f420e59291247604f72d9797af050f081a5c08..c7e17ccee8b48fb689a8009b4ddfdce2fda3ef48 100644 (file)
 #include <Cockpit/cockpit.hxx>
 #include <Debug/fg_debug.h>
 #include <GUI/gui.h>
-
-#ifdef ENABLE_JOYSTICK_SUPPORT
-#  include <Joystick/joystick.hxx>
-#endif
-
+#include <Joystick/joystick.hxx>
 #include <Math/fg_geodesy.hxx>
 #include <Math/mat3.h>
 #include <Math/polar3d.hxx>
@@ -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.
 //
index c3d91ab59bd73bef59ef298fed096c9c5ec94a66..5dd3c634a64b359f01e07123b3ab80b8d0d90026 100644 (file)
@@ -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 \
index 2f26d080f655830a16191b81e4a98966a0c82323..8b91b21d13013f03a8bf3b040bccc49fb8874b3d 100644 (file)
 #include <Autopilot/autopilot.hxx>
 #include <Cockpit/cockpit.hxx>
 #include <Debug/fg_debug.h>
-
-#ifdef ENABLE_JOYSTICK_SUPPORT
-#  include <Joystick/joystick.hxx>
-#endif
-
+#include <Joystick/joystick.hxx>
 #include <Math/fg_geodesy.hxx>
 #include <Math/fg_random.h>
 #include <Math/point3d.hxx>
@@ -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(&current_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.
 //
index fad76f883b7307ee3b10b41caa2c0f7ee40ee9ed..ed862d74577dc48ce214228e34b5dc8065153f2d 100644 (file)
@@ -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 \