示例#1
0
void JoystickInfo::SaveState()
{
	for (int i = 0; i < numbuttons; ++i)
		SetButtonState(i, SDL_JoystickGetButton(joy, i));
	for (int i = 0; i < numaxes; ++i)
		SetAxisState(i, SDL_JoystickGetAxis(joy, i));
	for (int i = 0; i < numhats; ++i)
		SetHatState(i, SDL_JoystickGetHat(joy, i));
}
示例#2
0
static int16_t sdl_pad_get_axis(sdl_joypad_t *pad, unsigned axis)
{
#ifdef HAVE_SDL2
   /* TODO: see if a rarch <-> sdl translation is needed. */
   if (pad->controller)
      return SDL_GameControllerGetAxis(pad->controller, (SDL_GameControllerAxis)axis);
#endif
   return SDL_JoystickGetAxis(pad->joypad, axis);
}
示例#3
0
static int joystick_axis( int axis, int dz, int div ) {
  axis = SDL_JoystickGetAxis( joy, axis );
  if( axis < dz && axis > -dz ) {
    axis = 0;
  } else {
    axis -= ( axis > 0 ? dz : -dz );
  }
  return( axis / div );
}
void JoystickControl::JoyState(){
	Sint16 x_mov = SDL_JoystickGetAxis(joystick,0);
	Sint16 y_mov = SDL_JoystickGetAxis(joystick,1);
	int sentido_personaje = personaje->getSentidoDeMovimiento();

	//frena si no se esta manteniendo para un lado el analogico
	if ( ( sentido_personaje > 0 && x_mov < JOYSTICK_DEAD_ZONE ) || (sentido_personaje < 0 && x_mov > -JOYSTICK_DEAD_ZONE)  )
		personaje->Frenar();

	//se levanta si no esta manteniendo para abajo el analogico
	if (!(y_mov > JOYSTICK_DEAD_ZONE))
		personaje->Levantarse();

	//se deja de cubrir si no esta apretado
	if (SDL_JoystickGetButton(joystick,JOY_R1) == BUTTON_UNPRESSED)
		personaje->dejarDeCubrirse();

}
示例#5
0
float DPInput::JoyAxis(int axis)
{
    Sint16 intvalue;
    if (joystick) {
        intvalue = SDL_JoystickGetAxis(joystick, axis);
        return ((float)intvalue + 0.5) / 32767.5f;
    }
    return 0.0f;
};
示例#6
0
static void do_poll(void) {
	int i;
	SDL_JoystickUpdate();
	/* Scan axes */
	for (i = 0; i < 4; i++) {
		if (control[i].joy) {
			input_control_press(i, ((SDL_JoystickGetAxis(control[i].joy->device, control[i].control_num)+32768) >> 8) ^ control[i].invert);
		}
	}
示例#7
0
int
GfctrlSDL2JoyGetCurrentStates(tCtrlJoyInfo *joyInfo)
{
   int			ind;
   int			i,j;
   unsigned int	b;
   unsigned int	mask;
   if (gfctrlJoyPresent == GFCTRL_JOY_PRESENT)
   {
      // Update all the joysticks
      SDL_JoystickUpdate();
      for (ind = 0; ind < gfctrlJoyPresent; ind++) 
      {
         if (Joysticks[ind])
         {
            j = SDL_JoystickNumAxes(Joysticks[ind]);
            if (j > GFCTRL_JOY_MAX_AXES) j = GFCTRL_JOY_MAX_AXES;

            for (i=0; i < j;i++)
               joyInfo->ax[GFCTRL_JOY_MAX_AXES * ind + i] = ((float) SDL_JoystickGetAxis(Joysticks[ind],i)) / 32768;

            b = 0;
            for (i=0; i < GFCTRL_JOY_MAX_BUTTONS;i++) 
            {
               mask = (unsigned int)SDL_JoystickGetButton(Joysticks[ind], i);
               b |= (mask << i);
            }

            /* Joystick buttons */
            for (i = 0, mask = 1; i < GFCTRL_JOY_MAX_BUTTONS; i++, mask *= 2) 
            {
               if (((b & mask) != 0) && ((joyInfo->oldb[ind] & mask) == 0)) {
                  joyInfo->edgeup[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 1;
               } else {
                  joyInfo->edgeup[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 0;
               }
               if (((b & mask) == 0) && ((joyInfo->oldb[ind] & mask) != 0)) {
                  joyInfo->edgedn[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 1;
               } else {
                  joyInfo->edgedn[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 0;
               }
               if ((b & mask) != 0) {
                  joyInfo->levelup[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 1;
               } else {
                  joyInfo->levelup[i + GFCTRL_JOY_MAX_BUTTONS * ind] = 0;
               }
            }
            joyInfo->oldb[ind] = b;
         }
      }
   }
   else
   {
      return -1;
   }
   return 0;
}
示例#8
0
void control_player_joy(SDL_Joystick *joy, pDesc *p)
{
	Uint8* keys;
	Uint8* mousebut;
	
	keys=SDL_GetKeyState(NULL);		
	mousebut=SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1);	
	
	int x,y,but;
	
	if(pause)
		return;

	SDL_JoystickUpdate();
	x=SDL_JoystickGetAxis(joy,0);
	y=SDL_JoystickGetAxis(joy,1);
	
	if(x<-16800) {//-4200 //21000
		p->incy=+1;
	} 
		
	if(x>-10500) {//4200
		p->incy=-1;		
	}		
	
	if(y<-4200) {	
		p->incx=-1;
	}
	
	if(y>4200) {
		p->incx=+1;
	}

	if(x>-16800 && x<-10500) //-21000
		p->incy=0;

	if(y>-4200 && y<4200)
		p->incx=0;
		
	if((mousebut||keys[p->keys[4]]) && !p->fire)//mousebut && !p->fire
		p->fire=1;
	if(!mousebut && !keys[p->keys[4]])//!mousebut
		p->fire=0;
}
示例#9
0
//getaxisjoystick(i,a) 							: Get the current state of an axis
int getaxisjoystick(int index,int axis)
{
    int ret;
    SDL_JoystickUpdate();
    if (SDLjoy[index])
	ret= SDL_JoystickGetAxis(SDLjoy[index],axis);
    else
	ret=0;
    return ret;
}
示例#10
0
void CheckJoy() {
    uint8_t i, j, n;

    SDL_JoystickUpdate();

    for (i = 0; i < 2; i++) {
        for (j = 0; j < DKEY_TOTAL; j++) {
            switch (g.cfg.PadDef[i].KeyDef[j].JoyEvType) {

                case AXIS:
                    n = abs(g.cfg.PadDef[i].KeyDef[j].J.Axis) - 1;

                    if (g.cfg.PadDef[i].KeyDef[j].J.Axis > 0) {
                        if (SDL_JoystickGetAxis(g.PadState[i].JoyDev, n) > 16383) {
                            bdown(i, j);
                        } else {
                            bup(i, j);
                        }
                    } else if (g.cfg.PadDef[i].KeyDef[j].J.Axis < 0) {
                        if (SDL_JoystickGetAxis(g.PadState[i].JoyDev, n) < -16383) {
                            bdown(i, j);
                        } else {
                            bup(i, j);
                        }
                    }
                    break;

                case BUTTON:
                    if (SDL_JoystickGetButton(g.PadState[i].JoyDev, g.cfg.PadDef[i].KeyDef[j].J.Button)) {
                        bdown(i, j);
                    } else {
                        bup(i, j);
                    }
                    break;

                default:
                    break;
            }
        }
    }

    CheckAnalog();
}
示例#11
0
文件: rockpush.c 项目: amfo/rockpush
void set_position(Rock_Sprite *object_rocco, SDL_Event event, SDL_Joystick *joystick)
{
  Sint16 joyx = 0, joyy = 0;
  Sint32 orientation;

    if (!(orientation = event.key.keysym.sym) && SDL_JoystickGetAttached(joystick)) {
        SDL_JoystickUpdate();

        joyx = SDL_JoystickGetAxis(joystick, 0);
        joyy = SDL_JoystickGetAxis(joystick, 1);

        if (joyy < -10)
            orientation = SDLK_UP;

        if (joyy > 10)
            orientation = SDLK_DOWN;

        if (joyx < -10)
            orientation = SDLK_LEFT;

        if (joyx > 10)
            orientation = SDLK_RIGHT;
    }

    switch (orientation) {
        case SDLK_RIGHT:
            rocco_set_action(object_rocco, RIGHT);
            break;

        case SDLK_LEFT:
            rocco_set_action(object_rocco, LEFT);
            break;

        case SDLK_UP:
            rocco_set_action(object_rocco, UP);
            break;

        case SDLK_DOWN:
            rocco_set_action(object_rocco, DOWN);
            break;

    }
}
示例#12
0
	float Joystick::getAxis(int index, int axis)
	{
		if (!verifyJoystick(index))
			return 0;

		if (axis >= getNumAxes(index))
			return 0;

		return clampval(((float)SDL_JoystickGetAxis(joysticks[index], axis))/32768.0f);
	}
static int
getJoystickAxisState(const config::input::InputDevice *device,
                     SDL_GameController *controller,
                     vpad::Channel channel,
                     vpad::CoreAxis axis)
{
   decaf_check(device);
   decaf_check(controller);

   auto joystick = SDL_GameControllerGetJoystick(controller);
   decaf_check(joystick);

   auto index = -1;
   auto name = SDL_CONTROLLER_AXIS_INVALID;
   auto invert = false;

   switch (axis) {
   case vpad::CoreAxis::LeftStickX:
      index = device->joystick.left_stick_x;
      name = SDL_CONTROLLER_AXIS_LEFTX;
      invert = device->joystick.left_stick_x_invert;
      break;
   case vpad::CoreAxis::LeftStickY:
      index = device->joystick.left_stick_y;
      name = SDL_CONTROLLER_AXIS_LEFTY;
      invert = device->joystick.left_stick_y_invert;
      break;
   case vpad::CoreAxis::RightStickX:
      index = device->joystick.right_stick_x;
      name = SDL_CONTROLLER_AXIS_RIGHTX;
      invert = device->joystick.right_stick_x_invert;
      break;
   case vpad::CoreAxis::RightStickY:
      index = device->joystick.right_stick_y;
      name = SDL_CONTROLLER_AXIS_RIGHTY;
      invert = device->joystick.right_stick_y_invert;
      break;
   }

   auto value = 0;

   if (index >= 0) {
      value = SDL_JoystickGetAxis(joystick, index);
   } else if (index == -2) {
      if (name != SDL_CONTROLLER_AXIS_INVALID) {
         value = SDL_GameControllerGetAxis(controller, name);
      }
   }

   if (invert) {
      value = -value;
   }

   return value;
}
示例#14
0
文件: PCMain.cpp 项目: PeterTh/native
void SimulateGamepad(const uint8 *keys, InputState *input) {
	input->pad_buttons = 0;
	input->pad_lstick_x = 0;
	input->pad_lstick_y = 0;
	input->pad_rstick_x = 0;
	input->pad_rstick_y = 0;
	for (int b = 0; b < 14; b++) {
		if (keys[buttonMappings[b]])
			input->pad_buttons |= (1<<b);
	}

#ifdef PANDORA
	if ((ljoy)||(rjoy)) {
		SDL_JoystickUpdate();
		if (ljoy) {
			input->pad_lstick_x = SDL_JoystickGetAxis(ljoy, 0) / 32768.0f;
			input->pad_lstick_y = SDL_JoystickGetAxis(ljoy, 1) / 32768.0f;
		}
		if (rjoy) {
			input->pad_rstick_x = SDL_JoystickGetAxis(rjoy, 0) / 32768.0f;
			input->pad_rstick_y = SDL_JoystickGetAxis(rjoy, 1) / 32768.0f;
		}
	}
#else
	if (keys[SDLK_i])
		input->pad_lstick_y=1;
	else if (keys[SDLK_k])
		input->pad_lstick_y=-1;
	if (keys[SDLK_j])
		input->pad_lstick_x=-1;
	else if (keys[SDLK_l])
		input->pad_lstick_x=1;
	if (keys[SDLK_KP8])
		input->pad_rstick_y=1;
	else if (keys[SDLK_KP2])
		input->pad_rstick_y=-1;
	if (keys[SDLK_KP4])
		input->pad_rstick_x=-1;
	else if (keys[SDLK_KP6])
		input->pad_rstick_x=1;
#endif
}
示例#15
0
int joystickb_sdl_stick_axe_analog_get(unsigned joystick, unsigned stick, unsigned axe)
{
	int r;
	log_debug(("joystickb:sdl: joystickb_sdl_stick_axe_analog_get()\n"));

	r = SDL_JoystickGetAxis(sdl_state.map[joystick], axe);

	r = joystickb_adjust_analog(r, -32768, 32768);

	return r;
}
示例#16
0
bool JoystickInfo::PollAxes(u32 &pkey)
{
    for (int i = 0; i < GetNumAxes(); ++i)
    {
        // Sixaxis, dualshock3 hack
        u32 found_hack = devname.find(string("PLAYSTATION(R)3"));
        if (found_hack != string::npos) {
            // The analog mode of the hat button is quite erratic. Values can be in half- axis
            // or full axis... So better keep them as button for the moment -- gregory
            if (i >= 8 && i <= 11 && (conf->pad_options[pad].sixaxis_usb))
                continue;
            // Disable accelerometer
            if ((i >= 4 && i <= 6))
                continue;
        }

        s32 value = SDL_JoystickGetAxis(GetJoy(), i);
        s32 old_value = GetAxisState(i);

        if (abs(value - old_value) < 0x1000)
            continue;

        if (value != old_value)
        {
            PAD_LOG("Change in joystick %d: %d.\n", i, value);
            // There are several kinds of axes
            // Half+: 0 (release) -> 32768
            // Half-: 0 (release) -> -32768
            // Full (like dualshock 3): -32768 (release) ->32768
            const s32 full_axis_ceil = -0x6FFF;
            const s32 half_axis_ceil = 0x1FFF;

            // Normally, old_value contains the release state so it can be used to detect the types of axis.
            bool is_full_axis = (old_value < full_axis_ceil) ? true : false;

            if ((!is_full_axis && abs(value) <= half_axis_ceil)
                    || (is_full_axis && value <= full_axis_ceil))  // we don't want this
            {
                continue;
            }

            if ((!is_full_axis && abs(value) > half_axis_ceil)
                    || (is_full_axis && value > full_axis_ceil))
            {
                bool sign = (value < 0);
                pkey = axis_to_key(is_full_axis, sign, i);

                return true;
            }
        }
    }

    return false;
}
示例#17
0
static mrb_value
mrb_sdl2_joystick_joystick_get_axis_y(mrb_state *mrb, mrb_value self)
{
  SDL_Joystick * joystick_p = mrb_sdl2_joystick_joystick_get_ptr(mrb, self);
  Sint16 result = SDL_JoystickGetAxis(joystick_p, 1);
  if (result == 0) {
    mruby_sdl2_raise_error(mrb);
  }

  return mrb_fixnum_value(result);
}
示例#18
0
int libjoy_get_position_specific( int joy, int axis )
{
    if ( joy >= 0 && joy < _max_joys )
    {
        if ( axis >= 0 && axis <= SDL_JoystickNumAxes( _joysticks[ joy ] ) )
        {
            return SDL_JoystickGetAxis( _joysticks[ joy ], axis ) ;
        }
    }
    return 0 ;
}
示例#19
0
文件: app.cpp 项目: pol51/colobot
/** Updates the state info in CApplication and on change, creates SDL events and pushes them to SDL event queue.
    This way, the events get handled properly in the main event loop and besides, SDL_PushEvent() ensures thread-safety. */
void CApplication::UpdateJoystick()
{
    if (! m_joystickEnabled)
        return;

    SDL_JoystickUpdate();

    for (int axis = 0; axis < static_cast<int>( m_joyAxeState.size() ); ++axis)
    {
        int newValue = SDL_JoystickGetAxis(m_private->joystick, axis);

        if (m_joyAxeState[axis] != newValue)
        {
            m_joyAxeState[axis] = newValue;

            SDL_Event joyAxisEvent;

            joyAxisEvent.jaxis.type = SDL_JOYAXISMOTION;
            joyAxisEvent.jaxis.which = 0;
            joyAxisEvent.jaxis.axis = axis;
            joyAxisEvent.jaxis.value = newValue;

            SDL_PushEvent(&joyAxisEvent);
        }
    }

    for (int button = 0; button < static_cast<int>( m_joyButtonState.size() ); ++button)
    {
        bool newValue = SDL_JoystickGetButton(m_private->joystick, button) == 1;

        if (m_joyButtonState[button] != newValue)
        {
            m_joyButtonState[button] = newValue;

            SDL_Event joyButtonEvent;

            if (newValue)
            {
                joyButtonEvent.jbutton.type = SDL_JOYBUTTONDOWN;
                joyButtonEvent.jbutton.state = SDL_PRESSED;
            }
            else
            {
                joyButtonEvent.jbutton.type = SDL_JOYBUTTONUP;
                joyButtonEvent.jbutton.state = SDL_RELEASED;
            }
            joyButtonEvent.jbutton.which = 0;
            joyButtonEvent.jbutton.button = button;

            SDL_PushEvent(&joyButtonEvent);
        }
    }
}
示例#20
0
void SimulateGamepad(const uint8 *keys, InputState *input) {
	input->pad_buttons = 0;
	input->pad_lstick_x = 0;
	input->pad_lstick_y = 0;
	input->pad_rstick_x = 0;
	input->pad_rstick_y = 0;
// TODO: Use NativeAxis for joy instead.
#ifdef PANDORA
	if ((ljoy)||(rjoy)) {
		SDL_JoystickUpdate();
		if (ljoy) {
			input->pad_lstick_x = max(min(SDL_JoystickGetAxis(ljoy, 0) / 32000.0f, 1.0f), -1.0f);
			input->pad_lstick_y = max(min(-SDL_JoystickGetAxis(ljoy, 1) / 32000.0f, 1.0f), -1.0f);
		}
		if (rjoy) {
			input->pad_rstick_x = max(min(SDL_JoystickGetAxis(rjoy, 0) / 32000.0f, 1.0f), -1.0f);
			input->pad_rstick_y = max(min(SDL_JoystickGetAxis(rjoy, 1) / 32000.0f, 1.0f), -1.0f);
		}
	}
#endif
}
示例#21
0
	float Joystick::getAxisValue(int8_t axis) const {
		if (axis < 0 || !isConnected()) {
			return 0;
		}

		if (!isController()) {
			return convertRange(SDL_JoystickGetAxis(m_joystickHandle, axis));
		}

		SDL_GameControllerAxis sdlAxis = static_cast<SDL_GameControllerAxis>(axis);
		return convertRange(SDL_GameControllerGetAxis(m_controllerHandle, sdlAxis));
	}
示例#22
0
void cStateEndRun::Tick(const Ogre::FrameEvent& evt, SDL_Event event){
	SDL_JoystickUpdate();
	//Todo cut this down to two axis on the same stick;
	short s1 = SDL_JoystickGetAxis(m_pJoystick, 0);
	short s2 = SDL_JoystickGetAxis(m_pJoystick, 1);
	short s3 = SDL_JoystickGetAxis(m_pJoystick, 2);
	short s4 = SDL_JoystickGetAxis(m_pJoystick, 3);

	//TODO; Deadzone may be joystick specific right now set to 800
	if(abs(s1) > 800){
	    s1 = s1/32767;
		printf("Menu:%i\n",s1);
	}
	if(abs(s2) > 800){
		s2 = s2/32767;
		printf("Menu:%i\n",s2);
	}
	if(abs(s3) > 800){
		s3 = s3/32767;
		printf("Menu:%i\n",s3);
	}
	if(abs(s4) > 800){
		s4 = s4/32767;
		printf("Menu:%i\n",s4);
	}
	if( event.type == SDL_KEYUP ){
	    KeyMap::iterator i = m_mKeys.find(event.key.keysym.sym);
	    if(i != m_mKeys.end()){
	    	KeyHandler Function = i->second;
	    	Function();
	    }
	}
	if(event.type == SDL_JOYBUTTONDOWN){
	    ButtonMap::iterator j = m_mButtons.find(event.jbutton.button);
	    if(j != m_mButtons.end()){
	    	KeyHandler Function = j->second;
	    	Function();
	    }
	}
}
示例#23
0
int PERSDLJoyInit(void) {
	int i, j;

	// does not need init if already done
	if ( SDL_PERCORE_INITIALIZED )
	{
		return 0;
	}

#if defined (_MSC_VER) && SDL_VERSION_ATLEAST(2,0,0)
   SDL_SetMainReady();
#endif

	// init joysticks
	if ( SDL_InitSubSystem( SDL_INIT_JOYSTICK ) == -1 )
	{
		return -1;
	}
	
	// ignore joysticks event in sdl event loop
	SDL_JoystickEventState( SDL_IGNORE );
	
	// open joysticks
	SDL_PERCORE_JOYSTICKS_INITIALIZED = SDL_NumJoysticks();
	SDL_PERCORE_JOYSTICKS = malloc(sizeof(PERSDLJoystick) * SDL_PERCORE_JOYSTICKS_INITIALIZED);
	for ( i = 0; i < SDL_PERCORE_JOYSTICKS_INITIALIZED; i++ )
	{
		SDL_Joystick* joy = SDL_JoystickOpen( i );
		
		SDL_JoystickUpdate();
		
		SDL_PERCORE_JOYSTICKS[ i ].mJoystick = joy;
		SDL_PERCORE_JOYSTICKS[ i ].mScanStatus = joy ? malloc(sizeof(s16) * SDL_JoystickNumAxes( joy )) : 0;
		SDL_PERCORE_JOYSTICKS[ i ].mHatStatus = joy ? malloc(sizeof(Uint8) * SDL_JoystickNumHats( joy )) : 0;
		
		if ( joy )
		{
			for ( j = 0; j < SDL_JoystickNumAxes( joy ); j++ )
			{
				SDL_PERCORE_JOYSTICKS[ i ].mScanStatus[ j ] = SDL_JoystickGetAxis( joy, j );
			}
			for ( j = 0; j < SDL_JoystickNumHats( joy ); j++ )
			{
				SDL_PERCORE_JOYSTICKS[ i ].mHatStatus[ j ] = SDL_JoystickGetHat( joy, j );
			}
		}
	}
	
	// success
	SDL_PERCORE_INITIALIZED = 1;
	return 0;
}
示例#24
0
void ndof_update(NDOF_Device *in_dev)
{
    int i;

    LinJoystickPrivate *priv = (LinJoystickPrivate *) in_dev->private_data;
    assert(priv != NULL);

    if(priv->USE_SDL)
    {
        SDL_JoystickUpdate();
        SDL_Joystick *j = priv->j;

        for(i = 0; i < in_dev->axes_count; i++)
        {
            in_dev->axes[i] = (int) (SDL_JoystickGetAxis(j, i));
        }

        for(i = 0; i < in_dev->btn_count; i++)
        {
            in_dev->buttons[i] = SDL_JoystickGetButton(j, i);
        }
    } else {
        // update SpaceNavigator

        struct input_event ev;

        while(read(priv->fd, &ev, sizeof(struct input_event)) > 0)
        {
            switch (ev.type)
            {
                case EV_KEY:
                    // printf("Key %d pressed %d.\n", ev.code, ev.value);
                    priv->buttons[ev.code & 0xff] = ev.value;
                    break;

                case EV_REL:
                case EV_ABS: // 2.6.35 and up, maybe earlier kernels too send EV_ABS instead of EV_REL
                    // printf("%d %g\n", ev.code, ev.value);

                    // clean up small values
                    priv->axes[ev.code] = abs(ev.value) > SPACE_NAVIG_THRESHOLD ? ev.value : 0;
                    break;

                default:
                    break;
            }
        }

        memcpy(in_dev->axes, priv->axes, in_dev->axes_count * sizeof(long int));
        memcpy(in_dev->buttons, priv->buttons, in_dev->btn_count * sizeof(long int));
    }
}
示例#25
0
///////////////////////////////////////////////////////////////////////////
//
//	IN_GetJoyFineDelta() - Returns the relative movement of the specified
//		joystick without dividing the results by 256 (from +/-127)
//
///////////////////////////////////////////////////////////////////////////
void IN_GetJoyFineDelta(int *dx, int *dy)
{
    if(!Joystick)
    {
        *dx = 0;
        *dy = 0;
        return;
    }

    SDL_JoystickUpdate();
    int x = SDL_JoystickGetAxis(Joystick, 0);
    int y = SDL_JoystickGetAxis(Joystick, 1);

    if(x < -128) x = -128;
    else if(x > 127) x = 127;

    if(y < -128) y = -128;
    else if(y > 127) y = 127;

    *dx = x;
    *dy = y;
}
示例#26
0
static void GetAxis(joystick_t *joy)
{
	// Get axes values, convert to direction
	const int x = SDL_JoystickGetAxis(joy->j, 0);
	const int y = SDL_JoystickGetAxis(joy->j, 1);
	if (x < -JOY_AXIS_THRESHOLD)
	{
		joy->currentButtonsField |= CMD_LEFT;
	}
	else if (x > JOY_AXIS_THRESHOLD)
	{
		joy->currentButtonsField |= CMD_RIGHT;
	}
	if (y < -JOY_AXIS_THRESHOLD)
	{
		joy->currentButtonsField |= CMD_UP;
	}
	else if (y > JOY_AXIS_THRESHOLD)
	{
		joy->currentButtonsField |= CMD_DOWN;
	}
}
示例#27
0
void InputSwitchJoystick(const int inc)
{
#ifdef __GCW0__
	JoystickIndex = CLAMP_OPPOSITE(JoystickIndex + inc, -1, 1);
	if (JoystickIndex == 1 && gSensor)
	{
		// Recalibrate G sensor
		gZero = (int16_t)SDL_JoystickGetAxis(gSensor, 0);
	}
#else
	UNUSED(inc);
#endif
}
示例#28
0
int libjoy_get_button_specific( int joy, int button )
{
    if ( joy >= 0 && joy < _max_joys )
    {
#ifdef TARGET_CAANOO
        if ( button >= 0 && ( ( joy == 0 && button <= 21 ) || ( joy != 0 && SDL_JoystickNumButtons( _joysticks[ joy ] ) ) ) )
#else
        if ( button >= 0 && button <= SDL_JoystickNumButtons( _joysticks[ joy ] ) )
#endif
        {
#ifdef TARGET_CAANOO
            if ( joy == 0 )
            {
                int vax;

                switch ( button )
                {
                    case    1: /* UPLF                  */  return ( SDL_JoystickGetAxis( _joysticks[ 0 ], 1 ) < -16384 && SDL_JoystickGetAxis( _joysticks[ 0 ], 0 ) < -16384 );
                    case    3: /* DWLF                  */  return ( SDL_JoystickGetAxis( _joysticks[ 0 ], 1 ) >  16384 && SDL_JoystickGetAxis( _joysticks[ 0 ], 0 ) < -16384 );
                    case    5: /* DWRT                  */  return ( SDL_JoystickGetAxis( _joysticks[ 0 ], 1 ) >  16384 && SDL_JoystickGetAxis( _joysticks[ 0 ], 0 ) >  16384 );
                    case    7: /* UPRT                  */  return ( SDL_JoystickGetAxis( _joysticks[ 0 ], 1 ) < -16384 && SDL_JoystickGetAxis( _joysticks[ 0 ], 0 ) >  16384 );
                    case    0: /* UP                    */  vax = SDL_JoystickGetAxis( _joysticks[ 0 ], 0 ) ; return ( SDL_JoystickGetAxis( _joysticks[ 0 ], 1 ) < -16384 && ABS( vax ) < 16384 );
                    case    4: /* DW                    */  vax = SDL_JoystickGetAxis( _joysticks[ 0 ], 0 ) ; return ( SDL_JoystickGetAxis( _joysticks[ 0 ], 1 ) >  16384 && ABS( vax ) < 16384 );
                    case    2: /* LF                    */  vax = SDL_JoystickGetAxis( _joysticks[ 0 ], 1 ) ; return ( SDL_JoystickGetAxis( _joysticks[ 0 ], 0 ) < -16384 && ABS( vax ) < 16384 );
                    case    6: /* RT                    */  vax = SDL_JoystickGetAxis( _joysticks[ 0 ], 1 ) ; return ( SDL_JoystickGetAxis( _joysticks[ 0 ], 0 ) >  16384 && ABS( vax ) < 16384 );

                    case    8:  /* MENU->HOME           */  return ( SDL_JoystickGetButton( _joysticks[ 0 ], 6 ) );
                    case    9:  /* SELECT->HELP-II      */  return ( SDL_JoystickGetButton( _joysticks[ 0 ], 9 ) );
                    case    10: /* L                    */  return ( SDL_JoystickGetButton( _joysticks[ 0 ], 4 ) );
                    case    11: /* R                    */  return ( SDL_JoystickGetButton( _joysticks[ 0 ], 5 ) );
                    case    12: /* A                    */  return ( SDL_JoystickGetButton( _joysticks[ 0 ], 0 ) );
                    case    13: /* B                    */  return ( SDL_JoystickGetButton( _joysticks[ 0 ], 2 ) );
                    case    14: /* X                    */  return ( SDL_JoystickGetButton( _joysticks[ 0 ], 1 ) );
                    case    15: /* Y                    */  return ( SDL_JoystickGetButton( _joysticks[ 0 ], 3 ) );
                    case    16: /* VOLUP                */  return ( 0 );
                    case    17: /* VOLDOWN              */  return ( 0 );
                    case    18: /* CLICK                */  return ( SDL_JoystickGetButton( _joysticks[ 0 ], 10 ) );
                    case    19: /* POWER-LOCK  (CAANOO) */  return ( SDL_JoystickGetButton( _joysticks[ 0 ], 7 ) ); /* Only Caanoo */
                    case    20: /* HELP-I      (CAANOO) */  return ( SDL_JoystickGetButton( _joysticks[ 0 ], 8 ) ); /* Only Caanoo */
                    default:                                return ( 0 );
                }
            }
#endif
            return SDL_JoystickGetButton( _joysticks[ joy ], button ) ;
        }
    }
    return 0 ;
}
示例#29
0
static mrb_value
mrb_sdl2_joystick_joystick_get_axis(mrb_state *mrb, mrb_value self)
{
  Sint16 result;
  mrb_int axis;
  SDL_Joystick * joystick_p = mrb_sdl2_joystick_joystick_get_ptr(mrb, self);
  mrb_get_args(mrb, "i", &axis);
  result = SDL_JoystickGetAxis(joystick_p, (int) axis);
  if (result == 0) {
    mruby_sdl2_raise_error(mrb);
  }

  return mrb_fixnum_value(result);
}
示例#30
0
	int Joystick::getAxes(lua_State * L)
	{
		love::luax_assert_argc(L, 1, 1);
		int index = (int)lua_tointeger(L, 1) - 1;

		if (!verifyJoystick(index))
			return 0;

		int num = getNumAxes(index);

		for (int i = 0; i<num; i++)
			lua_pushnumber(L, clampval(((float)SDL_JoystickGetAxis(joysticks[index], i))/32768.0f));
		return num;
	}