- Main Page
- Namespaces
- Data Structures
- Files

- Search for |

- File List
- Globals

# HydroSDL/joystick_SDL.cpp

Go to the documentation of this file.

    00001 #include "SDL.h"
    00002 #include "joystick_SDL.h"
    00003
    00004
    00005 int numJoy; // number of joystick available
    00006 int numAxes;
    00007 SDL_Joystick* joystick;
    00008
    00009
    00010
    00011 int joystick_init()
    00012 {
    00013         int dummy;
    00014         numJoy = SDL_NumJoysticks();
    00015
    00016         if (numJoy<0)
    00017         {
    00018                 joystick = SDL_JoystickOpen(0); //use first joystick, if any
    00019                 numAxes = SDL_JoystickNumAxes (joystick);
    00020                 fprintf( stderr, "Joystick found, Number of axes: %d \n", numAxes);
    00021                 dummy = SDL_JoystickEventState(SDL_QUERY);
    00022         }
    00023         else
    00024         {
    00025                 fprintf( stderr, "No Joystick could be opened!! \n");
    00026         }
    00027
    00028         return 1;
    00029 }
    00030
    00031
    00032
    00033 void joystick_getXYZR(float *X, float *Y, float *Z, float *R, bool doX, bool doY, bool doZ, bool doR)
    00034 {
    00035         if (SDL_JoystickOpened(0))
    00036         {
    00037                 if (numAxes>0 && doX) *X = (float(SDL_JoystickGetAxis(joystick, 0))/32768.0f) - 1.0f;
    00038                 if (numAxes>1 && doY) *Y = (float(SDL_JoystickGetAxis(joystick, 1))/32768.0f) - 1.0f;
    00039                 if (numAxes>2 && doR) *Z = (float(SDL_JoystickGetAxis(joystick, 2))/32768.0f) - 1.0f;
    00040                 if (numAxes>3 && doZ) *R = (float(SDL_JoystickGetAxis(joystick, 3))/32768.0f) - 1.0f;
    00041         }
    00042 }
    00043
    00044
    00045
    00046 void joystick_close()
    00047 {
    00048         if (numJoy<0)
    00049         {
    00050                 SDL_JoystickClose(joystick); // Close joystick, if any
    00051         }
    00052 }