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