diff options
| author | Mai <mathew1800@gmail.com> | 2022-10-12 17:35:50 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-12 17:35:50 +0000 |
| commit | a5fa95adfdef8b45fdbb859af0044b0d1622a680 (patch) | |
| tree | daec0d942dac905a520fb6e3e3686154ccf738bc /Source/Core | |
| parent | 1f8b196d6deed6d807a2afde7978bb9a216fd064 (diff) | |
| parent | bf53e14abe32e60c18122b15529884b9fbb0c413 (diff) | |
Merge pull request #11151 from jordan-woyak/quat-fix
Fix some bad quaternion math.
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/Common/Matrix.cpp | 2 | ||||
| -rw-r--r-- | Source/Core/Core/HW/WiimoteEmu/Dynamics.cpp | 4 |
2 files changed, 4 insertions, 2 deletions
diff --git a/Source/Core/Common/Matrix.cpp b/Source/Core/Common/Matrix.cpp index 724d28f17f..57be1a3cc4 100644 --- a/Source/Core/Common/Matrix.cpp +++ b/Source/Core/Common/Matrix.cpp @@ -78,7 +78,7 @@ Quaternion::Quaternion(float w, float x, float y, float z) : data(x, y, z, w) float Quaternion::Norm() const { - return data.Dot(data); + return std::sqrt(data.Dot(data)); } Quaternion Quaternion::Normalized() const diff --git a/Source/Core/Core/HW/WiimoteEmu/Dynamics.cpp b/Source/Core/Core/HW/WiimoteEmu/Dynamics.cpp index dd21cd721a..b3864e3c8b 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Dynamics.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Dynamics.cpp @@ -398,7 +398,9 @@ Common::Quaternion GetRotationFromAcceleration(const Common::Vec3& accel) Common::Quaternion GetRotationFromGyroscope(const Common::Vec3& gyro) { - return Common::Quaternion{1, gyro.x / 2, gyro.y / 2, gyro.z / 2}; + const auto length = gyro.Length(); + return (length != 0) ? Common::Quaternion::Rotate(length, gyro / length) : + Common::Quaternion::Identity(); } Common::Matrix33 GetRotationalMatrix(const Common::Vec3& angle) |
