Skip to content
Permalink
Browse files
Merge pull request #11151 from jordan-woyak/quat-fix
Fix some bad quaternion math.
  • Loading branch information
lioncash committed Oct 12, 2022
2 parents 1f8b196 + bf53e14 commit a5fa95a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
@@ -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
@@ -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)

0 comments on commit a5fa95a

Please sign in to comment.