diff options
author | bunnei <bunneidev@gmail.com> | 2020-10-08 10:18:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-08 10:18:39 -0700 |
commit | 06e65de93cfa923b6fb1f12fa20193515249234d (patch) | |
tree | 9771ca19a2686af1185f62ed7488d977d37a1703 /src/input_common/motion_input.cpp | |
parent | 7a99226785642103037cf4152bf0a34435054e00 (diff) | |
parent | 297823239026d1b5487f9b07f63646ca4a2e3a79 (diff) |
Merge pull request #4677 from german77/ShakeFromButton
InputCommon: Add random motion input for buttons
Diffstat (limited to 'src/input_common/motion_input.cpp')
-rw-r--r-- | src/input_common/motion_input.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/input_common/motion_input.cpp b/src/input_common/motion_input.cpp index 22a849866d..b99d3497f9 100644 --- a/src/input_common/motion_input.cpp +++ b/src/input_common/motion_input.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included +#include <random> #include "common/math_util.h" #include "input_common/motion_input.h" @@ -159,6 +160,37 @@ Common::Vec3f MotionInput::GetRotations() const { return rotations; } +Input::MotionStatus MotionInput::GetMotion() const { + const Common::Vec3f gyroscope = GetGyroscope(); + const Common::Vec3f accelerometer = GetAcceleration(); + const Common::Vec3f rotation = GetRotations(); + const std::array<Common::Vec3f, 3> orientation = GetOrientation(); + return {accelerometer, gyroscope, rotation, orientation}; +} + +Input::MotionStatus MotionInput::GetRandomMotion(int accel_magnitude, int gyro_magnitude) const { + std::random_device device; + std::mt19937 gen(device()); + std::uniform_int_distribution<s16> distribution(-1000, 1000); + const Common::Vec3f gyroscope = { + distribution(gen) * 0.001f, + distribution(gen) * 0.001f, + distribution(gen) * 0.001f, + }; + const Common::Vec3f accelerometer = { + distribution(gen) * 0.001f, + distribution(gen) * 0.001f, + distribution(gen) * 0.001f, + }; + const Common::Vec3f rotation = {}; + const std::array<Common::Vec3f, 3> orientation = { + Common::Vec3f{1.0f, 0, 0}, + Common::Vec3f{0, 1.0f, 0}, + Common::Vec3f{0, 0, 1.0f}, + }; + return {accelerometer * accel_magnitude, gyroscope * gyro_magnitude, rotation, orientation}; +} + void MotionInput::ResetOrientation() { if (!reset_enabled) { return; |