当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_JoystickGetHat函数代码示例

本文整理汇总了C++中SDL_JoystickGetHat函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_JoystickGetHat函数的具体用法?C++ SDL_JoystickGetHat怎么用?C++ SDL_JoystickGetHat使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_JoystickGetHat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SDL_JoystickUpdate

void Joystick::pollUpdate()
{
    SDL_JoystickUpdate();
    // update the state of every button
    for (int i=0; i<buttonsSupported(); i++){
        bool buttonHeld = SDL_JoystickGetButton(joy_, i);

        // map hats to buttons 12 to 15
        bool hatHeld = false;
        if(i==12 && (SDL_JoystickGetHat(joy_, 0) & SDL_HAT_UP)
        || i==13 && (SDL_JoystickGetHat(joy_, 0) & SDL_HAT_RIGHT)
        || i==14 && (SDL_JoystickGetHat(joy_, 0) & SDL_HAT_DOWN)
        || i==15 && (SDL_JoystickGetHat(joy_, 0) & SDL_HAT_LEFT))
            hatHeld = true;
        
        // buttonHeld will be true if either the button or a hat is held
        buttonHeld = buttonHeld|hatHeld;

        // set button pressed and held states
        if (buttonHeld){
            buttonPressedStates_[i] = !buttonHeldStates_[i];
            buttonHeldStates_[i] = true;
        }
        else
            buttonPressedStates_[i] = buttonHeldStates_[i] = false;
    }

    // axes
    for (int i=0; i<axesSupported(); i++)
        // map axis value to -1 to 1
        axisStates_[i] = float(SDL_JoystickGetAxis(joy_, i)) / 32768.0f; // max size of signed short int
}
开发者ID:MysteriousJ,项目名称:GamepadKeyController,代码行数:32,代码来源:Joystick.cpp

示例2: switch

bool JoyData::getState(int key_enum) const
{
    if(index < 0)
        return false;
    switch(key_type[key_enum])
    {
    case POS_AXIS:
        return SDL_JoystickGetAxis(joysticks[index], key_index[key_enum]) > JOY_DEAD_ZONE;
    case NEG_AXIS:
        return SDL_JoystickGetAxis(joysticks[index], key_index[key_enum]) < -JOY_DEAD_ZONE;
    case BUTTON:
        return SDL_JoystickGetButton(joysticks[index], key_index[key_enum]);
    case HAT_UP:
        return (SDL_JoystickGetHat(joysticks[index], key_index[key_enum]) & SDL_HAT_UP);
    case HAT_RIGHT:
        return (SDL_JoystickGetHat(joysticks[index], key_index[key_enum]) & SDL_HAT_RIGHT);
    case HAT_DOWN:
        return (SDL_JoystickGetHat(joysticks[index], key_index[key_enum]) & SDL_HAT_DOWN);
    case HAT_LEFT:
        return (SDL_JoystickGetHat(joysticks[index], key_index[key_enum]) & SDL_HAT_LEFT);
        // Diagonals are ignored because they are combinations of the cardinals
    case HAT_UP_RIGHT:
    case HAT_DOWN_RIGHT:
    case HAT_DOWN_LEFT:
    case HAT_UP_LEFT:
    default:
        return false;
    }
}
开发者ID:grimfang4,项目名称:openglad,代码行数:29,代码来源:input.cpp

示例3: SDL_JoystickUpdate

bool SdlJoystick::sample()
{
   SDL_JoystickUpdate();
   
   for (unsigned int i = 0 ; i < mButtons.size() ; ++i)
   {
      mButtons[i] = gadget::DigitalState::OFF;
      if (SDL_JoystickGetButton(mJoystick, i))
      {
        mButtons[i] = gadget::DigitalState::ON;
      }
      mButtons[i].setTime();
   }

   for (unsigned int i = 0 ; i < mAxes.size() ; ++i)
   {
      mAxes[i].setValue(SDL_JoystickGetAxis(mJoystick, i));
      mAxes[i].setTime();
   }

   for (unsigned int i = 0 ; i < mHats.size() ; ++i)
   {
      mHats[i].setValue(static_cast<HatState::State>(SDL_JoystickGetHat(mJoystick, i)));
      mHats[i].setTime();
   }

   addDigitalSample(mButtons);
   addAnalogSample(mAxes);
   addHatSample(mHats);

   return true;
}
开发者ID:Michael-Lfx,项目名称:vrjuggler,代码行数:32,代码来源:SdlJoystick.cpp

