1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 19:58:49 +00:00

fix: use intrinsic convention for ToVector3

This commit is contained in:
Oliver Booth 2023-03-31 01:31:19 +01:00
parent 02947944cd
commit cd4c3542f7
No known key found for this signature in database
GPG Key ID: 20BEB9DC87961025
2 changed files with 22 additions and 4 deletions

View File

@ -18,4 +18,22 @@ public class QuaternionTests
Assert.AreEqual(axis, axisAngle.Axis);
Assert.AreEqual(angle, axisAngle.Angle);
}
[TestMethod]
public void ToVector3_ShouldReturnZeroVector_GivenIdentityQuaternion()
{
Assert.AreEqual(Vector3.Zero, Quaternion.Identity.ToVector3());
}
[TestMethod]
public void ToVector3_ShouldReturnVector_0_PI_0_GivenQuaternionCreatedFrom_PI_0_0()
{
Quaternion quaternion = Quaternion.CreateFromYawPitchRoll(MathF.PI, 0, 0);
var expected = new Vector3(0, MathF.PI, 0);
var actual = quaternion.ToVector3();
Assert.AreEqual(expected.X, actual.X, 1e-5f);
Assert.AreEqual(expected.Y, actual.Y, 1e-5f);
Assert.AreEqual(expected.Z, actual.Z, 1e-5f);
}
}

View File

@ -64,9 +64,9 @@ public static class QuaternionExtensions
float qz = normalized.Z;
float qw = normalized.W;
float x = MathF.Atan2(2 * (qx * qw - qy * qz), 1 - 2 * (qx * qx + qz * qz));
float y = MathF.Asin(2 * (qx * qz + qy * qw));
float z = MathF.Atan2(2 * (qz * qw - qx * qy), 1 - 2 * (qy * qy + qz * qz));
return new Vector3(x, y, z);
float x = MathF.Asin(-2 * (qx * qy - qz * qw));
float y = MathF.Atan2(2 * (qy * qw + qx * qz), 1 - 2 * (qy * qy + qx * qx));
float z = MathF.Atan2(2 * (qx * qw + qy * qz), 1 - 2 * (qz * qz + qw * qw));
return new Vector3(-x, -y, -z);
}
}