mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-02-24 04:06:49 +00:00
Throw exception when encountering a singular matrix on matrix inversion. Add indexer: (Matrix4[i, j]) (not implemented yet)
This commit is contained in:
parent
9fd384420d
commit
336e6210c8
|
@ -94,7 +94,8 @@ namespace OpenTK.Math
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return Row0.X * Row1.Y * Row2.Z * Row3.W - Row0.X * Row1.Y * Row2.W * Row3.Z + Row0.X * Row1.Z * Row2.W * Row3.Y - Row0.X * Row1.Z * Row2.Y * Row3.W
|
return
|
||||||
|
Row0.X * Row1.Y * Row2.Z * Row3.W - Row0.X * Row1.Y * Row2.W * Row3.Z + Row0.X * Row1.Z * Row2.W * Row3.Y - Row0.X * Row1.Z * Row2.Y * Row3.W
|
||||||
+ Row0.X * Row1.W * Row2.Y * Row3.Z - Row0.X * Row1.W * Row2.Z * Row3.Y - Row0.Y * Row1.Z * Row2.W * Row3.X + Row0.Y * Row1.Z * Row2.X * Row3.W
|
+ Row0.X * Row1.W * Row2.Y * Row3.Z - Row0.X * Row1.W * Row2.Z * Row3.Y - Row0.Y * Row1.Z * Row2.W * Row3.X + Row0.Y * Row1.Z * Row2.X * Row3.W
|
||||||
- Row0.Y * Row1.W * Row2.X * Row3.Z + Row0.Y * Row1.W * Row2.Z * Row3.X - Row0.Y * Row1.X * Row2.Z * Row3.W + Row0.Y * Row1.X * Row2.W * Row3.Z
|
- Row0.Y * Row1.W * Row2.X * Row3.Z + Row0.Y * Row1.W * Row2.Z * Row3.X - Row0.Y * Row1.X * Row2.Z * Row3.W + Row0.Y * Row1.X * Row2.W * Row3.Z
|
||||||
+ Row0.Z * Row1.W * Row2.X * Row3.Y - Row0.Z * Row1.W * Row2.Y * Row3.X + Row0.Z * Row1.X * Row2.Y * Row3.W - Row0.Z * Row1.X * Row2.W * Row3.Y
|
+ Row0.Z * Row1.W * Row2.X * Row3.Y - Row0.Z * Row1.W * Row2.Y * Row3.X + Row0.Z * Row1.X * Row2.Y * Row3.W - Row0.Z * Row1.X * Row2.W * Row3.Y
|
||||||
|
@ -150,18 +151,9 @@ namespace OpenTK.Math
|
||||||
return Matrix4.Mult(left, right);
|
return Matrix4.Mult(left, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
[CLSCompliant(false)]
|
public float get(int x, int y)
|
||||||
unsafe public static explicit operator float*(Matrix4 mat)
|
|
||||||
{
|
{
|
||||||
return &mat.Row0.X;
|
throw new NotImplementedException();
|
||||||
}
|
|
||||||
|
|
||||||
public static explicit operator IntPtr(Matrix4 mat)
|
|
||||||
{
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
return (IntPtr)(&mat.Row0.X);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -373,6 +365,7 @@ namespace OpenTK.Math
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="mat">The matrix to invert</param>
|
/// <param name="mat">The matrix to invert</param>
|
||||||
/// <returns>The inverse of the given matrix if it has one, or the input if it is singular</returns>
|
/// <returns>The inverse of the given matrix if it has one, or the input if it is singular</returns>
|
||||||
|
/// <exception cref="InvalidOperationException">Thrown if the Matrix4 is singular.</exception>
|
||||||
public static Matrix4 Invert(Matrix4 mat)
|
public static Matrix4 Invert(Matrix4 mat)
|
||||||
{
|
{
|
||||||
int[] colIdx = { 0, 0, 0, 0 };
|
int[] colIdx = { 0, 0, 0, 0 };
|
||||||
|
@ -434,7 +427,8 @@ namespace OpenTK.Math
|
||||||
// check for singular matrix
|
// check for singular matrix
|
||||||
if (pivot == 0.0f)
|
if (pivot == 0.0f)
|
||||||
{
|
{
|
||||||
return mat;
|
throw new InvalidOperationException("Matrix is singular and cannot be inverted.");
|
||||||
|
//return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale row so it has a unit diagonal
|
// Scale row so it has a unit diagonal
|
||||||
|
|
Loading…
Reference in a new issue