示例4: FindUncenteredHat

static int FindUncenteredHat(SDL_Joystick *joystick, int *axis_invert)
{
    int i, hatval;

    for (i = 0; i < SDL_JoystickNumHats(joystick); ++i)
    {
        hatval = SDL_JoystickGetHat(joystick, i);

        switch (hatval)
        {
            case SDL_HAT_LEFT:
            case SDL_HAT_RIGHT:
                *axis_invert = hatval != SDL_HAT_LEFT;
                return CREATE_HAT_AXIS(i, HAT_AXIS_HORIZONTAL);

            case SDL_HAT_UP:
            case SDL_HAT_DOWN:
                *axis_invert = hatval != SDL_HAT_UP;
                return CREATE_HAT_AXIS(i, HAT_AXIS_VERTICAL);

            // If the hat is centered, or is not pointing in a
            // definite direction, then ignore it. We don't accept
            // the hat being pointed to the upper-left for example,
            // because it's ambiguous.
            case SDL_HAT_CENTERED:
            default:
                break;
        }
    }

    // None found.
    return -1;
}
开发者ID:Azarien,项目名称:chocolate-doom,代码行数:33,代码来源:txt_joyaxis.c

示例5: SDL_GameControllerGetButton

/*
 * Get the current state of a button on a controller
 */
Uint8
SDL_GameControllerGetButton(SDL_GameController * gamecontroller, SDL_GameControllerButton button)
{
    if ( !gamecontroller )
        return 0;

    if ( gamecontroller->mapping.buttons[button] >= 0 )
    {
        return ( SDL_JoystickGetButton( gamecontroller->joystick, gamecontroller->mapping.buttons[button] ) );
    }
    else if ( gamecontroller->mapping.axesasbutton[button] >= 0 )
    {
        Sint16 value;
        value = SDL_JoystickGetAxis( gamecontroller->joystick, gamecontroller->mapping.axesasbutton[button] );
        if ( ABS(value) > 32768/2 )
            return 1;
        return 0;
    }
    else if ( gamecontroller->mapping.hatasbutton[button].hat >= 0 )
    {
        Uint8 value;
        value = SDL_JoystickGetHat( gamecontroller->joystick, gamecontroller->mapping.hatasbutton[button].hat );

        if ( value & gamecontroller->mapping.hatasbutton[button].mask )
            return 1;
        return 0;
    }

    return 0;
}
开发者ID:Archytaus,项目名称:qgame-sdl2-mirror,代码行数:33,代码来源:SDL_gamecontroller.c

