From 55f95f1ea31818c574628a93ba66a1c9e461408a Mon Sep 17 00:00:00 2001 From: uramer Date: Tue, 18 Jan 2022 20:07:02 +0100 Subject: [PATCH 1/9] Enable controller gyro and capture the values --- apps/openmw/mwinput/controllermanager.cpp | 30 +++++++++++++++++++++++ apps/openmw/mwinput/controllermanager.hpp | 6 +++++ 2 files changed, 36 insertions(+) diff --git a/apps/openmw/mwinput/controllermanager.cpp b/apps/openmw/mwinput/controllermanager.cpp index 1e72a1c95b..5b37686c7d 100644 --- a/apps/openmw/mwinput/controllermanager.cpp +++ b/apps/openmw/mwinput/controllermanager.cpp @@ -4,6 +4,8 @@ #include #include +#include + #include #include @@ -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 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({gyro[0], gyro[1], gyro[2]}); + } } diff --git a/apps/openmw/mwinput/controllermanager.hpp b/apps/openmw/mwinput/controllermanager.hpp index 948b48d538..8df6ee5c9f 100644 --- a/apps/openmw/mwinput/controllermanager.hpp +++ b/apps/openmw/mwinput/controllermanager.hpp @@ -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 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; From 9fa0faf94453381039fde917877dcb245e30bdc7 Mon Sep 17 00:00:00 2001 From: uramer Date: Tue, 18 Jan 2022 21:10:35 +0100 Subject: [PATCH 2/9] Refactor sensor manager to match controller manager gyro API --- apps/openmw/mwinput/sensormanager.cpp | 45 ++++++++++++++++----------- apps/openmw/mwinput/sensormanager.hpp | 8 +++-- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/apps/openmw/mwinput/sensormanager.cpp b/apps/openmw/mwinput/sensormanager.cpp index 3e8e70aefe..601924fa16 100644 --- a/apps/openmw/mwinput/sensormanager.cpp +++ b/apps/openmw/mwinput/sensormanager.cpp @@ -13,8 +13,7 @@ namespace MWInput SensorManager::SensorManager() : mInvertX(Settings::Manager::getBool("invert x axis", "Input")) , mInvertY(Settings::Manager::getBool("invert y axis", "Input")) - , mGyroXSpeed(0.f) - , mGyroYSpeed(0.f) + , mGyroValues() , mGyroUpdateTimer(0.f) , mGyroHSensitivity(Settings::Manager::getFloat("gyro horizontal sensitivity", "Input")) , mGyroVSensitivity(Settings::Manager::getFloat("gyro vertical sensitivity", "Input")) @@ -119,7 +118,6 @@ namespace MWInput { SDL_SensorClose(mGyroscope); mGyroscope = nullptr; - mGyroXSpeed = mGyroYSpeed = 0.f; mGyroUpdateTimer = 0.f; } @@ -141,7 +139,6 @@ namespace MWInput { SDL_SensorClose(mGyroscope); mGyroscope = nullptr; - mGyroXSpeed = mGyroYSpeed = 0.f; mGyroUpdateTimer = 0.f; } } @@ -177,18 +174,18 @@ namespace MWInput } } - float SensorManager::getGyroAxisSpeed(GyroscopeAxis axis, const SDL_SensorEvent &arg) const + float SensorManager::getGyroAxisSpeed(GyroscopeAxis axis) const { switch (axis) { case GyroscopeAxis::X: case GyroscopeAxis::Y: case GyroscopeAxis::Z: - return std::abs(arg.data[0]) >= mGyroInputThreshold ? arg.data[axis-1] : 0.f; + return std::abs(mGyroValues[0]) >= mGyroInputThreshold ? mGyroValues[axis - 1] : 0.f; case GyroscopeAxis::Minus_X: case GyroscopeAxis::Minus_Y: case GyroscopeAxis::Minus_Z: - return std::abs(arg.data[0]) >= mGyroInputThreshold ? -arg.data[std::abs(axis)-1] : 0.f; + return std::abs(mGyroValues[0]) >= mGyroInputThreshold ? -mGyroValues[std::abs(axis) - 1] : 0.f; default: return 0.f; } @@ -217,8 +214,9 @@ namespace MWInput break; case SDL_SENSOR_GYRO: { - mGyroXSpeed = getGyroAxisSpeed(mGyroHAxis, arg); - mGyroYSpeed = getGyroAxisSpeed(mGyroVAxis, arg); + mGyroValues[0] = arg.data[0]; + mGyroValues[1] = arg.data[1]; + mGyroValues[2] = arg.data[2]; mGyroUpdateTimer = 0.f; break; @@ -230,28 +228,29 @@ namespace MWInput void SensorManager::update(float dt) { - if (mGyroXSpeed == 0.f && mGyroYSpeed == 0.f) - return; - + mGyroUpdateTimer += dt; if (mGyroUpdateTimer > 0.5f) { // More than half of second passed since the last gyroscope update. // A device more likely was disconnected or switched to the sleep mode. // Reset current rotation speed and wait for update. - mGyroXSpeed = 0.f; - mGyroYSpeed = 0.f; + mGyroValues = { 0, 0, 0 }; mGyroUpdateTimer = 0.f; return; } - mGyroUpdateTimer += dt; - if (!mGuiCursorEnabled) { + float gyroH = getGyroAxisSpeed(mGyroHAxis); + float gyroV = getGyroAxisSpeed(mGyroVAxis); + + if (gyroH == 0 && gyroV == 0) + return; + float rot[3]; - rot[0] = -mGyroYSpeed * dt * mGyroVSensitivity * 4 * (mInvertY ? -1 : 1); + rot[0] = -gyroV * dt * mGyroVSensitivity * 4 * (mInvertY ? -1 : 1); rot[1] = 0.0f; - rot[2] = -mGyroXSpeed * dt * mGyroHSensitivity * 4 * (mInvertX ? -1 : 1); + rot[2] = -gyroH * dt * mGyroHSensitivity * 4 * (mInvertX ? -1 : 1); // Only actually turn player when we're not in vanity mode bool playerLooking = MWBase::Environment::get().getInputManager()->getControlSwitch("playerlooking"); @@ -267,4 +266,14 @@ namespace MWInput MWBase::Environment::get().getInputManager()->resetIdleTime(); } } + + bool SensorManager::isGyroAvailable() const + { + return mGyroscope != nullptr; + } + + std::array SensorManager::getGyroValues() const + { + return mGyroValues; + } } diff --git a/apps/openmw/mwinput/sensormanager.hpp b/apps/openmw/mwinput/sensormanager.hpp index 75472d43b4..e096a89260 100644 --- a/apps/openmw/mwinput/sensormanager.hpp +++ b/apps/openmw/mwinput/sensormanager.hpp @@ -35,6 +35,9 @@ namespace MWInput void setGuiCursorEnabled(bool enabled) { mGuiCursorEnabled = enabled; } + bool isGyroAvailable() const; + std::array getGyroValues() const; + private: enum GyroscopeAxis { @@ -50,13 +53,12 @@ namespace MWInput void updateSensors(); void correctGyroscopeAxes(); GyroscopeAxis mapGyroscopeAxis(const std::string& axis); - float getGyroAxisSpeed(GyroscopeAxis axis, const SDL_SensorEvent &arg) const; + float getGyroAxisSpeed(GyroscopeAxis axis) const; bool mInvertX; bool mInvertY; - float mGyroXSpeed; - float mGyroYSpeed; + std::array mGyroValues; float mGyroUpdateTimer; float mGyroHSensitivity; From a496f16cdb6939df27949da07c1fa8b1cd40f320 Mon Sep 17 00:00:00 2001 From: uramer Date: Tue, 18 Jan 2022 22:47:49 +0100 Subject: [PATCH 3/9] Implement gyro camera for controllers --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwinput/gyroaxis.cpp | 22 ++++++ apps/openmw/mwinput/gyroaxis.hpp | 22 ++++++ apps/openmw/mwinput/gyromanager.cpp | 95 +++++++++++++++++++++++++ apps/openmw/mwinput/gyromanager.hpp | 38 ++++++++++ apps/openmw/mwinput/inputmanagerimp.cpp | 18 +++++ apps/openmw/mwinput/inputmanagerimp.hpp | 2 + apps/openmw/mwinput/sensormanager.cpp | 89 +---------------------- apps/openmw/mwinput/sensormanager.hpp | 20 +----- 9 files changed, 203 insertions(+), 105 deletions(-) create mode 100644 apps/openmw/mwinput/gyroaxis.cpp create mode 100644 apps/openmw/mwinput/gyroaxis.hpp create mode 100644 apps/openmw/mwinput/gyromanager.cpp create mode 100644 apps/openmw/mwinput/gyromanager.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index ea1d48885c..79cb6f30bd 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -27,7 +27,7 @@ add_openmw_dir (mwrender add_openmw_dir (mwinput actions actionmanager bindingsmanager controllermanager controlswitch - inputmanagerimp mousemanager keyboardmanager sensormanager + inputmanagerimp mousemanager keyboardmanager gyroaxis sensormanager gyromanager ) add_openmw_dir (mwgui diff --git a/apps/openmw/mwinput/gyroaxis.cpp b/apps/openmw/mwinput/gyroaxis.cpp new file mode 100644 index 0000000000..3eb71fb30b --- /dev/null +++ b/apps/openmw/mwinput/gyroaxis.cpp @@ -0,0 +1,22 @@ +#include "gyroaxis.hpp" + +namespace MWInput +{ + GyroscopeAxis gyroscopeAxisFromString(std::string_view s) + { + if (s == "x") + return GyroscopeAxis::X; + else if (s == "y") + return GyroscopeAxis::Y; + else if (s == "z") + return GyroscopeAxis::Z; + else if (s == "-x") + return GyroscopeAxis::Minus_X; + else if (s == "-y") + return GyroscopeAxis::Minus_Y; + else if (s == "-z") + return GyroscopeAxis::Minus_Z; + + return GyroscopeAxis::Unknown; + } +} diff --git a/apps/openmw/mwinput/gyroaxis.hpp b/apps/openmw/mwinput/gyroaxis.hpp new file mode 100644 index 0000000000..542217351d --- /dev/null +++ b/apps/openmw/mwinput/gyroaxis.hpp @@ -0,0 +1,22 @@ +#ifndef MWINPUT_GYROAXIS +#define MWINPUT_GYROAXIS + +#include + +namespace MWInput +{ + enum GyroscopeAxis + { + Unknown = 0, + X = 1, + Y = 2, + Z = 3, + Minus_X = -1, + Minus_Y = -2, + Minus_Z = -3 + }; + + GyroscopeAxis gyroscopeAxisFromString(std::string_view s); +} + +#endif // !MWINPUT_GYROAXIS diff --git a/apps/openmw/mwinput/gyromanager.cpp b/apps/openmw/mwinput/gyromanager.cpp new file mode 100644 index 0000000000..5a2b532186 --- /dev/null +++ b/apps/openmw/mwinput/gyromanager.cpp @@ -0,0 +1,95 @@ +#include "gyromanager.hpp" + +#include "../mwbase/inputmanager.hpp" +#include "../mwbase/environment.hpp" +#include "../mwbase/world.hpp" +#include "../mwworld/player.hpp" + +namespace MWInput +{ + GyroManager::GyroManager() + : mEnabled(Settings::Manager::getBool("enable gyroscope", "Input")) + , mGuiCursorEnabled(true) + , mSensitivityH(Settings::Manager::getFloat("gyro horizontal sensitivity", "Input")) + , mSensitivityV(Settings::Manager::getFloat("gyro vertical sensitivity", "Input")) + , mInvertH(Settings::Manager::getBool("invert x axis", "Input")) + , mInvertV(Settings::Manager::getBool("invert y axis", "Input")) + , mInputThreshold(Settings::Manager::getFloat("gyro input threshold", "Input")) + , mAxisH(gyroscopeAxisFromString(Settings::Manager::getString("gyro horizontal axis", "Input"))) + , mAxisV(gyroscopeAxisFromString(Settings::Manager::getString("gyro vertical axis", "Input"))) + {}; + + void GyroManager::update(float dt, std::array values) const + { + if (!mGuiCursorEnabled) + { + float gyroH = getAxisValue(mAxisH, values); + float gyroV = getAxisValue(mAxisV, values); + + if (gyroH == 0 && gyroV == 0) + return; + + float rot[3]; + rot[0] = -gyroV * dt * mSensitivityV * 4 * (mInvertV ? -1 : 1); + rot[1] = 0.0f; + rot[2] = -gyroH * dt * mSensitivityH * 4 * (mInvertH ? -1 : 1); + + // Only actually turn player when we're not in vanity mode + bool playerLooking = MWBase::Environment::get().getInputManager()->getControlSwitch("playerlooking"); + if (!MWBase::Environment::get().getWorld()->vanityRotateCamera(rot) && playerLooking) + { + MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer(); + player.yaw(-rot[2]); + player.pitch(-rot[0]); + } + else if (!playerLooking) + MWBase::Environment::get().getWorld()->disableDeferredPreviewRotation(); + + MWBase::Environment::get().getInputManager()->resetIdleTime(); + } + } + + void GyroManager::processChangedSettings(const Settings::CategorySettingVector& changed) + { + for (const auto& setting : changed) + { + if (setting.first != "Input") + continue; + + if (setting.second == "enable gyroscope") + mEnabled = Settings::Manager::getBool("enable gyroscope", "Input"); + else if (setting.second == "gyro horizontal sensitivity") + mSensitivityH = Settings::Manager::getFloat("gyro horizontal sensitivity", "Input"); + else if (setting.second == "gyro vertical sensitivity") + mSensitivityV = Settings::Manager::getFloat("gyro vertical sensitivity", "Input"); + else if (setting.second == "invert x axis") + mInvertH = Settings::Manager::getBool("invert x axis", "Input"); + else if (setting.second == "invert y axis") + mInvertV = Settings::Manager::getBool("invert y axis", "Input"); + else if (setting.second == "gyro input threshold") + mInputThreshold = Settings::Manager::getFloat("gyro input threshold", "Input"); + else if (setting.second == "gyro horizontal axis") + mAxisH = gyroscopeAxisFromString(Settings::Manager::getString("gyro horizontal axis", "Input")); + else if (setting.second == "gyro vertical axis") + mAxisV = gyroscopeAxisFromString(Settings::Manager::getString("gyro vertical axis", "Input")); + } + } + + namespace + { + int signum(int x) + { + return 0 < x - x < 0; + } + } + + float GyroManager::getAxisValue(GyroscopeAxis axis, std::array values) const + { + if (axis == GyroscopeAxis::Unknown) + return 0; + float value = values[std::abs(axis) - 1] * signum(axis); + //if (std::abs(value) <= mInputThreshold) + // value = 0; + return value; + } +} diff --git a/apps/openmw/mwinput/gyromanager.hpp b/apps/openmw/mwinput/gyromanager.hpp new file mode 100644 index 0000000000..2c4a13905f --- /dev/null +++ b/apps/openmw/mwinput/gyromanager.hpp @@ -0,0 +1,38 @@ +#ifndef MWINPUT_GYROMANAGER +#define MWINPUT_GYROMANAGER + +#include + +#include "gyroaxis.hpp" + +namespace MWInput +{ + class GyroManager + { + public: + GyroManager(); + + bool isEnabled() const { return mEnabled; } + + void update(float dt, std::array values) const; + + void processChangedSettings(const Settings::CategorySettingVector& changed); + + void setGuiCursorEnabled(bool enabled) { mGuiCursorEnabled = enabled; } + + private: + bool mEnabled; + bool mGuiCursorEnabled; + float mSensitivityH; + float mSensitivityV; + bool mInvertH; + bool mInvertV; + float mInputThreshold; + GyroscopeAxis mAxisH; + GyroscopeAxis mAxisV; + + float getAxisValue(GyroscopeAxis axis, std::array values) const; + }; +} + +#endif // !MWINPUT_GYROMANAGER diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index 4ebe56bf94..8beead5803 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -19,6 +19,7 @@ #include "keyboardmanager.hpp" #include "mousemanager.hpp" #include "sensormanager.hpp" +#include "gyromanager.hpp" namespace MWInput { @@ -51,6 +52,8 @@ namespace MWInput mSensorManager = new SensorManager(); mInputWrapper->setSensorEventCallback(mSensorManager); + + mGyroManager = new GyroManager(); } void InputManager::clear() @@ -72,6 +75,8 @@ namespace MWInput delete mBindingsManager; delete mInputWrapper; + + delete mGyroManager; } void InputManager::setAttemptJump(bool jumping) @@ -100,6 +105,17 @@ namespace MWInput mMouseManager->update(dt); mSensorManager->update(dt); mActionManager->update(dt, controllerMove); + + if (mGyroManager->isEnabled()) + { + bool controllerAvailable = mControllerManager->isGyroAvailable(); + bool sensorAvailable = mSensorManager->isGyroAvailable(); + if (controllerAvailable || sensorAvailable) + { + mGyroManager->update(dt, + controllerAvailable ? mControllerManager->getGyroValues() : mSensorManager->getGyroValues()); + } + } } void InputManager::setDragDrop(bool dragDrop) @@ -117,6 +133,7 @@ namespace MWInput mControllerManager->setGuiCursorEnabled(guiMode); mMouseManager->setGuiCursorEnabled(guiMode); mSensorManager->setGuiCursorEnabled(guiMode); + mGyroManager->setGuiCursorEnabled(guiMode); mMouseManager->setMouseLookEnabled(!guiMode); if (guiMode) MWBase::Environment::get().getWindowManager()->showCrosshair(false); @@ -130,6 +147,7 @@ namespace MWInput { mMouseManager->processChangedSettings(changed); mSensorManager->processChangedSettings(changed); + mGyroManager->processChangedSettings(changed); } bool InputManager::getControlSwitch(std::string_view sw) diff --git a/apps/openmw/mwinput/inputmanagerimp.hpp b/apps/openmw/mwinput/inputmanagerimp.hpp index 41478d5dcb..3f9f1b3be1 100644 --- a/apps/openmw/mwinput/inputmanagerimp.hpp +++ b/apps/openmw/mwinput/inputmanagerimp.hpp @@ -39,6 +39,7 @@ namespace MWInput class KeyboardManager; class MouseManager; class SensorManager; + class GyroManager; /** * @brief Class that provides a high-level API for game input @@ -128,6 +129,7 @@ namespace MWInput KeyboardManager* mKeyboardManager; MouseManager* mMouseManager; SensorManager* mSensorManager; + GyroManager* mGyroManager; }; } #endif diff --git a/apps/openmw/mwinput/sensormanager.cpp b/apps/openmw/mwinput/sensormanager.cpp index 601924fa16..fed25b88ce 100644 --- a/apps/openmw/mwinput/sensormanager.cpp +++ b/apps/openmw/mwinput/sensormanager.cpp @@ -11,15 +11,10 @@ namespace MWInput { SensorManager::SensorManager() - : mInvertX(Settings::Manager::getBool("invert x axis", "Input")) - , mInvertY(Settings::Manager::getBool("invert y axis", "Input")) - , mGyroValues() + : mGyroValues() , mGyroUpdateTimer(0.f) - , mGyroHSensitivity(Settings::Manager::getFloat("gyro horizontal sensitivity", "Input")) - , mGyroVSensitivity(Settings::Manager::getFloat("gyro vertical sensitivity", "Input")) , mGyroHAxis(GyroscopeAxis::Minus_X) , mGyroVAxis(GyroscopeAxis::Y) - , mGyroInputThreshold(Settings::Manager::getFloat("gyro input threshold", "Input")) , mGyroscope(nullptr) , mGuiCursorEnabled(true) { @@ -41,24 +36,6 @@ namespace MWInput } } - SensorManager::GyroscopeAxis SensorManager::mapGyroscopeAxis(const std::string& axis) - { - if (axis == "x") - return GyroscopeAxis::X; - else if (axis == "y") - return GyroscopeAxis::Y; - else if (axis == "z") - return GyroscopeAxis::Z; - else if (axis == "-x") - return GyroscopeAxis::Minus_X; - else if (axis == "-y") - return GyroscopeAxis::Minus_Y; - else if (axis == "-z") - return GyroscopeAxis::Minus_Z; - - return GyroscopeAxis::Unknown; - } - void SensorManager::correctGyroscopeAxes() { if (!Settings::Manager::getBool("enable gyroscope", "Input")) @@ -67,8 +44,8 @@ namespace MWInput // Treat setting from config as axes for landscape mode. // If the device does not support orientation change, do nothing. // Note: in is unclear how to correct axes for devices with non-standart Z axis direction. - mGyroHAxis = mapGyroscopeAxis(Settings::Manager::getString("gyro horizontal axis", "Input")); - mGyroVAxis = mapGyroscopeAxis(Settings::Manager::getString("gyro vertical axis", "Input")); + mGyroHAxis = gyroscopeAxisFromString(Settings::Manager::getString("gyro horizontal axis", "Input")); + mGyroVAxis = gyroscopeAxisFromString(Settings::Manager::getString("gyro vertical axis", "Input")); SDL_DisplayOrientation currentOrientation = SDL_GetDisplayOrientation(Settings::Manager::getInt("screen", "Video")); switch (currentOrientation) @@ -148,18 +125,6 @@ namespace MWInput { for (const auto& setting : changed) { - if (setting.first == "Input" && setting.second == "invert x axis") - mInvertX = Settings::Manager::getBool("invert x axis", "Input"); - - if (setting.first == "Input" && setting.second == "invert y axis") - mInvertY = Settings::Manager::getBool("invert y axis", "Input"); - - if (setting.first == "Input" && setting.second == "gyro horizontal sensitivity") - mGyroHSensitivity = Settings::Manager::getFloat("gyro horizontal sensitivity", "Input"); - - if (setting.first == "Input" && setting.second == "gyro vertical sensitivity") - mGyroVSensitivity = Settings::Manager::getFloat("gyro vertical sensitivity", "Input"); - if (setting.first == "Input" && setting.second == "enable gyroscope") init(); @@ -168,26 +133,6 @@ namespace MWInput if (setting.first == "Input" && setting.second == "gyro vertical axis") correctGyroscopeAxes(); - - if (setting.first == "Input" && setting.second == "gyro input threshold") - mGyroInputThreshold = Settings::Manager::getFloat("gyro input threshold", "Input"); - } - } - - float SensorManager::getGyroAxisSpeed(GyroscopeAxis axis) const - { - switch (axis) - { - case GyroscopeAxis::X: - case GyroscopeAxis::Y: - case GyroscopeAxis::Z: - return std::abs(mGyroValues[0]) >= mGyroInputThreshold ? mGyroValues[axis - 1] : 0.f; - case GyroscopeAxis::Minus_X: - case GyroscopeAxis::Minus_Y: - case GyroscopeAxis::Minus_Z: - return std::abs(mGyroValues[0]) >= mGyroInputThreshold ? -mGyroValues[std::abs(axis) - 1] : 0.f; - default: - return 0.f; } } @@ -236,34 +181,6 @@ namespace MWInput // Reset current rotation speed and wait for update. mGyroValues = { 0, 0, 0 }; mGyroUpdateTimer = 0.f; - return; - } - - if (!mGuiCursorEnabled) - { - float gyroH = getGyroAxisSpeed(mGyroHAxis); - float gyroV = getGyroAxisSpeed(mGyroVAxis); - - if (gyroH == 0 && gyroV == 0) - return; - - float rot[3]; - rot[0] = -gyroV * dt * mGyroVSensitivity * 4 * (mInvertY ? -1 : 1); - rot[1] = 0.0f; - rot[2] = -gyroH * dt * mGyroHSensitivity * 4 * (mInvertX ? -1 : 1); - - // Only actually turn player when we're not in vanity mode - bool playerLooking = MWBase::Environment::get().getInputManager()->getControlSwitch("playerlooking"); - if (!MWBase::Environment::get().getWorld()->vanityRotateCamera(rot) && playerLooking) - { - MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer(); - player.yaw(-rot[2]); - player.pitch(-rot[0]); - } - else if (!playerLooking) - MWBase::Environment::get().getWorld()->disableDeferredPreviewRotation(); - - MWBase::Environment::get().getInputManager()->resetIdleTime(); } } diff --git a/apps/openmw/mwinput/sensormanager.hpp b/apps/openmw/mwinput/sensormanager.hpp index e096a89260..92d0a036e8 100644 --- a/apps/openmw/mwinput/sensormanager.hpp +++ b/apps/openmw/mwinput/sensormanager.hpp @@ -6,6 +6,8 @@ #include #include +#include "gyroaxis.hpp" + namespace SDLUtil { class InputWrapper; @@ -39,33 +41,15 @@ namespace MWInput std::array getGyroValues() const; private: - enum GyroscopeAxis - { - Unknown = 0, - X = 1, - Y = 2, - Z = 3, - Minus_X = -1, - Minus_Y = -2, - Minus_Z = -3 - }; void updateSensors(); void correctGyroscopeAxes(); - GyroscopeAxis mapGyroscopeAxis(const std::string& axis); - float getGyroAxisSpeed(GyroscopeAxis axis) const; - - bool mInvertX; - bool mInvertY; std::array mGyroValues; float mGyroUpdateTimer; - float mGyroHSensitivity; - float mGyroVSensitivity; GyroscopeAxis mGyroHAxis; GyroscopeAxis mGyroVAxis; - float mGyroInputThreshold; SDL_Sensor* mGyroscope; From 4021d23cff2cd6b0dba7693c953d1b9c4f78e38c Mon Sep 17 00:00:00 2001 From: uramer Date: Wed, 19 Jan 2022 17:01:43 +0100 Subject: [PATCH 4/9] Refactor sensor manager axis correction --- apps/openmw/mwinput/controllermanager.cpp | 2 +- apps/openmw/mwinput/gyromanager.cpp | 28 ++++---------- apps/openmw/mwinput/gyromanager.hpp | 2 - apps/openmw/mwinput/sensormanager.cpp | 45 ++++++++--------------- apps/openmw/mwinput/sensormanager.hpp | 11 +++--- files/settings-default.cfg | 2 +- 6 files changed, 31 insertions(+), 59 deletions(-) diff --git a/apps/openmw/mwinput/controllermanager.cpp b/apps/openmw/mwinput/controllermanager.cpp index 5b37686c7d..8753344373 100644 --- a/apps/openmw/mwinput/controllermanager.cpp +++ b/apps/openmw/mwinput/controllermanager.cpp @@ -33,8 +33,8 @@ namespace MWInput : mBindingsManager(bindingsManager) , mActionManager(actionManager) , mMouseManager(mouseManager) - , mGyroAvailable(false) , mJoystickEnabled (Settings::Manager::getBool("enable controller", "Input")) + , mGyroAvailable(false) , mGamepadCursorSpeed(Settings::Manager::getFloat("gamepad cursor speed", "Input")) , mSneakToggleShortcutTimer(0.f) , mGamepadGuiCursorEnabled(true) diff --git a/apps/openmw/mwinput/gyromanager.cpp b/apps/openmw/mwinput/gyromanager.cpp index 5a2b532186..f590abf45c 100644 --- a/apps/openmw/mwinput/gyromanager.cpp +++ b/apps/openmw/mwinput/gyromanager.cpp @@ -12,8 +12,6 @@ namespace MWInput , mGuiCursorEnabled(true) , mSensitivityH(Settings::Manager::getFloat("gyro horizontal sensitivity", "Input")) , mSensitivityV(Settings::Manager::getFloat("gyro vertical sensitivity", "Input")) - , mInvertH(Settings::Manager::getBool("invert x axis", "Input")) - , mInvertV(Settings::Manager::getBool("invert y axis", "Input")) , mInputThreshold(Settings::Manager::getFloat("gyro input threshold", "Input")) , mAxisH(gyroscopeAxisFromString(Settings::Manager::getString("gyro horizontal axis", "Input"))) , mAxisV(gyroscopeAxisFromString(Settings::Manager::getString("gyro vertical axis", "Input"))) @@ -26,13 +24,13 @@ namespace MWInput float gyroH = getAxisValue(mAxisH, values); float gyroV = getAxisValue(mAxisV, values); - if (gyroH == 0 && gyroV == 0) + if (gyroH == 0.f && gyroV == 0.f) return; float rot[3]; - rot[0] = -gyroV * dt * mSensitivityV * 4 * (mInvertV ? -1 : 1); + rot[0] = -gyroV * dt * mSensitivityV; rot[1] = 0.0f; - rot[2] = -gyroH * dt * mSensitivityH * 4 * (mInvertH ? -1 : 1); + rot[2] = -gyroH * dt * mSensitivityH; // Only actually turn player when we're not in vanity mode bool playerLooking = MWBase::Environment::get().getInputManager()->getControlSwitch("playerlooking"); @@ -62,10 +60,6 @@ namespace MWInput mSensitivityH = Settings::Manager::getFloat("gyro horizontal sensitivity", "Input"); else if (setting.second == "gyro vertical sensitivity") mSensitivityV = Settings::Manager::getFloat("gyro vertical sensitivity", "Input"); - else if (setting.second == "invert x axis") - mInvertH = Settings::Manager::getBool("invert x axis", "Input"); - else if (setting.second == "invert y axis") - mInvertV = Settings::Manager::getBool("invert y axis", "Input"); else if (setting.second == "gyro input threshold") mInputThreshold = Settings::Manager::getFloat("gyro input threshold", "Input"); else if (setting.second == "gyro horizontal axis") @@ -75,21 +69,15 @@ namespace MWInput } } - namespace - { - int signum(int x) - { - return 0 < x - x < 0; - } - } - float GyroManager::getAxisValue(GyroscopeAxis axis, std::array values) const { if (axis == GyroscopeAxis::Unknown) return 0; - float value = values[std::abs(axis) - 1] * signum(axis); - //if (std::abs(value) <= mInputThreshold) - // value = 0; + float value = values[std::abs(axis) - 1]; + if (axis < 0) + value *= -1; + if (std::abs(value) <= mInputThreshold) + value = 0; return value; } } diff --git a/apps/openmw/mwinput/gyromanager.hpp b/apps/openmw/mwinput/gyromanager.hpp index 2c4a13905f..ede8eb5c81 100644 --- a/apps/openmw/mwinput/gyromanager.hpp +++ b/apps/openmw/mwinput/gyromanager.hpp @@ -25,8 +25,6 @@ namespace MWInput bool mGuiCursorEnabled; float mSensitivityH; float mSensitivityV; - bool mInvertH; - bool mInvertV; float mInputThreshold; GyroscopeAxis mAxisH; GyroscopeAxis mAxisV; diff --git a/apps/openmw/mwinput/sensormanager.cpp b/apps/openmw/mwinput/sensormanager.cpp index fed25b88ce..cab78c46f2 100644 --- a/apps/openmw/mwinput/sensormanager.cpp +++ b/apps/openmw/mwinput/sensormanager.cpp @@ -11,10 +11,9 @@ namespace MWInput { SensorManager::SensorManager() - : mGyroValues() + : mRotation() + , mGyroValues() , mGyroUpdateTimer(0.f) - , mGyroHAxis(GyroscopeAxis::Minus_X) - , mGyroVAxis(GyroscopeAxis::Y) , mGyroscope(nullptr) , mGuiCursorEnabled(true) { @@ -44,40 +43,36 @@ namespace MWInput // Treat setting from config as axes for landscape mode. // If the device does not support orientation change, do nothing. // Note: in is unclear how to correct axes for devices with non-standart Z axis direction. - mGyroHAxis = gyroscopeAxisFromString(Settings::Manager::getString("gyro horizontal axis", "Input")); - mGyroVAxis = gyroscopeAxisFromString(Settings::Manager::getString("gyro vertical axis", "Input")); + + mRotation = osg::Matrixf::identity(); + + float angle = 0; SDL_DisplayOrientation currentOrientation = SDL_GetDisplayOrientation(Settings::Manager::getInt("screen", "Video")); switch (currentOrientation) { case SDL_ORIENTATION_UNKNOWN: - return; + break; case SDL_ORIENTATION_LANDSCAPE: break; case SDL_ORIENTATION_LANDSCAPE_FLIPPED: { - mGyroHAxis = GyroscopeAxis(-mGyroHAxis); - mGyroVAxis = GyroscopeAxis(-mGyroVAxis); - + angle = osg::PIf; break; } case SDL_ORIENTATION_PORTRAIT: { - GyroscopeAxis oldVAxis = mGyroVAxis; - mGyroVAxis = mGyroHAxis; - mGyroHAxis = GyroscopeAxis(-oldVAxis); - + angle = -0.5 * osg::PIf; break; } case SDL_ORIENTATION_PORTRAIT_FLIPPED: { - GyroscopeAxis oldVAxis = mGyroVAxis; - mGyroVAxis = GyroscopeAxis(-mGyroHAxis); - mGyroHAxis = oldVAxis; - + angle = 0.5 * osg::PIf; break; } } + + mRotation.makeRotate(angle, osg::Vec3f(0, 0, 1)); } void SensorManager::updateSensors() @@ -127,12 +122,6 @@ namespace MWInput { if (setting.first == "Input" && setting.second == "enable gyroscope") init(); - - if (setting.first == "Input" && setting.second == "gyro horizontal axis") - correctGyroscopeAxes(); - - if (setting.first == "Input" && setting.second == "gyro vertical axis") - correctGyroscopeAxes(); } } @@ -159,11 +148,9 @@ namespace MWInput break; case SDL_SENSOR_GYRO: { - mGyroValues[0] = arg.data[0]; - mGyroValues[1] = arg.data[1]; - mGyroValues[2] = arg.data[2]; + osg::Vec3f gyro(arg.data[0], arg.data[1], arg.data[2]); + mGyroValues = mRotation * gyro; mGyroUpdateTimer = 0.f; - break; } default: @@ -179,7 +166,7 @@ namespace MWInput // More than half of second passed since the last gyroscope update. // A device more likely was disconnected or switched to the sleep mode. // Reset current rotation speed and wait for update. - mGyroValues = { 0, 0, 0 }; + mGyroValues = osg::Vec3f(); mGyroUpdateTimer = 0.f; } } @@ -191,6 +178,6 @@ namespace MWInput std::array SensorManager::getGyroValues() const { - return mGyroValues; + return { mGyroValues.x(), mGyroValues.y(), mGyroValues.z() }; } } diff --git a/apps/openmw/mwinput/sensormanager.hpp b/apps/openmw/mwinput/sensormanager.hpp index 92d0a036e8..6353c47764 100644 --- a/apps/openmw/mwinput/sensormanager.hpp +++ b/apps/openmw/mwinput/sensormanager.hpp @@ -3,11 +3,12 @@ #include +#include +#include + #include #include -#include "gyroaxis.hpp" - namespace SDLUtil { class InputWrapper; @@ -45,12 +46,10 @@ namespace MWInput void updateSensors(); void correctGyroscopeAxes(); - std::array mGyroValues; + osg::Matrixf mRotation; + osg::Vec3f mGyroValues; float mGyroUpdateTimer; - GyroscopeAxis mGyroHAxis; - GyroscopeAxis mGyroVAxis; - SDL_Sensor* mGyroscope; bool mGuiCursorEnabled; diff --git a/files/settings-default.cfg b/files/settings-default.cfg index f1f3206661..cec1dc3432 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -540,7 +540,7 @@ gyro horizontal axis = -x gyro vertical axis = y # The minimum gyroscope movement that is able to rotate the camera. -gyro input threshold = 0.01 +gyro input threshold = 0 # Horizontal camera axis sensitivity to gyroscope movement. gyro horizontal sensitivity = 1.0 From 15e9c6615c304b5d66365be0005cdcb3d4a55aa0 Mon Sep 17 00:00:00 2001 From: uramer Date: Wed, 19 Jan 2022 21:32:46 +0100 Subject: [PATCH 5/9] Disable controller gyro with older SDL --- apps/openmw/mwinput/controllermanager.cpp | 26 +++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwinput/controllermanager.cpp b/apps/openmw/mwinput/controllermanager.cpp index 8753344373..6c6549face 100644 --- a/apps/openmw/mwinput/controllermanager.cpp +++ b/apps/openmw/mwinput/controllermanager.cpp @@ -406,14 +406,16 @@ namespace MWInput 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; + #if SDL_VERSION_ATLEAST(2, 0, 14) + 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; + #endif } bool ControllerManager::isGyroAvailable() const @@ -424,9 +426,11 @@ namespace MWInput std::array ControllerManager::getGyroValues() const { float gyro[3] = { 0.f }; - SDL_GameController* cntrl = mBindingsManager->getControllerOrNull(); - if (cntrl && mGyroAvailable) - SDL_GameControllerGetSensorData(cntrl, SDL_SENSOR_GYRO, gyro, 3); + #if SDL_VERSION_ATLEAST(2, 0, 14) + SDL_GameController* cntrl = mBindingsManager->getControllerOrNull(); + if (cntrl && mGyroAvailable) + SDL_GameControllerGetSensorData(cntrl, SDL_SENSOR_GYRO, gyro, 3); + #endif return std::array({gyro[0], gyro[1], gyro[2]}); } } From 57ac592973e81edc08e613e96b32f9d77eb2a02e Mon Sep 17 00:00:00 2001 From: uramer Date: Wed, 19 Jan 2022 22:35:32 +0100 Subject: [PATCH 6/9] Fix warning --- apps/openmw/mwinput/gyromanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwinput/gyromanager.cpp b/apps/openmw/mwinput/gyromanager.cpp index f590abf45c..e06f9ac08d 100644 --- a/apps/openmw/mwinput/gyromanager.cpp +++ b/apps/openmw/mwinput/gyromanager.cpp @@ -15,7 +15,7 @@ namespace MWInput , mInputThreshold(Settings::Manager::getFloat("gyro input threshold", "Input")) , mAxisH(gyroscopeAxisFromString(Settings::Manager::getString("gyro horizontal axis", "Input"))) , mAxisV(gyroscopeAxisFromString(Settings::Manager::getString("gyro vertical axis", "Input"))) - {}; + {} void GyroManager::update(float dt, std::array values) const { From 183ca3079e8f9f1f7a99f025cc6eb4543d73b3ba Mon Sep 17 00:00:00 2001 From: uramer Date: Thu, 20 Jan 2022 15:42:01 +0100 Subject: [PATCH 7/9] Merge gyroaxis into gyro manager --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwinput/gyroaxis.cpp | 22 ---------------------- apps/openmw/mwinput/gyroaxis.hpp | 22 ---------------------- apps/openmw/mwinput/gyromanager.cpp | 18 ++++++++++++++++++ apps/openmw/mwinput/gyromanager.hpp | 15 +++++++++++++-- 5 files changed, 32 insertions(+), 47 deletions(-) delete mode 100644 apps/openmw/mwinput/gyroaxis.cpp delete mode 100644 apps/openmw/mwinput/gyroaxis.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 79cb6f30bd..3c8a0a4d9a 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -27,7 +27,7 @@ add_openmw_dir (mwrender add_openmw_dir (mwinput actions actionmanager bindingsmanager controllermanager controlswitch - inputmanagerimp mousemanager keyboardmanager gyroaxis sensormanager gyromanager + inputmanagerimp mousemanager keyboardmanager sensormanager gyromanager ) add_openmw_dir (mwgui diff --git a/apps/openmw/mwinput/gyroaxis.cpp b/apps/openmw/mwinput/gyroaxis.cpp deleted file mode 100644 index 3eb71fb30b..0000000000 --- a/apps/openmw/mwinput/gyroaxis.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "gyroaxis.hpp" - -namespace MWInput -{ - GyroscopeAxis gyroscopeAxisFromString(std::string_view s) - { - if (s == "x") - return GyroscopeAxis::X; - else if (s == "y") - return GyroscopeAxis::Y; - else if (s == "z") - return GyroscopeAxis::Z; - else if (s == "-x") - return GyroscopeAxis::Minus_X; - else if (s == "-y") - return GyroscopeAxis::Minus_Y; - else if (s == "-z") - return GyroscopeAxis::Minus_Z; - - return GyroscopeAxis::Unknown; - } -} diff --git a/apps/openmw/mwinput/gyroaxis.hpp b/apps/openmw/mwinput/gyroaxis.hpp deleted file mode 100644 index 542217351d..0000000000 --- a/apps/openmw/mwinput/gyroaxis.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef MWINPUT_GYROAXIS -#define MWINPUT_GYROAXIS - -#include - -namespace MWInput -{ - enum GyroscopeAxis - { - Unknown = 0, - X = 1, - Y = 2, - Z = 3, - Minus_X = -1, - Minus_Y = -2, - Minus_Z = -3 - }; - - GyroscopeAxis gyroscopeAxisFromString(std::string_view s); -} - -#endif // !MWINPUT_GYROAXIS diff --git a/apps/openmw/mwinput/gyromanager.cpp b/apps/openmw/mwinput/gyromanager.cpp index e06f9ac08d..b0c6f121c5 100644 --- a/apps/openmw/mwinput/gyromanager.cpp +++ b/apps/openmw/mwinput/gyromanager.cpp @@ -7,6 +7,24 @@ namespace MWInput { + GyroManager::GyroscopeAxis GyroManager::gyroscopeAxisFromString(std::string_view s) + { + if (s == "x") + return GyroscopeAxis::X; + else if (s == "y") + return GyroscopeAxis::Y; + else if (s == "z") + return GyroscopeAxis::Z; + else if (s == "-x") + return GyroscopeAxis::Minus_X; + else if (s == "-y") + return GyroscopeAxis::Minus_Y; + else if (s == "-z") + return GyroscopeAxis::Minus_Z; + + return GyroscopeAxis::Unknown; + } + GyroManager::GyroManager() : mEnabled(Settings::Manager::getBool("enable gyroscope", "Input")) , mGuiCursorEnabled(true) diff --git a/apps/openmw/mwinput/gyromanager.hpp b/apps/openmw/mwinput/gyromanager.hpp index ede8eb5c81..bcd3b88f49 100644 --- a/apps/openmw/mwinput/gyromanager.hpp +++ b/apps/openmw/mwinput/gyromanager.hpp @@ -3,8 +3,6 @@ #include -#include "gyroaxis.hpp" - namespace MWInput { class GyroManager @@ -21,6 +19,19 @@ namespace MWInput void setGuiCursorEnabled(bool enabled) { mGuiCursorEnabled = enabled; } private: + enum GyroscopeAxis + { + Unknown = 0, + X = 1, + Y = 2, + Z = 3, + Minus_X = -1, + Minus_Y = -2, + Minus_Z = -3 + }; + + static GyroscopeAxis gyroscopeAxisFromString(std::string_view s); + bool mEnabled; bool mGuiCursorEnabled; float mSensitivityH; From a85f2b0b2ac1e2ec172a6d094ff48a639784e5b8 Mon Sep 17 00:00:00 2001 From: uramer Date: Sat, 22 Jan 2022 13:21:23 +0100 Subject: [PATCH 8/9] Remove unnecessary mGuiCursorEnabled; from sensor manager --- apps/openmw/mwinput/inputmanagerimp.cpp | 1 - apps/openmw/mwinput/sensormanager.cpp | 1 - apps/openmw/mwinput/sensormanager.hpp | 4 ---- 3 files changed, 6 deletions(-) diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index 8beead5803..40de2b45fb 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -132,7 +132,6 @@ namespace MWInput { mControllerManager->setGuiCursorEnabled(guiMode); mMouseManager->setGuiCursorEnabled(guiMode); - mSensorManager->setGuiCursorEnabled(guiMode); mGyroManager->setGuiCursorEnabled(guiMode); mMouseManager->setMouseLookEnabled(!guiMode); if (guiMode) diff --git a/apps/openmw/mwinput/sensormanager.cpp b/apps/openmw/mwinput/sensormanager.cpp index cab78c46f2..f3cee579e5 100644 --- a/apps/openmw/mwinput/sensormanager.cpp +++ b/apps/openmw/mwinput/sensormanager.cpp @@ -15,7 +15,6 @@ namespace MWInput , mGyroValues() , mGyroUpdateTimer(0.f) , mGyroscope(nullptr) - , mGuiCursorEnabled(true) { init(); } diff --git a/apps/openmw/mwinput/sensormanager.hpp b/apps/openmw/mwinput/sensormanager.hpp index 6353c47764..8f72b99de9 100644 --- a/apps/openmw/mwinput/sensormanager.hpp +++ b/apps/openmw/mwinput/sensormanager.hpp @@ -36,8 +36,6 @@ namespace MWInput void displayOrientationChanged() override; void processChangedSettings(const Settings::CategorySettingVector& changed); - void setGuiCursorEnabled(bool enabled) { mGuiCursorEnabled = enabled; } - bool isGyroAvailable() const; std::array getGyroValues() const; @@ -51,8 +49,6 @@ namespace MWInput float mGyroUpdateTimer; SDL_Sensor* mGyroscope; - - bool mGuiCursorEnabled; }; } #endif From 40a228026104b9d1e3c4fb58c0123d1cc24d6cdd Mon Sep 17 00:00:00 2001 From: uramer Date: Mon, 24 Jan 2022 16:26:24 +0100 Subject: [PATCH 9/9] Update documentation regarding gyroscope --- docs/source/reference/modding/settings/input.rst | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/source/reference/modding/settings/input.rst b/docs/source/reference/modding/settings/input.rst index d04c267a76..7aedf1bc21 100644 --- a/docs/source/reference/modding/settings/input.rst +++ b/docs/source/reference/modding/settings/input.rst @@ -158,6 +158,11 @@ Enable the support of camera rotation based on the information supplied from the This setting can only be configured by editing the settings configuration file. +Built-in (e. g. in a phone or tablet) and controller gyroscopes are supported. If both are present, controller gyroscope takes priority. + +Note: controller gyroscopes are only supported when OpenMW is built with SDL 2.0.14 or higher, +and were tested only on Windows. + gyro horizontal axis -------------------- @@ -190,8 +195,8 @@ gyro input threshold -------------------- :Type: floating point -:Range: > 0 -:Default: 0.01 +:Range: >=0 +:Default: 0.0 This setting determines the minimum value of the rotation that will be accepted. It allows to avoid crosshair oscillation due to gyroscope "noise". @@ -209,6 +214,8 @@ This setting controls the overall gyroscope horizontal sensitivity. The smaller this sensitivity is, the less visible effect the device rotation will have on the horizontal camera rotation, and vice versa. +Value of X means that rotating the device by 1 degree will cause the player to rotate by X degrees. + This setting can only be configured by editing the settings configuration file. gyro vertical sensitivity @@ -222,4 +229,6 @@ This setting controls the overall gyroscope vertical sensitivity. The smaller this sensitivity is, the less visible effect the device rotation will have on the vertical camera rotation, and vice versa. +Value of X means that rotating the device by 1 degree will cause the player to rotate by X degrees. + This setting can only be configured by editing the settings configuration file.