Exemplo n.º 1
0
void TeleopNaoJoy::initializePreviousJoystick(const Joy::ConstPtr& joy) {
    if(!m_previousJoystick_initialized) {
        // if no previous joystick message has been received
        // assume all buttons and axes have been zero
        //
        Joy::Ptr pJoy(new Joy());
        pJoy->buttons.resize( joy->buttons.size(), 0);
        pJoy->axes.resize( joy->axes.size(), 0.0);
        m_previousJoystick = pJoy;
        m_previousJoystick_initialized = true;
    }

}
Exemplo n.º 2
0
void 
InputImpl::Init( )
{
    if ( m_initialized )
        return;
    m_initialized = true;

    uint32_t ignoreTypes = Input::Instance().IgnoreTypes();

#ifdef SUPPORT_WIIMOTE
    if ( (ignoreTypes & InputDevice::Wiimote) == 0 )
    {
        Wiimote::FindAll( &m_wiimotes );
    }
#endif

    SDL::Instance().Init( );
    Assert( ::SDL_WasInit( SDL_INIT_VIDEO ) != 0 );

    if ( (ignoreTypes & InputDevice::Keyboard) == 0 )
    {
        m_pKeyboard = shared_ptr< Keyboard >( new Keyboard( "Keyboard" ) );
    }
    if ( (ignoreTypes & InputDevice::Mouse) == 0 )
    {
        m_pMouse = shared_ptr< Mouse >( new Mouse( "Mouse" ) );
    }
    if ( (ignoreTypes & InputDevice::Gamepad) == 0 )
    {
        if ( ::SDL_WasInit( SDL_INIT_JOYSTICK ) == 0 )
        {
            int initRslt = ::SDL_InitSubSystem( SDL_INIT_JOYSTICK );

            if ( initRslt != 0 )
                throw SDLException( "SDL_InitSubSystem( SDL_INIT_JOYSTICK )" );
        }
        int joystickEventState = ::SDL_JoystickEventState( SDL_ENABLE );
        if ( joystickEventState != SDL_ENABLE )
            throw SDLException( "SDL_JoystickEventState" );

        for ( int i = 0; i < ::SDL_NumJoysticks( ); ++i )
        {
            
            shared_ptr< Gamepad > pJoy(
                new Gamepad( ::SDL_JoystickName( i ), i ) );
            m_joysticks.push_back( pJoy );
        }
    }
}