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


C++ Joystick::assignDefaultInputMapping方法代码示例

本文整理汇总了C++中Joystick::assignDefaultInputMapping方法的典型用法代码示例。如果您正苦于以下问题:C++ Joystick::assignDefaultInputMapping方法的具体用法?C++ Joystick::assignDefaultInputMapping怎么用?C++ Joystick::assignDefaultInputMapping使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Joystick的用法示例。


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

示例1: joystickAdded

void SDL2Manager::init() {
#ifdef HAVE_SDL2
    bool initSuccess = (SDL_Init(SDL_INIT_GAMECONTROLLER) == 0);

    if (initSuccess) {
        int joystickCount = SDL_NumJoysticks();

        for (int i = 0; i < joystickCount; i++) {
            SDL_GameController* controller = SDL_GameControllerOpen(i);

            if (controller) {
                SDL_JoystickID id = getInstanceId(controller);
                if (!_openJoysticks.contains(id)) {
                    Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller);
                    _openJoysticks[id] = joystick;
                    auto userInputMapper = DependencyManager::get<UserInputMapper>();
                    joystick->registerToUserInputMapper(*userInputMapper);
                    joystick->assignDefaultInputMapping(*userInputMapper);
                    emit joystickAdded(joystick);
                }
            }
        }

        _isInitialized = true;
    }
    else {
        qDebug() << "Error initializing SDL2 Manager";
    }
#endif
}
开发者ID:bwent,项目名称:hifi,代码行数:30,代码来源:SDL2Manager.cpp

示例2: perfTimer

void SDL2Manager::pluginUpdate(float deltaTime, bool jointsCaptured) {
#ifdef HAVE_SDL2
    if (_isInitialized) {
        auto userInputMapper = DependencyManager::get<UserInputMapper>();
        for (auto joystick : _openJoysticks) {
            joystick->update(deltaTime, jointsCaptured);
        }
        
        PerformanceTimer perfTimer("SDL2Manager::update");
        SDL_GameControllerUpdate();
        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_CONTROLLERAXISMOTION) {
                Joystick* joystick = _openJoysticks[event.caxis.which];
                if (joystick) {
                    joystick->handleAxisEvent(event.caxis);
                }
            } else if (event.type == SDL_CONTROLLERBUTTONDOWN || event.type == SDL_CONTROLLERBUTTONUP) {
                Joystick* joystick = _openJoysticks[event.cbutton.which];
                if (joystick) {
                    joystick->handleButtonEvent(event.cbutton);
                }
                
                if (event.cbutton.button == SDL_CONTROLLER_BUTTON_BACK) {
                    // this will either start or stop a global back event
                    QEvent::Type backType = (event.type == SDL_CONTROLLERBUTTONDOWN)
                    ? HFBackEvent::startType()
                    : HFBackEvent::endType();
                    HFBackEvent backEvent(backType);
                    
                    qApp->sendEvent(qApp, &backEvent);
                }
                
            } else if (event.type == SDL_CONTROLLERDEVICEADDED) {
                SDL_GameController* controller = SDL_GameControllerOpen(event.cdevice.which);
                
                SDL_JoystickID id = getInstanceId(controller);
                if (!_openJoysticks.contains(id)) {
                    Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller);
                    _openJoysticks[id] = joystick;
                    joystick->registerToUserInputMapper(*userInputMapper);
                    joystick->assignDefaultInputMapping(*userInputMapper);
                    emit joystickAdded(joystick);
                }
            } else if (event.type == SDL_CONTROLLERDEVICEREMOVED) {
                Joystick* joystick = _openJoysticks[event.cdevice.which];
                _openJoysticks.remove(event.cdevice.which);
                userInputMapper->removeDevice(joystick->getDeviceID());
                emit joystickRemoved(joystick);
            }
        }
    }
#endif
}
开发者ID:bwent,项目名称:hifi,代码行数:54,代码来源:SDL2Manager.cpp


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