InputCommon/WiimoteEmu: Replace stateful rotational matrices with quaternions.

This commit is contained in:
Jordan Woyak
2020-10-19 15:29:16 -05:00
parent 39030ea33c
commit 09431635f3
7 changed files with 43 additions and 35 deletions

View File

@ -579,7 +579,7 @@ void AccelerometerMappingIndicator::Draw()
// UI axes are opposite that of Wii remote accelerometer.
p.scale(-1.0, -1.0);
const auto rotation = WiimoteEmu::GetMatrixFromAcceleration(state);
const auto rotation = WiimoteEmu::GetRotationFromAcceleration(state);
// Draw sphere.
p.setPen(GetCosmeticPen(QPen(GetRawInputColor(), 0.5)));
@ -650,8 +650,9 @@ void GyroMappingIndicator::Draw()
const auto jitter = raw_gyro_state - m_previous_velocity;
m_previous_velocity = raw_gyro_state;
m_state *= WiimoteEmu::GetMatrixFromGyroscope(angular_velocity * Common::Vec3(-1, +1, -1) /
INDICATOR_UPDATE_FREQ);
m_state *= WiimoteEmu::GetRotationFromGyroscope(angular_velocity * Common::Vec3(-1, +1, -1) /
INDICATOR_UPDATE_FREQ);
m_state = m_state.Normalized();
// Reset orientation when stable for a bit:
constexpr u32 STABLE_RESET_STEPS = INDICATOR_UPDATE_FREQ;
@ -664,10 +665,11 @@ void GyroMappingIndicator::Draw()
++m_stable_steps;
if (STABLE_RESET_STEPS == m_stable_steps)
m_state = Common::Matrix33::Identity();
m_state = Common::Quaternion::Identity();
// Use an empty rotation matrix if gyroscope data is not present.
const auto rotation = (gyro_state.has_value() ? m_state : Common::Matrix33{});
const auto rotation =
(gyro_state.has_value() ? Common::Matrix33::FromQuaternion(m_state) : Common::Matrix33{});
QPainter p(this);
DrawBoundingBox(p);

View File

@ -176,7 +176,7 @@ private:
void Draw() override;
ControllerEmu::IMUGyroscope& m_gyro_group;
Common::Matrix33 m_state = Common::Matrix33::Identity();
Common::Quaternion m_state = Common::Quaternion::Identity();
Common::Vec3 m_previous_velocity = {};
u32 m_stable_steps = 0;
};