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
JoyStick Class Reference

#include <in_joystick.h>

Public Member Functions

 JoyStick (int)
 
void GetJoyStick (float &x, float &y, float &z, int &buttons)
 
bool isAvailable (void)
 
bool is_around (float axe, float hswitch)
 
int NumButtons ()
 
 JoyStick ()
 

Public Attributes

void * otherdata
 
int nr_of_axes
 
int nr_of_buttons
 
int nr_of_hats
 
int hat_margin
 
size_t player
 
bool axis_inverse [MAX_AXES]
 
int axis_axis [MAX_AXES]
 
float joy_axis [MAX_AXES]
 
unsigned char digital_hat [MAX_DIGITAL_HATSWITCHES]
 
bool debug_digital_hatswitch
 
int joy_buttons
 
bool joy_available
 
float joy_xmin
 
float joy_xmax
 
float joy_ymin
 
float joy_ymax
 
float joy_zmin
 
float joy_zmax
 
float joy_x
 
float joy_y
 
float joy_z
 
float deadzone
 

Detailed Description

Definition at line 62 of file in_joystick.h.

Constructor & Destructor Documentation

JoyStick::JoyStick ( int  which)

Definition at line 177 of file in_joystick.cpp.

References axis_axis, axis_inverse, vs_options::deadband, deadzone, vs_options::debug_digital_hatswitch, debug_digital_hatswitch, j, joy_available, joy_axis, joy_buttons, joy_x, joy_y, joy_z, MAX_AXES, vs_options::mouse_deadband, MOUSE_JOYSTICK, nr_of_axes, nr_of_buttons, nr_of_hats, num_joysticks, and player.

177  : mouse( which == MOUSE_JOYSTICK )
178 {
179  for (int j = 0; j < MAX_AXES; ++j) {
180  axis_axis[j] = -1;
181  axis_inverse[j] = false;
182  joy_axis[j] = 0;
183  }
184  joy_buttons = 0;
185 
186  player = which; //by default bind players to whichever joystick it is
188  if (which != MOUSE_JOYSTICK)
190 
191  else
193  ;
194  joy_available = 0;
195  joy_x = joy_y = joy_z = 0;
196  if (which == MOUSE_JOYSTICK)
197  InitMouse( which );
198 #if defined (NO_SDL_JOYSTICK)
199  return;
200 
201 #else
202 #ifdef HAVE_SDL
203  num_joysticks = SDL_NumJoysticks();
204  if (which >= num_joysticks) {
205  if (which != MOUSE_JOYSTICK)
206  joy_available = false;
207  return;
208  }
209  joy = SDL_JoystickOpen( which ); //joystick nr should be configurable
210  if (joy == NULL) {
211  printf( "warning: no joystick nr %d\n", which );
212  joy_available = false;
213  return;
214  }
215  joy_available = true;
216  nr_of_axes = SDL_JoystickNumAxes( joy );
217  nr_of_buttons = SDL_JoystickNumButtons( joy );
218  nr_of_hats = SDL_JoystickNumHats( joy );
219 #else
220  //WE HAVE GLUT
221  if (which > 0 && which != MOUSE_JOYSTICK) {
222  joy_available = false;
223  return;
224  }
225  joy_available = true;
226  nr_of_axes = 3; //glutDeviceGet(GLUT_JOYSTICK_AXES);
227  nr_of_buttons = 15; //glutDeviceGet(GLUT_JOYSTICK_BUTTONS);
228  nr_of_hats = 0;
229 #endif //we have GLUT
230 #endif
231  printf( "axes: %d buttons: %d hats: %d\n", nr_of_axes, nr_of_buttons, nr_of_hats );
232 }
JoyStick::JoyStick ( )

Definition at line 116 of file in_joystick.cpp.

References axis_axis, axis_inverse, j, joy_axis, joy_buttons, and MAX_AXES.

117 {
118  for (int j = 0; j < MAX_AXES; ++j) {
119  axis_axis[j] = -1;
120  axis_inverse[j] = false;
121  joy_axis[j] = axis_axis[j] = 0;
122  }
123  joy_buttons = 0;
124 }

Member Function Documentation

void JoyStick::GetJoyStick ( float x,
float y,
float z,
int buttons 
)

Definition at line 329 of file in_joystick.cpp.

References a, digital_hat, h, joy_available, joy_axis, joy_buttons, JoystickPollingRate(), MAX_AXES, modifyDeadZone(), modifyExponent(), nr_of_buttons, and nr_of_hats.

Referenced by ProcessJoystick().

