diff options
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 182a2869a..e89019723 100644 --- a/src/input_common/motion_input.cpp +++ b/src/input_common/motion_input.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included | 3 | // Refer to the license.txt file included |
| 4 | 4 | ||
| 5 | #include <random> | ||
| 5 | #include "common/math_util.h" | 6 | #include "common/math_util.h" |
| 6 | #include "input_common/motion_input.h" | 7 | #include "input_common/motion_input.h" |
| 7 | 8 | ||
| @@ -190,6 +191,37 @@ Common::Vec3f MotionInput::GetRotations() const { | |||
| 190 | return rotations; | 191 | return rotations; |
| 191 | } | 192 | } |
| 192 | 193 | ||
| 194 | Input::MotionStatus MotionInput::GetMotion() const { | ||
| 195 | const Common::Vec3f gyroscope = GetGyroscope(); | ||
| 196 | const Common::Vec3f accelerometer = GetAcceleration(); | ||
| 197 | const Common::Vec3f rotation = GetRotations(); | ||
| 198 | const std::array<Common::Vec3f, 3> orientation = GetOrientation(); | ||
| 199 | return {accelerometer, gyroscope, rotation, orientation}; | ||
| 200 | } | ||
| 201 | |||
| 202 | Input::MotionStatus MotionInput::GetRandomMotion(int accel_magnitude, int gyro_magnitude) const { | ||
| 203 | std::random_device device; | ||
| 204 | std::mt19937 gen(device()); | ||
| 205 | std::uniform_int_distribution<s16> distribution(-1000, 1000); | ||
| 206 | const Common::Vec3f gyroscope = { | ||
| 207 | distribution(gen) * 0.001f, | ||
| 208 | distribution(gen) * 0.001f, | ||
| 209 | distribution(gen) * 0.001f, | ||
| 210 | }; | ||
| 211 | const Common::Vec3f accelerometer = { | ||
| 212 | distribution(gen) * 0.001f, | ||
| 213 | distribution(gen) * 0.001f, | ||
| 214 | distribution(gen) * 0.001f, | ||
| 215 | }; | ||
| 216 | const Common::Vec3f rotation = {}; | ||
| 217 | const std::array<Common::Vec3f, 3> orientation = { | ||
| 218 | Common::Vec3f{1.0f, 0, 0}, | ||
| 219 | Common::Vec3f{0, 1.0f, 0}, | ||
| 220 | Common::Vec3f{0, 0, 1.0f}, | ||
| 221 | }; | ||
| 222 | return {accelerometer * accel_magnitude, gyroscope * gyro_magnitude, rotation, orientation}; | ||
| 223 | } | ||
| 224 | |||
| 193 | void MotionInput::ResetOrientation() { | 225 | void MotionInput::ResetOrientation() { |
| 194 | if (!reset_enabled || only_accelerometer) { | 226 | if (!reset_enabled || only_accelerometer) { |
| 195 | return; | 227 | return; |