示例6: ProcessInput

    void ProcessInput()
    {
        BYTE buttonstate;

        for (int i = 0; i < NumAxes; ++i)
        {
            buttonstate = 0;

            Axes[i].Value = SDL_JoystickGetAxis(Device, i)/32767.0;
            Axes[i].Value = Joy_RemoveDeadZone(Axes[i].Value, Axes[i].DeadZone, &buttonstate);

            // Map button to axis
            // X and Y are handled differently so if we have 2 or more axes then we'll use that code instead.
            if (NumAxes == 1 || (i >= 2 && i < NUM_JOYAXISBUTTONS))
            {
                Joy_GenerateButtonEvents(Axes[i].ButtonValue, buttonstate, 2, KEY_JOYAXIS1PLUS + i*2);
                Axes[i].ButtonValue = buttonstate;
            }
        }

        if(NumAxes > 1)
        {
            buttonstate = Joy_XYAxesToButtons(Axes[0].Value, Axes[1].Value);
            Joy_GenerateButtonEvents(Axes[0].ButtonValue, buttonstate, 4, KEY_JOYAXIS1PLUS);
            Axes[0].ButtonValue = buttonstate;
        }

        // Map POV hats to buttons and axes.  Why axes?  Well apparently I have
        // a gamepad where the left control stick is a POV hat (instead of the
        // d-pad like you would expect, no that's pressure sensitive).  Also
        // KDE's joystick dialog maps them to axes as well.
        for (int i = 0; i < NumHats; ++i)
        {
            AxisInfo &x = Axes[NumAxes + i*2];
            AxisInfo &y = Axes[NumAxes + i*2 + 1];

            buttonstate = SDL_JoystickGetHat(Device, i);

            // If we're going to assume that we can pass SDL's value into
            // Joy_GenerateButtonEvents then we might as well assume the format here.
            if(buttonstate & 0x1) // Up
                y.Value = -1.0;
            else if(buttonstate & 0x4) // Down
                y.Value = 1.0;
            else
                y.Value = 0.0;
            if(buttonstate & 0x2) // Left
                x.Value = 1.0;
            else if(buttonstate & 0x8) // Right
                x.Value = -1.0;
            else
                x.Value = 0.0;

            if(i < 4)
            {
                Joy_GenerateButtonEvents(x.ButtonValue, buttonstate, 4, KEY_JOYPOV1_UP + i*4);
                x.ButtonValue = buttonstate;
            }
        }
    }
开发者ID:AkumaKing,项目名称:Xeu,代码行数:60,代码来源:i_joystick.cpp

示例7: sdl_joykey_pressed

static bool sdl_joykey_pressed(sdl_input_t *sdl, int port_num, uint16_t joykey)
{
   if (joykey == NO_BTN)
      return false;

   // Check hat.
   if (GET_HAT_DIR(joykey))
   {
      uint16_t hat = GET_HAT(joykey);
      if (hat >= sdl->num_hats[port_num])
         return false;

      Uint8 dir = SDL_JoystickGetHat(sdl->joysticks[port_num], hat);
      switch (GET_HAT_DIR(joykey))
      {
         case HAT_UP_MASK:
            return dir & SDL_HAT_UP;
         case HAT_DOWN_MASK:
            return dir & SDL_HAT_DOWN;
         case HAT_LEFT_MASK:
            return dir & SDL_HAT_LEFT;
         case HAT_RIGHT_MASK:
            return dir & SDL_HAT_RIGHT;
         default:
            return false;
      }
   }
   else // Check the button
   {
      if (joykey < sdl->num_buttons[port_num] && SDL_JoystickGetButton(sdl->joysticks[port_num], joykey))
         return true;

      return false;
   }
}
开发者ID:damariei,项目名称:RetroArch-Rpi,代码行数:35,代码来源:sdl_input.c

示例8: sdl_pad_get_hat

static uint8_t sdl_pad_get_hat(sdl_joypad_t *pad, unsigned hat)
{
#ifdef HAVE_SDL2
   if (pad->controller)
      return sdl_pad_get_button(pad, hat);
#endif
   return SDL_JoystickGetHat(pad->joypad, hat);
}
开发者ID:DoctorGoat,项目名称:RetroArch_LibNX,代码行数:8,代码来源:sdl_joypad.c

示例9: setup_sdl_joysticks

