From fffd005178a59877a0072be6c1f4ed50f1e888a7 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 18 Oct 2020 14:32:13 -0500 Subject: [PATCH] WiimoteEmu: Allow tilt to wrap around and simulate full 360 degree rotations. --- Source/Core/Core/HW/WiimoteEmu/Dynamics.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/HW/WiimoteEmu/Dynamics.cpp b/Source/Core/Core/HW/WiimoteEmu/Dynamics.cpp index 0f5532d58a..43bf5e0ce9 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Dynamics.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Dynamics.cpp @@ -120,9 +120,19 @@ void EmulateTilt(RotationalState* state, ControllerEmu::Tilt* const tilt_group, const ControlState roll = target.x * MathUtil::PI; const ControlState pitch = target.y * MathUtil::PI; + const auto target_angle = Common::Vec3(pitch, -roll, 0); + + // For each axis, wrap around current angle if target is farther than 180 degrees. + for (std::size_t i = 0; i != target_angle.data.size(); ++i) + { + auto& angle = state->angle.data[i]; + if (std::abs(angle - target_angle.data[i]) > float(MathUtil::PI)) + angle -= std::copysign(MathUtil::TAU, angle); + } + const auto max_accel = std::pow(tilt_group->GetMaxRotationalVelocity(), 2) / MathUtil::TAU; - ApproachAngleWithAccel(state, Common::Vec3(pitch, -roll, 0), max_accel, time_elapsed); + ApproachAngleWithAccel(state, target_angle, max_accel, time_elapsed); } void EmulateSwing(MotionState* state, ControllerEmu::Force* swing_group, float time_elapsed)