summaryrefslogtreecommitdiff
path: root/src/input_common/motion_input.cpp
diff options
context:
space:
mode:
authorGravatar german2020-09-17 20:26:34 -0500
committerGravatar german2020-09-25 17:59:52 -0500
commit03b574ae2272fc8465e7d38f21b198fcb1885186 (patch)
treee6e70906677339fce1a7bedafab8d8fcb39026b4 /src/input_common/motion_input.cpp
parentMerge pull request #4717 from lioncash/debug (diff)
downloadyuzu-03b574ae2272fc8465e7d38f21b198fcb1885186.tar.gz
yuzu-03b574ae2272fc8465e7d38f21b198fcb1885186.tar.xz
yuzu-03b574ae2272fc8465e7d38f21b198fcb1885186.zip
Add random motion input to SDL
Diffstat (limited to 'src/input_common/motion_input.cpp')
-rw-r--r--src/input_common/motion_input.cpp32
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
163Input::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
171Input::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
162void MotionInput::ResetOrientation() { 194void MotionInput::ResetOrientation() {
163 if (!reset_enabled) { 195 if (!reset_enabled) {
164 return; 196 return;