diff options
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/motion_input.cpp | 76 | ||||
| -rw-r--r-- | src/input_common/motion_input.h | 4 |
2 files changed, 40 insertions, 40 deletions
diff --git a/src/input_common/motion_input.cpp b/src/input_common/motion_input.cpp index d3e736044..182a2869a 100644 --- a/src/input_common/motion_input.cpp +++ b/src/input_common/motion_input.cpp | |||
| @@ -57,7 +57,7 @@ bool MotionInput::IsCalibrated(f32 sensitivity) const { | |||
| 57 | return real_error.Length() < sensitivity; | 57 | return real_error.Length() < sensitivity; |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | void MotionInput::UpdateRotation(const u64 elapsed_time) { | 60 | void MotionInput::UpdateRotation(u64 elapsed_time) { |
| 61 | const f32 sample_period = elapsed_time / 1000000.0f; | 61 | const f32 sample_period = elapsed_time / 1000000.0f; |
| 62 | if (sample_period > 0.1f) { | 62 | if (sample_period > 0.1f) { |
| 63 | return; | 63 | return; |
| @@ -65,7 +65,7 @@ void MotionInput::UpdateRotation(const u64 elapsed_time) { | |||
| 65 | rotations += gyro * sample_period; | 65 | rotations += gyro * sample_period; |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | void MotionInput::UpdateOrientation(const u64 elapsed_time) { | 68 | void MotionInput::UpdateOrientation(u64 elapsed_time) { |
| 69 | if (!IsCalibrated(0.1f)) { | 69 | if (!IsCalibrated(0.1f)) { |
| 70 | ResetOrientation(); | 70 | ResetOrientation(); |
| 71 | } | 71 | } |
| @@ -174,6 +174,42 @@ std::array<Common::Vec3f, 3> MotionInput::GetOrientation() const { | |||
| 174 | Common::Vec3f(-matrix4x4[8], -matrix4x4[9], matrix4x4[10])}; | 174 | Common::Vec3f(-matrix4x4[8], -matrix4x4[9], matrix4x4[10])}; |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | Common::Vec3f MotionInput::GetAcceleration() const { | ||
| 178 | return accel; | ||
| 179 | } | ||
| 180 | |||
| 181 | Common::Vec3f MotionInput::GetGyroscope() const { | ||
| 182 | return gyro; | ||
| 183 | } | ||
| 184 | |||
| 185 | Common::Quaternion<f32> MotionInput::GetQuaternion() const { | ||
| 186 | return quat; | ||
| 187 | } | ||
| 188 | |||
| 189 | Common::Vec3f MotionInput::GetRotations() const { | ||
| 190 | return rotations; | ||
| 191 | } | ||
| 192 | |||
| 193 | void MotionInput::ResetOrientation() { | ||
| 194 | if (!reset_enabled || only_accelerometer) { | ||
| 195 | return; | ||
| 196 | } | ||
| 197 | if (!IsMoving(0.5f) && accel.z <= -0.9f) { | ||
| 198 | ++reset_counter; | ||
| 199 | if (reset_counter > 900) { | ||
| 200 | quat.w = 0; | ||
| 201 | quat.xyz[0] = 0; | ||
| 202 | quat.xyz[1] = 0; | ||
| 203 | quat.xyz[2] = -1; | ||
| 204 | SetOrientationFromAccelerometer(); | ||
| 205 | integral_error = {}; | ||
| 206 | reset_counter = 0; | ||
| 207 | } | ||
| 208 | } else { | ||
| 209 | reset_counter = 0; | ||
| 210 | } | ||
| 211 | } | ||
| 212 | |||
| 177 | void MotionInput::SetOrientationFromAccelerometer() { | 213 | void MotionInput::SetOrientationFromAccelerometer() { |
| 178 | int iterations = 0; | 214 | int iterations = 0; |
| 179 | const f32 sample_period = 0.015f; | 215 | const f32 sample_period = 0.015f; |
| @@ -234,40 +270,4 @@ void MotionInput::SetOrientationFromAccelerometer() { | |||
| 234 | quat = quat.Normalized(); | 270 | quat = quat.Normalized(); |
| 235 | } | 271 | } |
| 236 | } | 272 | } |
| 237 | |||
| 238 | Common::Vec3f MotionInput::GetAcceleration() const { | ||
| 239 | return accel; | ||
| 240 | } | ||
| 241 | |||
| 242 | Common::Vec3f MotionInput::GetGyroscope() const { | ||
| 243 | return gyro; | ||
| 244 | } | ||
| 245 | |||
| 246 | Common::Quaternion<f32> MotionInput::GetQuaternion() const { | ||
| 247 | return quat; | ||
| 248 | } | ||
| 249 | |||
| 250 | Common::Vec3f MotionInput::GetRotations() const { | ||
| 251 | return rotations; | ||
| 252 | } | ||
| 253 | |||
| 254 | void MotionInput::ResetOrientation() { | ||
| 255 | if (!reset_enabled || only_accelerometer) { | ||
| 256 | return; | ||
| 257 | } | ||
| 258 | if (!IsMoving(0.5f) && accel.z <= -0.9f) { | ||
| 259 | ++reset_counter; | ||
| 260 | if (reset_counter > 900) { | ||
| 261 | quat.w = 0; | ||
| 262 | quat.xyz[0] = 0; | ||
| 263 | quat.xyz[1] = 0; | ||
| 264 | quat.xyz[2] = -1; | ||
| 265 | SetOrientationFromAccelerometer(); | ||
| 266 | integral_error = {}; | ||
| 267 | reset_counter = 0; | ||
| 268 | } | ||
| 269 | } else { | ||
| 270 | reset_counter = 0; | ||
| 271 | } | ||
| 272 | } | ||
| 273 | } // namespace InputCommon | 273 | } // namespace InputCommon |
diff --git a/src/input_common/motion_input.h b/src/input_common/motion_input.h index f6c1fece7..c90ee64e5 100644 --- a/src/input_common/motion_input.h +++ b/src/input_common/motion_input.h | |||
| @@ -29,8 +29,8 @@ public: | |||
| 29 | void EnableReset(bool reset); | 29 | void EnableReset(bool reset); |
| 30 | void ResetRotations(); | 30 | void ResetRotations(); |
| 31 | 31 | ||
| 32 | void UpdateRotation(const u64 elapsed_time); | 32 | void UpdateRotation(u64 elapsed_time); |
| 33 | void UpdateOrientation(const u64 elapsed_time); | 33 | void UpdateOrientation(u64 elapsed_time); |
| 34 | 34 | ||
| 35 | std::array<Common::Vec3f, 3> GetOrientation() const; | 35 | std::array<Common::Vec3f, 3> GetOrientation() const; |
| 36 | Common::Vec3f GetAcceleration() const; | 36 | Common::Vec3f GetAcceleration() const; |