diff options
Diffstat (limited to '')
| -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 22a849866..b99d3497f 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 | ||
| @@ -159,6 +160,37 @@ Common::Vec3f MotionInput::GetRotations() const { | |||
| 159 | return rotations; | 160 | return rotations; |
| 160 | } | 161 | } |
| 161 | 162 | ||
| 163 | Input::MotionStatus MotionInput::GetMotion() const { | ||
| 164 | const Common::Vec3f gyroscope = GetGyroscope(); | ||
| 165 | const Common::Vec3f accelerometer = GetAcceleration(); | ||
| 166 | const Common::Vec3f rotation = GetRotations(); | ||
| 167 | const std::array<Common::Vec3f, 3> orientation = GetOrientation(); | ||
| 168 | return {accelerometer, gyroscope, rotation, orientation}; | ||
| 169 | } | ||
| 170 | |||
| 171 | Input::MotionStatus MotionInput::GetRandomMotion(int accel_magnitude, int gyro_magnitude) const { | ||
| 172 | std::random_device device; | ||
| 173 | std::mt19937 gen(device()); | ||
| 174 | std::uniform_int_distribution<s16> distribution(-1000, 1000); | ||
| 175 | const Common::Vec3f gyroscope = { | ||
| 176 | distribution(gen) * 0.001f, | ||
| 177 | distribution(gen) * 0.001f, | ||
| 178 | distribution(gen) * 0.001f, | ||
| 179 | }; | ||
| 180 | const Common::Vec3f accelerometer = { | ||
| 181 | distribution(gen) * 0.001f, | ||
| 182 | distribution(gen) * 0.001f, | ||
| 183 | distribution(gen) * 0.001f, | ||
| 184 | }; | ||
| 185 | const Common::Vec3f rotation = {}; | ||
| 186 | const std::array<Common::Vec3f, 3> orientation = { | ||
| 187 | Common::Vec3f{1.0f, 0, 0}, | ||
| 188 | Common::Vec3f{0, 1.0f, 0}, | ||
| 189 | Common::Vec3f{0, 0, 1.0f}, | ||
| 190 | }; | ||
| 191 | return {accelerometer * accel_magnitude, gyroscope * gyro_magnitude, rotation, orientation}; | ||
| 192 | } | ||
| 193 | |||
| 162 | void MotionInput::ResetOrientation() { | 194 | void MotionInput::ResetOrientation() { |
| 163 | if (!reset_enabled) { | 195 | if (!reset_enabled) { |
| 164 | return; | 196 | return; |