Changes to support GLUT joystick routines as fall back.
This commit is contained in:
parent
bab1b9c2e5
commit
80b8037230
8 changed files with 128 additions and 34 deletions
|
@ -77,7 +77,7 @@ void guage_instr :: draw (void)
|
||||||
int marker_xs, marker_xe;
|
int marker_xs, marker_xe;
|
||||||
int marker_ys, marker_ye;
|
int marker_ys, marker_ye;
|
||||||
int text_x, text_y;
|
int text_x, text_y;
|
||||||
register i;
|
int i;
|
||||||
char TextScale[80];
|
char TextScale[80];
|
||||||
bool condition;
|
bool condition;
|
||||||
int disp_val;
|
int disp_val;
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
if ENABLE_LINUX_JOYSTICK
|
||||||
|
DEFS += -DENABLE_LINUX_JOYSTICK
|
||||||
|
else
|
||||||
|
DEFS += -DENABLE_GLUT_JOYSTICK
|
||||||
|
endif
|
||||||
|
|
||||||
EXTRA_DIST = js.cxx
|
EXTRA_DIST = js.cxx
|
||||||
|
|
||||||
noinst_LIBRARIES = libJoystick.a
|
noinst_LIBRARIES = libJoystick.a
|
||||||
|
|
|
@ -22,19 +22,91 @@
|
||||||
// (Log is kept at end of this 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 <Aircraft/aircraft.hxx>
|
||||||
#include <Debug/fg_debug.h>
|
#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"
|
#include "joystick.hxx"
|
||||||
|
|
||||||
|
|
||||||
// joystick classes
|
#if defined( ENABLE_LINUX_JOYSTICK )
|
||||||
static jsJoystick *js0;
|
|
||||||
static jsJoystick *js1;
|
|
||||||
|
|
||||||
// these will hold the values of the axes
|
// joystick classes
|
||||||
static float *js_ax0, *js_ax1;
|
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)
|
// Initialize the joystick(s)
|
||||||
|
@ -42,6 +114,8 @@ int fgJoystickInit( void ) {
|
||||||
|
|
||||||
fgPrintf( FG_INPUT, FG_INFO, "Initializing joystick\n");
|
fgPrintf( FG_INPUT, FG_INFO, "Initializing joystick\n");
|
||||||
|
|
||||||
|
#if defined( ENABLE_LINUX_JOYSTICK )
|
||||||
|
|
||||||
js0 = new jsJoystick ( 0 );
|
js0 = new jsJoystick ( 0 );
|
||||||
js1 = new jsJoystick ( 1 );
|
js1 = new jsJoystick ( 1 );
|
||||||
|
|
||||||
|
@ -80,10 +154,20 @@ int fgJoystickInit( void ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#elif defined( ENABLE_GLUT_JOYSTICK )
|
||||||
|
|
||||||
|
glutJoystickFunc(joystick, 100);
|
||||||
|
|
||||||
|
#else
|
||||||
|
# error port me: no joystick support
|
||||||
|
#endif
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if defined( ENABLE_LINUX_JOYSTICK )
|
||||||
|
|
||||||
// update the control parameters based on joystick intput
|
// update the control parameters based on joystick intput
|
||||||
int fgJoystickRead( void ) {
|
int fgJoystickRead( void ) {
|
||||||
int b;
|
int b;
|
||||||
|
@ -103,8 +187,13 @@ int fgJoystickRead( void ) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // ENABLE_LINUX_JOYSTICK
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $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
|
// Revision 1.3 1998/10/25 14:08:44 curt
|
||||||
// Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
|
// Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
|
||||||
//
|
//
|
||||||
|
|
|
@ -34,14 +34,19 @@
|
||||||
// Initialize the joystick(s)
|
// Initialize the joystick(s)
|
||||||
int fgJoystickInit( void );
|
int fgJoystickInit( void );
|
||||||
|
|
||||||
// update the control parameters based on joystick intput
|
#if defined( ENABLE_LINUX_JOYSTICK )
|
||||||
int fgJoystickRead( void );
|
// update the control parameters based on joystick intput
|
||||||
|
int fgJoystickRead( void );
|
||||||
|
#endif // ENABLE_LINUX_JOYSTICK
|
||||||
|
|
||||||
|
|
||||||
#endif // _JOYSTICK_HXX
|
#endif // _JOYSTICK_HXX
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $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
|
// Revision 1.2 1998/10/25 10:56:27 curt
|
||||||
// Completely rewritten to use Steve Baker's joystick interface class.
|
// Completely rewritten to use Steve Baker's joystick interface class.
|
||||||
//
|
//
|
||||||
|
|
|
@ -64,11 +64,7 @@
|
||||||
#include <Cockpit/cockpit.hxx>
|
#include <Cockpit/cockpit.hxx>
|
||||||
#include <Debug/fg_debug.h>
|
#include <Debug/fg_debug.h>
|
||||||
#include <GUI/gui.h>
|
#include <GUI/gui.h>
|
||||||
|
#include <Joystick/joystick.hxx>
|
||||||
#ifdef ENABLE_JOYSTICK_SUPPORT
|
|
||||||
# include <Joystick/joystick.hxx>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <Math/fg_geodesy.hxx>
|
#include <Math/fg_geodesy.hxx>
|
||||||
#include <Math/mat3.h>
|
#include <Math/mat3.h>
|
||||||
#include <Math/polar3d.hxx>
|
#include <Math/polar3d.hxx>
|
||||||
|
@ -511,9 +507,13 @@ static void fgMainLoop( void ) {
|
||||||
// update "time"
|
// update "time"
|
||||||
fgTimeUpdate(f, t);
|
fgTimeUpdate(f, t);
|
||||||
|
|
||||||
#ifdef ENABLE_JOYSTICK_SUPPORT
|
#if defined( ENABLE_LINUX_JOYSTICK )
|
||||||
// Read joystick and update control settings
|
// Read joystick and update control settings
|
||||||
fgJoystickRead();
|
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
|
#endif
|
||||||
|
|
||||||
// Get elapsed time for this past frame
|
// Get elapsed time for this past frame
|
||||||
|
@ -892,6 +892,9 @@ int main( int argc, char **argv ) {
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $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
|
// Revision 1.61 1998/10/25 14:08:47 curt
|
||||||
// Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
|
// Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
|
||||||
//
|
//
|
||||||
|
|
|
@ -13,11 +13,10 @@ if ENABLE_WIN32_AUDIO
|
||||||
LIBS += -lwinmm
|
LIBS += -lwinmm
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ENABLE_JOYSTICK_SUPPORT
|
if ENABLE_LINUX_JOYSTICK
|
||||||
DEFS += -DENABLE_JOYSTICK_SUPPORT
|
DEFS += -DENABLE_LINUX_JOYSTICK
|
||||||
JOYSTICK_LIBS = $(top_builddir)/Simulator/Joystick/libJoystick.a
|
|
||||||
else
|
else
|
||||||
JOYSTICK_LIBS =
|
DEFS += -DENABLE_GLUT_JOYSTICK
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ENABLE_XMESA_FX
|
if ENABLE_XMESA_FX
|
||||||
|
@ -53,7 +52,8 @@ fgfs_LDADD = \
|
||||||
$(top_builddir)/Simulator/Objects/libObjects.a \
|
$(top_builddir)/Simulator/Objects/libObjects.a \
|
||||||
$(top_builddir)/Simulator/Time/libTime.a \
|
$(top_builddir)/Simulator/Time/libTime.a \
|
||||||
$(top_builddir)/Simulator/Weather/libWeather.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/Math/libMath.a \
|
||||||
$(top_builddir)/Lib/Bucket/libBucket.a \
|
$(top_builddir)/Lib/Bucket/libBucket.a \
|
||||||
$(top_builddir)/Lib/Debug/libDebug.a \
|
$(top_builddir)/Lib/Debug/libDebug.a \
|
||||||
|
|
|
@ -50,11 +50,7 @@
|
||||||
#include <Autopilot/autopilot.hxx>
|
#include <Autopilot/autopilot.hxx>
|
||||||
#include <Cockpit/cockpit.hxx>
|
#include <Cockpit/cockpit.hxx>
|
||||||
#include <Debug/fg_debug.h>
|
#include <Debug/fg_debug.h>
|
||||||
|
#include <Joystick/joystick.hxx>
|
||||||
#ifdef ENABLE_JOYSTICK_SUPPORT
|
|
||||||
# include <Joystick/joystick.hxx>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <Math/fg_geodesy.hxx>
|
#include <Math/fg_geodesy.hxx>
|
||||||
#include <Math/fg_random.h>
|
#include <Math/fg_random.h>
|
||||||
#include <Math/point3d.hxx>
|
#include <Math/point3d.hxx>
|
||||||
|
@ -349,14 +345,12 @@ int fgInitSubsystems( void )
|
||||||
FG_Altitude * FEET_TO_METER);
|
FG_Altitude * FEET_TO_METER);
|
||||||
// end of thing that I just stuck in that I should probably move
|
// end of thing that I just stuck in that I should probably move
|
||||||
|
|
||||||
#ifdef ENABLE_JOYSTICK_SUPPORT
|
|
||||||
// Joystick support
|
// Joystick support
|
||||||
if ( fgJoystickInit() ) {
|
if ( fgJoystickInit() ) {
|
||||||
// Joystick initialized ok.
|
// Joystick initialized ok.
|
||||||
} else {
|
} else {
|
||||||
fgPrintf( FG_GENERAL, FG_ALERT, "Error in Joystick initialization!\n" );
|
fgPrintf( FG_GENERAL, FG_ALERT, "Error in Joystick initialization!\n" );
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// Autopilot init added here, by Jeff Goeke-Smith
|
// Autopilot init added here, by Jeff Goeke-Smith
|
||||||
fgAPInit(¤t_aircraft);
|
fgAPInit(¤t_aircraft);
|
||||||
|
@ -368,6 +362,9 @@ int fgInitSubsystems( void )
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $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
|
// Revision 1.45 1998/10/25 10:57:21 curt
|
||||||
// Changes to use the new joystick library if it is available.
|
// Changes to use the new joystick library if it is available.
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,9 +1,3 @@
|
||||||
if ENABLE_JOYSTICK_SUPPORT
|
|
||||||
JOYSTICK_DIRS = Joystick
|
|
||||||
else
|
|
||||||
JOYSTICK_DIRS =
|
|
||||||
endif
|
|
||||||
|
|
||||||
SUBDIRS = \
|
SUBDIRS = \
|
||||||
Aircraft \
|
Aircraft \
|
||||||
Airports \
|
Airports \
|
||||||
|
@ -13,7 +7,7 @@ SUBDIRS = \
|
||||||
Controls \
|
Controls \
|
||||||
Flight \
|
Flight \
|
||||||
GUI \
|
GUI \
|
||||||
$(JOYSTICK_DIRS) \
|
Joystick \
|
||||||
Objects \
|
Objects \
|
||||||
Scenery \
|
Scenery \
|
||||||
Time \
|
Time \
|
||||||
|
|
Loading…
Reference in a new issue