Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
in_joystick.cpp File Reference
#include <list>
#include <lin_time.h>
#include "vegastrike.h"
#include "vs_globals.h"
#include "in_handler.h"
#include "in_joystick.h"
#include "config_xml.h"
#include "in_mouse.h"
#include "gldrv/gl_include.h"
#include "options.h"

Go to the source code of this file.

Classes

struct  mouseData
 

Macros

#define NO_SDL_JOYSTICK
 

Functions

void modifyDeadZone (JoyStick *j)
 
void modifyExponent (JoyStick *j)
 
void JoyStickToggleDisable ()
 
void JoyStickToggleKey (const KBData &key, KBSTATE a)
 
void myGlutJoystickCallback (unsigned int buttonmask, int x, int y, int z)
 
int JoystickPollingRate ()
 
void InitJoystick ()
 
void DeInitJoystick ()
 
void GetMouseXY (int &mousex, int &mousey)
 

Variables

vs_options game_options
 
static int maxx = 1
 
static int minx = -1
 
static int maxy = 1
 
static int miny = -1
 
static int maxz = 1
 
static int minz = -1
 
JoyStickjoystick [MAX_JOYSTICKS]
 
int num_joysticks = 0
 
static bool JoyStickToggle = true
 

Macro Definition Documentation

#define NO_SDL_JOYSTICK

Definition at line 38 of file in_joystick.cpp.

Function Documentation

void DeInitJoystick ( )

Definition at line 172 of file in_joystick.cpp.

References i, and MAX_JOYSTICKS.

Referenced by DeInitInput().

173 {
174  for (int i = 0; i < MAX_JOYSTICKS; i++)
175  delete joystick[i];
176 }
void GetMouseXY ( int mousex,
int mousey 
)

Definition at line 43 of file in_mouse.cpp.

References mousex, and mousey.

44 {
45  mx = mousex;
46  my = mousey;
47 }
void InitJoystick ( )

Definition at line 129 of file in_joystick.cpp.

References vs_options::force_use_of_joystick, h, i, j, JoystickPollingRate(), MAX_DIGITAL_HATSWITCHES, MAX_DIGITAL_VALUES, MAX_HATSWITCHES, MAX_JOYSTICKS, MAX_VALUES, myGlutJoystickCallback(), num_joysticks, NUMJBUTTONS, UnbindDigitalHatswitchKey(), UnbindHatswitchKey(), UnbindJoyKey(), and v.

Referenced by InitInput().

130 {
131  int i;
132  for (i = 0; i < NUMJBUTTONS; i++)
133  for (int j = 0; j < MAX_JOYSTICKS; j++)
134  UnbindJoyKey( j, i );
135  for (int h = 0; h < MAX_HATSWITCHES; h++)
136  for (int v = 0; v < MAX_VALUES; v++)
137  UnbindHatswitchKey( h, v );
138  for (int j = 0; j < MAX_JOYSTICKS; j++)
139  for (int h = 0; h < MAX_DIGITAL_HATSWITCHES; h++)
140  for (int v = 0; v < MAX_DIGITAL_VALUES; v++)
141  UnbindDigitalHatswitchKey( j, h, v );
142 #ifndef NO_SDL_JOYSTICK
143 #ifdef HAVE_SDL
144  num_joysticks = SDL_NumJoysticks();
145  printf( "%i joysticks were found.\n\n", num_joysticks );
146  printf( "The names of the joysticks are:\n" );
147 #else
148  //use glut
149  if (glutDeviceGet( GLUT_HAS_JOYSTICK ) || game_options.force_use_of_joystick) {
150  printf( "setting joystick functionality:: joystick online" );
151  glutJoystickFunc( myGlutJoystickCallback, JoystickPollingRate() );
152  num_joysticks = 1;
153  }
154 #endif
155 #endif
156  for (i = 0; i < MAX_JOYSTICKS; i++) {
157 #ifndef NO_SDL_JOYSTICK
158 #ifdef HAVE_SDL
159  if (i < num_joysticks)
160  printf( " %s\n", SDL_JoystickName( i ) );
161 #else
162  if (i < num_joysticks)
163  //SDL_EventState (SDL_JOYBUTTONDOWN,SDL_ENABLE);
164  //SDL_EventState (SDL_JOYBUTTONUP,SDL_ENABLE);
165  printf( "Glut detects %d joystick", i+1 );
166 #endif
167 #endif
168  joystick[i] = new JoyStick( i ); //SDL_Init is done in main.cpp
169  }
170 }
int JoystickPollingRate ( )

