1
mirror of https://github.com/yuzu-emu/yuzu synced 2024-11-16 23:30:35 +01:00

Address comments

This commit is contained in:
german 2020-10-04 18:15:53 -05:00
parent a220d8799e
commit a54aee290f
2 changed files with 40 additions and 40 deletions

View File

@ -57,7 +57,7 @@ bool MotionInput::IsCalibrated(f32 sensitivity) const {
return real_error.Length() < sensitivity;
}
void MotionInput::UpdateRotation(const u64 elapsed_time) {
void MotionInput::UpdateRotation(u64 elapsed_time) {
const f32 sample_period = elapsed_time / 1000000.0f;
if (sample_period > 0.1f) {
return;
@ -65,7 +65,7 @@ void MotionInput::UpdateRotation(const u64 elapsed_time) {
rotations += gyro * sample_period;
}
void MotionInput::UpdateOrientation(const u64 elapsed_time) {
void MotionInput::UpdateOrientation(u64 elapsed_time) {
if (!IsCalibrated(0.1f)) {
ResetOrientation();
}
@ -174,6 +174,42 @@ std::array<Common::Vec3f, 3> MotionInput::GetOrientation() const {
Common::Vec3f(-matrix4x4[8], -matrix4x4[9], matrix4x4[10])};
}
Common::Vec3f MotionInput::GetAcceleration() const {
return accel;
}
Common::Vec3f MotionInput::GetGyroscope() const {
return gyro;
}
Common::Quaternion<f32> MotionInput::GetQuaternion() const {
return quat;
}
Common::Vec3f MotionInput::GetRotations() const {
return rotations;
}
void MotionInput::ResetOrientation() {
if (!reset_enabled || only_accelerometer) {
return;
}
if (!IsMoving(0.5f) && accel.z <= -0.9f) {
++reset_counter;
if (reset_counter > 900) {
quat.w = 0;
quat.xyz[0] = 0;
quat.xyz[1] = 0;
quat.xyz[2] = -1;
SetOrientationFromAccelerometer();
integral_error = {};
reset_counter = 0;
}
} else {
reset_counter = 0;
}
}
void MotionInput::SetOrientationFromAccelerometer() {
int iterations = 0;
const f32 sample_period = 0.015f;
@ -234,40 +270,4 @@ void MotionInput::SetOrientationFromAccelerometer() {
quat = quat.Normalized();
}
}
Common::Vec3f MotionInput::GetAcceleration() const {
return accel;
}
Common::Vec3f MotionInput::GetGyroscope() const {
return gyro;
}
Common::Quaternion<f32> MotionInput::GetQuaternion() const {
return quat;
}
Common::Vec3f MotionInput::GetRotations() const {
return rotations;
}
void MotionInput::ResetOrientation() {
if (!reset_enabled || only_accelerometer) {
return;
}
if (!IsMoving(0.5f) && accel.z <= -0.9f) {
++reset_counter;
if (reset_counter > 900) {
quat.w = 0;
quat.xyz[0] = 0;
quat.xyz[1] = 0;
quat.xyz[2] = -1;
SetOrientationFromAccelerometer();
integral_error = {};
reset_counter = 0;
}
} else {
reset_counter = 0;
}
}
} // namespace InputCommon

View File

@ -29,8 +29,8 @@ public:
void EnableReset(bool reset);
void ResetRotations();
void UpdateRotation(const u64 elapsed_time);
void UpdateOrientation(const u64 elapsed_time);
void UpdateRotation(u64 elapsed_time);
void UpdateOrientation(u64 elapsed_time);
std::array<Common::Vec3f, 3> GetOrientation() const;
Common::Vec3f GetAcceleration() const;