Daily update on 20230806 by nitload youmu
This commit is contained in:
@@ -3,80 +3,126 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct matrix4x2 : IEquatable<matrix4x2>
|
||||
public class Matrix4x2
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public vec2d row1;
|
||||
[FieldOffset(8)]
|
||||
public vec2d row2;
|
||||
[FieldOffset(16)]
|
||||
public vec2d row3;
|
||||
[FieldOffset(24)]
|
||||
public vec2d row4;
|
||||
internal M128Map _map;
|
||||
|
||||
public matrix4x2(vec2d r1, vec2d r2, vec2d r3, vec2d r4)
|
||||
{
|
||||
row1 = r1;
|
||||
row2 = r2;
|
||||
row3 = r3;
|
||||
row4 = r4;
|
||||
}
|
||||
internal IntPtr _colum0Ptr;
|
||||
internal IntPtr _colum1Ptr;
|
||||
|
||||
public matrix4x2(
|
||||
float a11, float a12,
|
||||
float a21, float a22,
|
||||
float a31, float a32,
|
||||
float a41, float a42
|
||||
private bool _isTransposed;
|
||||
private Matrix2x4 _transpose;
|
||||
|
||||
public Matrix4x2(
|
||||
float a00, float a01,
|
||||
float a10, float a11,
|
||||
float a20, float a21,
|
||||
float a30, float a31
|
||||
)
|
||||
{
|
||||
row1 = new vec2d(a11, a12);
|
||||
row2 = new vec2d(a21, a22);
|
||||
row3 = new vec2d(a31, a32);
|
||||
row4 = new vec2d(a41, a42);
|
||||
_colum0Ptr = internalIO.load_internal(a00,a10,a20,a30);
|
||||
_colum0Ptr = internalIO.load_internal(a01,a11,a21,a31);
|
||||
|
||||
_transpose = new Matrix2x4(this);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
public Matrix4x2(
|
||||
IntPtr colum0Ptr,
|
||||
IntPtr colum1Ptr
|
||||
)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj.GetType() == typeof(matrix4x2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Equals((matrix4x2)obj);
|
||||
}
|
||||
_colum0Ptr = colum0Ptr;
|
||||
_colum1Ptr = colum1Ptr;
|
||||
|
||||
_transpose = new Matrix2x4(this);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
public Matrix4x2(Matrix2x4 transpose)
|
||||
{
|
||||
return HashCode.Combine(row1, row2, row3, row4);
|
||||
_transpose = transpose;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
public unsafe Matrix2x4 Transpose(TransposeMode transposeMode )
|
||||
{
|
||||
return $"{row1}\n{row2}\n{row3}\n{row4}";
|
||||
}
|
||||
|
||||
bool IEquatable<matrix4x2>.Equals(matrix4x2 other)
|
||||
{
|
||||
if (this.GetHashCode() != other.GetHashCode())
|
||||
if (!_isTransposed)
|
||||
{
|
||||
return false;
|
||||
(*(M128*)_transpose._colum0Ptr).single_0 = (*(M128*)_colum0Ptr).single_0;
|
||||
(*(M128*)_transpose._colum1Ptr).single_0 = (*(M128*)_colum0Ptr).single_1;
|
||||
(*(M128*)_transpose._colum2Ptr).single_0 = (*(M128*)_colum0Ptr).single_2;
|
||||
(*(M128*)_transpose._colum3Ptr).single_0 = (*(M128*)_colum0Ptr).single_3;
|
||||
|
||||
(*(M128*)_transpose._colum0Ptr).single_1 = (*(M128*)_colum1Ptr).single_0;
|
||||
(*(M128*)_transpose._colum1Ptr).single_1 = (*(M128*)_colum1Ptr).single_1;
|
||||
(*(M128*)_transpose._colum2Ptr).single_1 = (*(M128*)_colum1Ptr).single_2;
|
||||
(*(M128*)_transpose._colum3Ptr).single_1 = (*(M128*)_colum1Ptr).single_3;
|
||||
|
||||
_isTransposed = true;
|
||||
|
||||
}
|
||||
else
|
||||
|
||||
switch (transposeMode)
|
||||
{
|
||||
return this.row1 == other.row1
|
||||
&& this.row2 == other.row2
|
||||
&& this.row3 == other.row3
|
||||
&& this.row4 == other.row4;
|
||||
case TransposeMode.New:
|
||||
return new Matrix2x4(
|
||||
internalIO.load_cpy_internal(_transpose._colum0Ptr),
|
||||
internalIO.load_cpy_internal(_transpose._colum1Ptr),
|
||||
internalIO.load_cpy_internal(_transpose._colum2Ptr),
|
||||
internalIO.load_cpy_internal(_transpose._colum3Ptr)
|
||||
);
|
||||
break;
|
||||
case TransposeMode.Copy:
|
||||
return _transpose;
|
||||
break;
|
||||
default:
|
||||
throw new Exception();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Matrix4x2 operator +(Matrix4x2 matrix1, Matrix4x2 matrix2)
|
||||
{
|
||||
return new Matrix4x2(
|
||||
internalIO.addps_internal(matrix1._colum0Ptr,matrix2._colum0Ptr),
|
||||
internalIO.addps_internal(matrix1._colum1Ptr,matrix2._colum1Ptr)
|
||||
);
|
||||
}
|
||||
|
||||
public static Matrix4x2 operator -(Matrix4x2 matrix1, Matrix4x2 matrix2)
|
||||
{
|
||||
return new Matrix4x2(
|
||||
internalIO.subps_internal(matrix1._colum0Ptr, matrix2._colum0Ptr),
|
||||
internalIO.subps_internal(matrix1._colum1Ptr, matrix2._colum1Ptr)
|
||||
);
|
||||
}
|
||||
|
||||
public static Matrix4x2 operator *(Matrix4x2 matrix,float value)
|
||||
{
|
||||
return new Matrix4x2(
|
||||
internalIO.mulps_const_internal(matrix._colum0Ptr,value),
|
||||
internalIO.mulps_const_internal(matrix._colum1Ptr,value)
|
||||
);
|
||||
}
|
||||
|
||||
public static Matrix4x2 operator /(Matrix4x2 matrix, float value)
|
||||
{
|
||||
return new Matrix4x2(
|
||||
internalIO.divps_const_internal(matrix._colum0Ptr,value),
|
||||
internalIO.divps_const_internal(matrix._colum1Ptr,value)
|
||||
);
|
||||
}
|
||||
|
||||
~Matrix4x2()
|
||||
{
|
||||
if (_map == null)
|
||||
{
|
||||
internalIO.deinitM128_internal(_colum0Ptr);
|
||||
internalIO.deinitM128_internal(_colum1Ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user