int setup_sdl_joysticks( void ) {

    int
        i, j, n;

    int
        number_of_joysticks_detected;

    number_of_joysticks_detected = SDL_NumJoysticks();

    if(number_of_joysticks_detected < 1)
        return -1;

    n = 0;

    for(i = 0; i < number_of_joysticks_detected; i++) {

        joystick_devices[ n ].input_device = SDL_JoystickOpen( i );

        if( joystick_devices[ n ].input_device ) {

            joystick_devices[ n ].number_of_buttons = SDL_JoystickNumButtons( joystick_devices[ n ].input_device );
            joystick_devices[ n ].number_of_axes = SDL_JoystickNumAxes( joystick_devices[ n ].input_device );
            joystick_devices[ n ].number_of_hats = SDL_JoystickNumHats( joystick_devices[ n ].input_device );
            
            for(j = 0; j < joystick_devices[ n ].number_of_buttons; j++) {
                joystick_devices[ n ].joystick_last_state.buttons[ j ] = SDL_JoystickGetButton( joystick_devices[ n ].input_device, j );
            }

            for(j = 0; j < joystick_devices[ n ].number_of_axes; j++) {
                joystick_devices[ n ].joystick_last_state.axes[ j ] = SDL_JoystickGetAxis( joystick_devices[ n ].input_device, j );
            }

            for(j = 0; j < joystick_devices[ n ].number_of_hats; j++) {
                joystick_devices[ n ].joystick_last_state.hats[ j ] = SDL_JoystickGetHat( joystick_devices[ n ].input_device, j );
            }
        
            strncpy( joystick_devices[ n ].device_name, SDL_JoystickName( i ), 1023 );
            
            strcpy( joystick_devices[ n ].device_product_name, "Unknown" );

#if DEBUG_MODULE

            debug_log ("Got joystick device %s (SDL device %d, Game device %d)", joystick_devices[ n ].device_name, i, n);

#endif

            n++;
        }
        else {
            debug_log("Unable to open joystick device %d, skipped.", i);
        }
    }

    number_of_joystick_devices = n;

    return 0;
}
开发者ID:Comanche93,项目名称:eech,代码行数:58,代码来源:unix_joystick.c

示例10: get_key_analog_state

    float get_key_analog_state(const int key_code) override {
        LP3_ASSERT(key_code >= 0);
        LP3_ASSERT(key_code < get_key_count());
        if (key_code < this->button_count) {
            return 1 == SDL_JoystickGetButton(joystick, key_code) ? 1.0f : 0.0f;
        } else if (key_code < this->button_count + (this->hat_count * hat_sides)) {
            const int subtracted_kc = key_code - this->button_count;
            const int position_check = subtracted_kc % 4;
            const int hat_code = subtracted_kc / 4;
            Uint8 r = SDL_JoystickGetHat(joystick, hat_code);
            switch(position_check) {
                case 0:
                    if (SDL_HAT_UP == r) {
                        return 1.0f;
                    } else if (SDL_HAT_LEFTUP == r || SDL_HAT_RIGHTUP == r) {
                        return diag_slop;
                    }
                    return 0.0f;
                case 1:
                    if (SDL_HAT_DOWN == r) {
                        return 1.0f;
                    } else if (SDL_HAT_LEFTDOWN == r || SDL_HAT_RIGHTDOWN == r) {
                        return diag_slop;
                    }
                    return 0.0f;
                case 2:
                    if (SDL_HAT_LEFT == r) {
                        return 1.0f;
                    } else if (SDL_HAT_LEFTUP == r || SDL_HAT_LEFTDOWN == r) {
                        return diag_slop;
                    }
                    return 0.0f;
                case 3:
                    if (SDL_HAT_RIGHT == r) {
                        return 1.0f;
                    } else if (SDL_HAT_RIGHTUP == r || SDL_HAT_RIGHTDOWN == r) {
                        return diag_slop;
                    }
                    return 0.0f;
                default:
                    LP3_THROW2(lp3::core::Exception, "Bad case!");
            }
        } else {
            const int subtracted_kc
                = key_code - (button_count + (hat_sides * hat_count));
            const int axis_code = subtracted_kc / axis_sides;

            const Sint16 r = SDL_JoystickGetAxis(joystick, axis_code);
            //LP3_LOG_DEBUG("MARIO, %i is %i", axis_code, r);
            const int position_check = subtracted_kc % axis_sides;
            if (0 == position_check) {
                return lp3::narrow<float>(n_dz_adjust(r)) / -32768.0f;
            } else {
                return lp3::narrow<float>(dz_adjust(r)) / 32767.0f;
            }
        }

    }