Definition at line 125 of file in_joystick.cpp.

References vs_options::polling_rate.

Referenced by JoyStick::GetJoyStick(), and InitJoystick().

126 {
127  return game_options.polling_rate;
128 }
void JoyStickToggleDisable ( )

Definition at line 80 of file in_joystick.cpp.

References JoyStickToggle.

Referenced by FlyByKeyboard::DownKey(), FlyByKeyboard::LeftKey(), FlyByKeyboard::RightKey(), and FlyByKeyboard::UpKey().

81 {
82  JoyStickToggle = false;
83 }
void JoyStickToggleKey ( const KBData key,
KBSTATE  a 
)

Definition at line 84 of file in_joystick.cpp.

References JoyStickToggle, and PRESS.

Referenced by initGlobalCommandMap().

85 {
86  if (a == PRESS)
88 }
void modifyDeadZone ( JoyStick j)

Definition at line 56 of file in_joystick.cpp.

References a, JoyStick::deadzone, JoyStick::joy_axis, and JoyStick::nr_of_axes.

Referenced by JoyStick::GetJoyStick(), and myGlutJoystickCallback().

57 {
58  for (int a = 0; a < j->nr_of_axes; a++) {
59  if (fabs( j->joy_axis[a] ) <= j->deadzone)
60  j->joy_axis[a] = 0.0;
61  else if (j->joy_axis[a] > 0)
62  j->joy_axis[a] -= j->deadzone;
63  else
64  j->joy_axis[a] += j->deadzone;
65  if (j->deadzone < .999)
66  j->joy_axis[a] /= (1-j->deadzone);
67  }
68 }
void modifyExponent ( JoyStick j)

Definition at line 69 of file in_joystick.cpp.

References a, JoyStick::joy_axis, vs_options::joystick_exponent, and JoyStick::nr_of_axes.

Referenced by JoyStick::GetJoyStick(), and myGlutJoystickCallback().

70 {
72  for (int a = 0; a < j->nr_of_axes; a++)
73  j->joy_axis[a] =
74  ( (j->joy_axis[a] < 0) ? -pow( -j->joy_axis[a], game_options.joystick_exponent ) : pow( j->joy_axis[a],
76  joystick_exponent ) );
77  }
78 }
void myGlutJoystickCallback ( unsigned int  buttonmask,
int  x,
int  y,
int  z 
)

Definition at line 89 of file in_joystick.cpp.

References float, i, JoyStick::joy_axis, JoyStick::joy_buttons, JoyStickToggle, MAX_AXES, maxx, maxy, maxz, minx, miny, minz, modifyDeadZone(), modifyExponent(), x, and y.

Referenced by InitJoystick().

90 {
91  unsigned int i;
92  for (i = 0; i < MAX_AXES; i++)
93  joystick[0]->joy_axis[i] = 0.0;
94  joystick[0]->joy_buttons = 0;
95  if (JoyStickToggle) {
96  joystick[0]->joy_buttons = buttonmask;
97  if (joystick[0]->nr_of_axes > 0)
98  //Set the max and min of each axis - Okona
99  if (x < minx) minx = x;
100  if (x > maxx) maxx = x;
101  //Calculate an autocalibrated value based on the max min values - Okona
102  joystick[0]->joy_axis[0] = ( (float) x-( ( (float) (maxx+minx) )/2.0 ) )/( ( (float) (maxx-minx) )/2.0 );
103  if (joystick[0]->nr_of_axes > 1)
104  if (y < miny) miny = y;
105  if (y > maxy) maxy = y;
106  joystick[0]->joy_axis[1] = ( (float) y-( ( (float) (maxy+miny) )/2.0 ) )/( ( (float) (maxy-miny) )/2.0 );
107  if (joystick[0]->nr_of_axes > 2)
108  if (z < minz) minz = z;
109  if (z > maxz) maxz = z;
110  joystick[0]->joy_axis[2] = ( (float) z-( ( (float) (maxz+minz) )/2.0 ) )/( ( (float) (maxz-minz) )/2.0 );
111  modifyDeadZone( joystick[0] );
112  modifyExponent( joystick[0] );
113  }
114 }

Variable Documentation

vs_options game_options

Draws cockpit parts Draws gauges, info strings, radar, ...

Definition at line 83 of file main.cpp.

bool JoyStickToggle = true
static
int num_joysticks = 0

Definition at line 55 of file in_joystick.cpp.

Referenced by InitJoystick(), and JoyStick::JoyStick().