feat: added basic 4d matrix
This commit is contained in:
@@ -167,7 +167,7 @@ public readonly struct Quaternion(float x, float y, float z, float w) : IEquatab
|
||||
Vector3D right = up.Cross(forward).Normalized;
|
||||
Vector3D newUp = forward.Cross(right);
|
||||
|
||||
System.Numerics.Matrix4x4 rot = new(
|
||||
Matrix4x4 rot = new(
|
||||
right.X, right.Y, right.Z, 0f,
|
||||
newUp.X, newUp.Y, newUp.Z, 0f,
|
||||
forward.X, forward.Y, forward.Z, 0f,
|
||||
@@ -297,11 +297,11 @@ public readonly struct Quaternion(float x, float y, float z, float w) : IEquatab
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the <see cref="System.Numerics.Matrix4x4"/> from given <see cref="Quaternion"/>.
|
||||
/// Calculates the <see cref="Matrix4x4"/> from given <see cref="Quaternion"/>.
|
||||
/// </summary>
|
||||
/// <param name="quaternion">The rotation <see cref="Quaternion"/>.</param>
|
||||
/// <returns>The rotation <see cref="System.Numerics.Matrix4x4"/> calculated by the given <see cref="Quaternion"/>.</returns>
|
||||
public static System.Numerics.Matrix4x4 ToRotationMatrix4x4(Quaternion quaternion)
|
||||
/// <returns>The rotation <see cref="Matrix4x4"/> calculated by the given <see cref="Quaternion"/>.</returns>
|
||||
public static Matrix4x4 ToRotationMatrix4x4(Quaternion quaternion)
|
||||
{
|
||||
float m00 = 1 - 2 * (quaternion.Y * quaternion.Y + quaternion.Z * quaternion.Z);
|
||||
float m01 = 2 * (quaternion.X * quaternion.Y - quaternion.W * quaternion.Z);
|
||||
@@ -332,11 +332,11 @@ public readonly struct Quaternion(float x, float y, float z, float w) : IEquatab
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the <see cref="Quaternion"/> from given <see cref="System.Numerics.Matrix4x4"/>.
|
||||
/// Calculates the <see cref="Quaternion"/> from given <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="martix">The rotation <see cref="System.Numerics.Matrix4x4"/>.</param>
|
||||
/// <returns>The rotation <see cref="Quaternion"/> calculated by the given <see cref="System.Numerics.Matrix4x4"/>.</returns>
|
||||
public static Quaternion FromRotationMatrix4x4(System.Numerics.Matrix4x4 martix)
|
||||
/// <param name="martix">The rotation <see cref="Matrix4x4"/>.</param>
|
||||
/// <returns>The rotation <see cref="Quaternion"/> calculated by the given <see cref="Matrix4x4"/>.</returns>
|
||||
public static Quaternion FromRotationMatrix4x4(Matrix4x4 martix)
|
||||
{
|
||||
float trace = martix.M11 + martix.M22 + martix.M33;
|
||||
float w, x, y, z;
|
||||
@@ -459,7 +459,7 @@ public static class QuaternionExtensions
|
||||
public static float Dot(this Quaternion left, Quaternion right) => Quaternion.Dot(left, right);
|
||||
|
||||
/// <inheritdoc cref="Quaternion.ToRotationMatrix4x4(Quaternion, Quaternion)" />
|
||||
public static System.Numerics.Matrix4x4 ToRotationMatrix4x4(this Quaternion quaternion) => Quaternion.ToRotationMatrix4x4(quaternion);
|
||||
public static Matrix4x4 ToRotationMatrix4x4(this Quaternion quaternion) => Quaternion.ToRotationMatrix4x4(quaternion);
|
||||
|
||||
/// <inheritdoc cref="Quaternion.FromAxisAngle(Vector3D, float)" />
|
||||
public static Quaternion CreateRotation(this Vector3D axis, float angle) => Quaternion.FromAxisAngle(axis, angle);
|
||||
|
||||
Reference in New Issue
Block a user