本文整理汇总了C++中SDL_JoystickGetAxis函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_JoystickGetAxis函数的具体用法?C++ SDL_JoystickGetAxis怎么用?C++ SDL_JoystickGetAxis使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_JoystickGetAxis函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetButtonState
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: sdl_pad_get_axis
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: joystick_axis
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 );
}
示例4: SDL_JoystickGetAxis
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: SDL_JoystickGetAxis
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: do_poll
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: GfctrlSDL2JoyGetCurrentStates
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: control_player_joy
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: getaxisjoystick
//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: CheckJoy
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: set_position
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: clampval
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);
}
示例13: getJoystickAxisState
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: SimulateGamepad
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: joystickb_sdl_stick_axe_analog_get
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;
}