开发者ID:TimSimpson,项目名称:Lp3-Engine,代码行数:58,代码来源:SdlJoystick.cpp

示例11: 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));
}
开发者ID:nkreadly07,项目名称:pcsx2,代码行数:9,代码来源:joystick.cpp

示例12: gethatjoystick

//gethatjoystick(i,a) 							: Get the current state of a joystick hat
int gethatjoystick(int index,int hat)
{
    int ret;
    SDL_JoystickUpdate();
    if (SDLjoy[index])
    ret= SDL_JoystickGetHat(SDLjoy[index],hat);
    else
    ret=-1;
    return ret;
}
开发者ID:xquiet,项目名称:sdlbasic,代码行数:11,代码来源:joystick.c

示例13: Java_at_wisch_joystick_Joystick_getPovValueYNative

JNIEXPORT jint JNICALL Java_at_wisch_joystick_Joystick_getPovValueYNative (JNIEnv *, jobject, jint joystickIndex, jint hatIndex){
    int value = SDL_JoystickGetHat(joysticks[joystickIndex], hatIndex);
    if (value & SDL_HAT_DOWN) {
        return at_wisch_joystick_Joystick_POV_AXIS_POSITIVE;
    } else if (value & SDL_HAT_UP) {
        return at_wisch_joystick_Joystick_POV_AXIS_NEGATIVE;
    } else {
        return at_wisch_joystick_Joystick_POV_AXIS_NEUTRAL;
    }
}
开发者ID:nickpenaranda,项目名称:gmdrive,代码行数:10,代码来源:FFJoystick.cpp

示例14: SDL_JoystickUpdate

bool JoystickController::bindJoystickKey(SDL_Joystick *joy, KM_Key &k)
{
    int val=0, dx=0, dy=0;
    //SDL_PumpEvents();
    SDL_JoystickUpdate();

    for(int i=0; i<SDL_JoystickNumBalls(joy);i++)
    {
        dx=0; dy=0;
        SDL_JoystickGetBall(joy, i, &dx, &dy);
        if(dx!=0)
        {
            k.val=dx;
            k.id=i;
            k.type=(int)KeyMapJoyCtrls::JoyBallX;
            return true;
        }else if(dy!=0)
        {
            k.val=dy;
            k.id=i;
            k.type=(int)KeyMapJoyCtrls::JoyBallY;
            return true;
        }
    }

    for(int i=0; i<SDL_JoystickNumHats(joy);i++)
    {
        val=0;
        val=SDL_JoystickGetHat(joy, i);
        if(val!=0)
        {
            k.val=val;
            k.id=i;
            k.type=(int)KeyMapJoyCtrls::JoyHat;
            return true;
        }
    }
    for(int i=0; i<SDL_JoystickNumButtons(joy);i++)
    {
        val=0;
        val=SDL_JoystickGetButton(joy, i);
        if(val==1)
        {
            k.val=val;
            k.id=i;
            k.type=(int)KeyMapJoyCtrls::JoyButton;
            return true;
        }
    }

    k.val=0;
    k.id=0;
    k.type=(int)KeyMapJoyCtrls::NoControl;
    return false;
}
开发者ID:zigurana,项目名称:PGE-Project,代码行数:55,代码来源:controller_joystick.cpp

示例15: getConstant

Joystick::Hat Joystick::getHat(int hatindex) const
{
    Hat h = HAT_INVALID;

    if (!isConnected() || hatindex < 0 || hatindex >= getHatCount())
        return h;

    getConstant(SDL_JoystickGetHat(joyhandle, hatindex), h);

    return h;
}
开发者ID:AntonioModer,项目名称:LoveMore,代码行数:11,代码来源:Joystick.cpp


注:本文中的SDL_JoystickGetHat函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。