1
0
mirror of https://github.com/oliverbooth/VpSharp synced 2024-11-22 19:18:47 +00:00

Add ToQuaternion to Rotation struct

This commit is contained in:
Oliver Booth 2022-12-08 17:55:36 +00:00
parent 703f099187
commit 2f3069d1bf
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634

View File

@ -172,6 +172,24 @@ public readonly struct Rotation : IEquatable<Rotation>, IFormattable
return HashCode.Combine(Angle, Roll, Tilt, Yaw); return HashCode.Combine(Angle, Roll, Tilt, Yaw);
} }
/// <summary>
/// Converts this rotation to a quaternion.
/// </summary>
/// <returns>An instance of <see cref="Quaternion" /> representing the same rotation as this instance.</returns>
public Quaternion ToQuaternion()
{
if (double.IsPositiveInfinity(Angle))
{
var yaw = (float)Yaw.DegreesToRadians();
var tilt = (float)Tilt.DegreesToRadians();
var roll = (float)Roll.DegreesToRadians();
return Quaternion.CreateFromYawPitchRoll(yaw, tilt, roll);
}
var axis = new Vector3d(Tilt, Yaw, Roll);
return Quaternion.CreateFromAxisAngle((Vector3)axis, (float)Angle);
}
/// <summary> /// <summary>
/// Returns the string representation of these coordinates. /// Returns the string representation of these coordinates.
/// </summary> /// </summary>