mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-28 23:06:41 +00:00
Enable controller gyro and capture the values
This commit is contained in:
parent
9d0e427ec1
commit
55f95f1ea3
2 changed files with 36 additions and 0 deletions
|
@ -4,6 +4,8 @@
|
|||
#include <MyGUI_InputManager.h>
|
||||
#include <MyGUI_Widget.h>
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#include <components/debug/debuglog.hpp>
|
||||
#include <components/sdlutil/sdlmappings.hpp>
|
||||
|
||||
|
@ -31,6 +33,7 @@ namespace MWInput
|
|||
: mBindingsManager(bindingsManager)
|
||||
, mActionManager(actionManager)
|
||||
, mMouseManager(mouseManager)
|
||||
, mGyroAvailable(false)
|
||||
, mJoystickEnabled (Settings::Manager::getBool("enable controller", "Input"))
|
||||
, mGamepadCursorSpeed(Settings::Manager::getFloat("gamepad cursor speed", "Input"))
|
||||
, mSneakToggleShortcutTimer(0.f)
|
||||
|
@ -287,6 +290,7 @@ namespace MWInput
|
|||
void ControllerManager::controllerAdded(int deviceID, const SDL_ControllerDeviceEvent &arg)
|
||||
{
|
||||
mBindingsManager->controllerAdded(deviceID, arg);
|
||||
enableGyroSensor();
|
||||
}
|
||||
|
||||
void ControllerManager::controllerRemoved(const SDL_ControllerDeviceEvent &arg)
|
||||
|
@ -399,4 +403,30 @@ namespace MWInput
|
|||
return false;
|
||||
}
|
||||
|
||||
void ControllerManager::enableGyroSensor()
|
||||
{
|
||||
mGyroAvailable = false;
|
||||
SDL_GameController* cntrl = mBindingsManager->getControllerOrNull();
|
||||
if (!cntrl)
|
||||
return;
|
||||
if (!SDL_GameControllerHasSensor(cntrl, SDL_SENSOR_GYRO))
|
||||
return;
|
||||
if (SDL_GameControllerSetSensorEnabled(cntrl, SDL_SENSOR_GYRO, SDL_TRUE) < 0)
|
||||
return;
|
||||
mGyroAvailable = true;
|
||||
}
|
||||
|
||||
bool ControllerManager::isGyroAvailable() const
|
||||
{
|
||||
return mGyroAvailable;
|
||||
}
|
||||
|
||||
std::array<float, 3> ControllerManager::getGyroValues() const
|
||||
{
|
||||
float gyro[3] = { 0.f };
|
||||
SDL_GameController* cntrl = mBindingsManager->getControllerOrNull();
|
||||
if (cntrl && mGyroAvailable)
|
||||
SDL_GameControllerGetSensorData(cntrl, SDL_SENSOR_GYRO, gyro, 3);
|
||||
return std::array<float, 3>({gyro[0], gyro[1], gyro[2]});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,16 +44,22 @@ namespace MWInput
|
|||
float getAxisValue(SDL_GameControllerAxis axis) const; // returns value in range [-1, 1]
|
||||
bool isButtonPressed(SDL_GameControllerButton button) const;
|
||||
|
||||
bool isGyroAvailable() const;
|
||||
std::array<float, 3> getGyroValues() const;
|
||||
|
||||
private:
|
||||
// Return true if GUI consumes input.
|
||||
bool gamepadToGuiControl(const SDL_ControllerButtonEvent &arg);
|
||||
bool gamepadToGuiControl(const SDL_ControllerAxisEvent &arg);
|
||||
|
||||
void enableGyroSensor();
|
||||
|
||||
BindingsManager* mBindingsManager;
|
||||
ActionManager* mActionManager;
|
||||
MouseManager* mMouseManager;
|
||||
|
||||
bool mJoystickEnabled;
|
||||
bool mGyroAvailable;
|
||||
float mGamepadCursorSpeed;
|
||||
float mSneakToggleShortcutTimer;
|
||||
bool mGamepadGuiCursorEnabled;
|
||||
|
|
Loading…
Reference in a new issue