330 {
331  //int status;
332  if (joy_available == false) {
333  for (int a = 0; a < MAX_AXES; a++)
334  joy_axis[a] = 0;
335  x = y = z = 0;
336  joy_buttons = buttons = 0;
337  return;
338  } else if (mouse) {
339  GetMouse( x, y, z, buttons );
340  return;
341  }
342  int a;
343 #ifndef NO_SDL_JOYSTICK
344 #if defined (HAVE_SDL)
345  int numaxes = SDL_JoystickNumAxes( joy );
346 
347  vector< Sint16 >axi( numaxes < MAX_AXES ? MAX_AXES : numaxes );
348  for (a = 0; a < numaxes; a++)
349  axi[a] = SDL_JoystickGetAxis( joy, a );
350  joy_buttons = 0;
351  nr_of_buttons = SDL_JoystickNumButtons( joy );
352  for (int i = 0; i < nr_of_buttons; i++) {
353  int butt = SDL_JoystickGetButton( joy, i );
354  if (butt == 1)
355  joy_buttons |= (1<<i);
356  }
357  for (int h = 0; h < nr_of_hats; h++)
358  digital_hat[h] = SDL_JoystickGetHat( joy, h );
359  for (a = 0; a < MAX_AXES; a++)
360  joy_axis[a] = ( (float) axi[a]/32768.0 );
361  modifyDeadZone( this );
362  modifyExponent( this );
363 #else //we have glut
364  if (JoystickPollingRate() <= 0)
365  glutForceJoystickFunc();
366 #endif
367  x = joy_axis[0];
368  y = joy_axis[1];
369  z = joy_axis[2];
370  buttons = joy_buttons;
371 #endif //we have no joystick
372 }
bool JoyStick::is_around ( float  axe,
float  hswitch 
)
bool JoyStick::isAvailable ( void  )

Definition at line 242 of file in_joystick.cpp.

References joy_available.

243 {
244  return joy_available;
245 }
int JoyStick::NumButtons ( )

Definition at line 374 of file in_joystick.cpp.

References nr_of_buttons.

375 {
376  return nr_of_buttons;
377 }

Member Data Documentation

int JoyStick::axis_axis[MAX_AXES]

Definition at line 86 of file in_joystick.h.

Referenced by FlyByJoystick::Execute(), and JoyStick().

bool JoyStick::axis_inverse[MAX_AXES]

Definition at line 85 of file in_joystick.h.

Referenced by FlyByJoystick::Execute(), and JoyStick().

float JoyStick::deadzone

Definition at line 101 of file in_joystick.h.

Referenced by JoyStick(), and modifyDeadZone().

bool JoyStick::debug_digital_hatswitch

Definition at line 95 of file in_joystick.h.

Referenced by JoyStick().

unsigned char JoyStick::digital_hat[MAX_DIGITAL_HATSWITCHES]

Definition at line 92 of file in_joystick.h.

Referenced by GetJoyStick(), and ProcessJoystick().

int JoyStick::hat_margin

Definition at line 82 of file in_joystick.h.

bool JoyStick::joy_available

Definition at line 98 of file in_joystick.h.

Referenced by GetJoyStick(), isAvailable(), and JoyStick().

int JoyStick::joy_buttons

Definition at line 97 of file in_joystick.h.

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

float JoyStick::joy_x

Definition at line 100 of file in_joystick.h.

Referenced by JoyStick().

float JoyStick::joy_xmax

Definition at line 99 of file in_joystick.h.

float JoyStick::joy_xmin

Definition at line 99 of file in_joystick.h.

float JoyStick::joy_y

Definition at line 100 of file in_joystick.h.

Referenced by JoyStick().

float JoyStick::joy_ymax

Definition at line 99 of file in_joystick.h.

float JoyStick::joy_ymin

Definition at line 99 of file in_joystick.h.

float JoyStick::joy_z

Definition at line 100 of file in_joystick.h.

Referenced by JoyStick().

float JoyStick::joy_zmax

Definition at line 99 of file in_joystick.h.

float JoyStick::joy_zmin

Definition at line 99 of file in_joystick.h.

int JoyStick::nr_of_axes

Definition at line 81 of file in_joystick.h.

Referenced by JoyStick(), modifyDeadZone(), and modifyExponent().

int JoyStick::nr_of_buttons

Definition at line 81 of file in_joystick.h.

Referenced by GetJoyStick(), JoyStick(), and NumButtons().

int JoyStick::nr_of_hats

Definition at line 81 of file in_joystick.h.

Referenced by GetJoyStick(), JoyStick(), and ProcessJoystick().

void* JoyStick::otherdata

Definition at line 79 of file in_joystick.h.

size_t JoyStick::player

Definition at line 83 of file in_joystick.h.

Referenced by JoyStick().


The documentation for this class was generated from the following files: