Skip to content

Commit

Permalink
Merge pull request #8751 from jordan-woyak/point-fix
Browse files Browse the repository at this point in the history
WiimoteEmu: Apply "Tilt" and "Point" rotations separately for proper tilted pointing.
  • Loading branch information
leoetlino committed Apr 27, 2020
2 parents 03c569a + d6dfb3a commit 75e79ec
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/WiimoteEmu/Dynamics.cpp
Expand Up @@ -216,7 +216,7 @@ WiimoteCommon::AccelData ConvertAccelData(const Common::Vec3& accel, u16 zero_g,
u16(std::clamp(std::lround(scaled_accel.z + zero_g), 0l, MAX_VALUE))});
}

void EmulateCursor(MotionState* state, ControllerEmu::Cursor* ir_group, float time_elapsed)
void EmulatePoint(MotionState* state, ControllerEmu::Cursor* ir_group, float time_elapsed)
{
const auto cursor = ir_group->GetState(true);

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/WiimoteEmu/Dynamics.h
Expand Up @@ -83,7 +83,7 @@ void ApproachAngleWithAccel(RotationalState* state, const Common::Vec3& target,
void EmulateShake(PositionalState* state, ControllerEmu::Shake* shake_group, float time_elapsed);
void EmulateTilt(RotationalState* state, ControllerEmu::Tilt* tilt_group, float time_elapsed);
void EmulateSwing(MotionState* state, ControllerEmu::Force* swing_group, float time_elapsed);
void EmulateCursor(MotionState* state, ControllerEmu::Cursor* ir_group, float time_elapsed);
void EmulatePoint(MotionState* state, ControllerEmu::Cursor* ir_group, float time_elapsed);
void EmulateIMUCursor(IMUCursorState* state, ControllerEmu::IMUCursor* imu_ir_group,
ControllerEmu::IMUAccelerometer* imu_accelerometer_group,
ControllerEmu::IMUGyroscope* imu_gyroscope_group, float time_elapsed);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp
Expand Up @@ -588,7 +588,7 @@ void Wiimote::DoState(PointerWrap& p)
// Dynamics
p.Do(m_swing_state);
p.Do(m_tilt_state);
p.Do(m_cursor_state);
p.Do(m_point_state);
p.Do(m_shake_state);

// We'll consider the IMU state part of the user's physical controller state and not sync it.
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/HW/WiimoteEmu/Extension/Nunchuk.cpp
Expand Up @@ -96,7 +96,8 @@ void Nunchuk::Update()
EmulateTilt(&m_tilt_state, m_tilt, 1.f / ::Wiimote::UPDATE_FREQ);
EmulateShake(&m_shake_state, m_shake, 1.f / ::Wiimote::UPDATE_FREQ);

const auto transformation = GetRotationalMatrix(-m_tilt_state.angle - m_swing_state.angle);
const auto transformation =
GetRotationalMatrix(-m_tilt_state.angle) * GetRotationalMatrix(-m_swing_state.angle);

Common::Vec3 accel =
transformation *
Expand Down
14 changes: 7 additions & 7 deletions Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp
Expand Up @@ -189,7 +189,7 @@ void Wiimote::Reset()
// Dynamics:
m_swing_state = {};
m_tilt_state = {};
m_cursor_state = {};
m_point_state = {};
m_shake_state = {};

m_imu_cursor_state = {};
Expand Down Expand Up @@ -793,7 +793,7 @@ void Wiimote::StepDynamics()
{
EmulateSwing(&m_swing_state, m_swing, 1.f / ::Wiimote::UPDATE_FREQ);
EmulateTilt(&m_tilt_state, m_tilt, 1.f / ::Wiimote::UPDATE_FREQ);
EmulateCursor(&m_cursor_state, m_ir, 1.f / ::Wiimote::UPDATE_FREQ);
EmulatePoint(&m_point_state, m_ir, 1.f / ::Wiimote::UPDATE_FREQ);
EmulateShake(&m_shake_state, m_shake, 1.f / ::Wiimote::UPDATE_FREQ);
EmulateIMUCursor(&m_imu_cursor_state, m_imu_ir, m_imu_accelerometer, m_imu_gyroscope,
1.f / ::Wiimote::UPDATE_FREQ);
Expand All @@ -813,7 +813,7 @@ Common::Vec3 Wiimote::GetAcceleration(Common::Vec3 extra_acceleration)
Common::Vec3 Wiimote::GetAngularVelocity(Common::Vec3 extra_angular_velocity)
{
return GetOrientation() * (m_tilt_state.angular_velocity + m_swing_state.angular_velocity +
m_cursor_state.angular_velocity + extra_angular_velocity);
m_point_state.angular_velocity + extra_angular_velocity);
}

Common::Matrix44 Wiimote::GetTransformation(const Common::Matrix33& extra_rotation) const
Expand All @@ -823,10 +823,10 @@ Common::Matrix44 Wiimote::GetTransformation(const Common::Matrix33& extra_rotati

// TODO: Think about and clean up matrix order + make nunchuk match.
return Common::Matrix44::Translate(-m_shake_state.position) *
Common::Matrix44::FromMatrix33(
extra_rotation * GetRotationalMatrix(-m_tilt_state.angle - m_swing_state.angle -
m_cursor_state.angle)) *
Common::Matrix44::Translate(-m_swing_state.position - m_cursor_state.position);
Common::Matrix44::FromMatrix33(extra_rotation * GetRotationalMatrix(-m_tilt_state.angle) *
GetRotationalMatrix(-m_point_state.angle) *
GetRotationalMatrix(-m_swing_state.angle)) *
Common::Matrix44::Translate(-m_swing_state.position - m_point_state.position);
}

Common::Matrix33 Wiimote::GetOrientation() const
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h
Expand Up @@ -296,7 +296,7 @@ class Wiimote : public ControllerEmu::EmulatedController
// Dynamics:
MotionState m_swing_state;
RotationalState m_tilt_state;
MotionState m_cursor_state;
MotionState m_point_state;
PositionalState m_shake_state;

IMUCursorState m_imu_cursor_state;
Expand Down

0 comments on commit 75e79ec

Please sign in to comment.