daily update on 20230829 by nitload youmu

This commit is contained in:
Nitload
2023-08-29 22:29:47 +08:00
parent 8aac9fee87
commit 1fcbfb972b
125 changed files with 6505 additions and 2077 deletions
+108 -54
View File
@@ -28,22 +28,10 @@ namespace StgSharp.Math
float a30, float a31, float a32, float a33
)
{
M128* c0ref = internalIO.loadptr_internal(a00, a10, a20, a30);
M128* c1ref = internalIO.loadptr_internal(a01, a11, a21, a31);
M128* c2ref = internalIO.loadptr_internal(a02, a12, a22, a32);
M128* c3ref = internalIO.loadptr_internal(a03, a13, a23, a33);
mat.colum0 = *c0ref;
mat.colum1 = *c1ref;
mat.colum2 = *c2ref;
mat.colum3 = *c3ref;
/**/
internalIO.deinitM128_internal(c0ref);
internalIO.deinitM128_internal(c1ref);
internalIO.deinitM128_internal(c2ref);
internalIO.deinitM128_internal(c3ref);
/**/
mat.colum0 = new Vector4(a00, a10, a20, a30);
mat.colum0 = new Vector4(a01, a11, a21, a31);
mat.colum0 = new Vector4(a02, a12, a22, a32);
mat.colum0 = new Vector4(a03, a13, a23, a33);
}
@@ -60,22 +48,44 @@ namespace StgSharp.Math
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.a00 )
fixed (float* p = &this.transpose.m00 )
{
ulong pbit = (ulong)p
+ (ulong)sizeof(M128) * (ulong)rowNum
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
return *(float*)pbit;
}
}
set
{
if (rowNum > 3 || rowNum < 0)
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 3 || columNum < 0)
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
*(float*)pbit = value;
}
isTransposed = false;
}
}
internal Matrix4x4(
ref M128 vec0,
ref M128 vec1,
ref M128 vec2,
ref M128 vec3
Vector4 vec0,
Vector4 vec1,
Vector4 vec2,
Vector4 vec3
)
{
mat.colum0 = vec0;
@@ -90,67 +100,111 @@ namespace StgSharp.Math
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x4 operator +(Matrix4x4 mat1, Matrix4x4 Mat2)
public static unsafe Matrix4x4 operator +(Matrix4x4 left, Matrix4x4 right)
{
Mat4* refret = internalIO.add_mat4(ref mat1.mat, ref Mat2.mat);
Matrix4x4 ret = new Matrix4x4(*refret);
internalIO.deinit_mat4(refret);
return ret;
return new Matrix4x4(
Mat4.add( right.mat,left.mat)
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x4 operator -(Matrix4x4 mat1, Matrix4x4 Mat2)
public static unsafe Matrix4x4 operator -(Matrix4x4 left, Matrix4x4 right)
{
Mat4* refret = internalIO.sub_mat4(ref mat1.mat, ref Mat2.mat);
Matrix4x4 ret = new Matrix4x4(*refret);
internalIO.deinit_mat4(refret);
return ret;
return new Matrix4x4(
Mat4.sub(right.mat, left.mat)
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x4 operator *(Matrix4x4 mat, float value)
{
Mat4* refret = internalIO.mul_const(ref mat.mat, value);
Matrix4x4 ret = new Matrix4x4(*refret);
internalIO.deinit_mat4(refret);
return ret;
return new Matrix4x4(
mat.mat.colum0 * value,
mat.mat.colum1 * value,
mat.mat.colum2 * value,
mat.mat.colum3 * value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x2 operator *(Matrix4x4 left, Matrix4x2 right)
{
left.InternalTranspose();
Mat4 tr = left.transpose;
return new Matrix4x2(
internalIO.mulps_sum_internal(&tr.colum0, &right.mat.colum0),
internalIO.mulps_sum_internal(&tr.colum0, &right.mat.colum1),
internalIO.mulps_sum_internal(&tr.colum1, &right.mat.colum0),
internalIO.mulps_sum_internal(&tr.colum1, &right.mat.colum1),
internalIO.mulps_sum_internal(&tr.colum2, &right.mat.colum0),
internalIO.mulps_sum_internal(&tr.colum2, &right.mat.colum1),
internalIO.mulps_sum_internal(&tr.colum3, &right.mat.colum0),
internalIO.mulps_sum_internal(&tr.colum3, &right.mat.colum1)
);
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
Vector4.Dot(left.transpose.colum3, right.mat.colum1)
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x4 operator *(Matrix4x4 left, Matrix4x4 right)
public static Matrix4x3 operator *(Matrix4x4 left, Matrix4x3 right)
{
left.InternalTranspose();
Mat4* p = internalIO.mul_4_4(&left.transpose, &right.mat);
Matrix4x4 ret = new Matrix4x4(*p);
internalIO.deinit_mat4(p);
return ret;
return new Matrix4x3(
Vector4.Dot(left.transpose.colum0,right.mat.colum0),
Vector4.Dot(left.transpose.colum0,right.mat.colum1),
Vector4.Dot(left.transpose.colum0,right.mat.colum2),
Vector4.Dot(left.transpose.colum1,right.mat.colum0),
Vector4.Dot(left.transpose.colum1,right.mat.colum1),
Vector4.Dot(left.transpose.colum1,right.mat.colum2),
Vector4.Dot(left.transpose.colum2,right.mat.colum0),
Vector4.Dot(left.transpose.colum2,right.mat.colum1),
Vector4.Dot(left.transpose.colum2,right.mat.colum2),
Vector4.Dot(left.transpose.colum3,right.mat.colum0),
Vector4.Dot(left.transpose.colum3,right.mat.colum1),
Vector4.Dot(left.transpose.colum3,right.mat.colum2)
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x4 operator *(Matrix4x4 left, Matrix4x4 right)
{
left.InternalTranspose();
return new Matrix4x4(
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
Vector4.Dot(left.transpose.colum0, right.mat.colum3),
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
Vector4.Dot(left.transpose.colum1, right.mat.colum3),
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
Vector4.Dot(left.transpose.colum2, right.mat.colum3),
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
Vector4.Dot(left.transpose.colum3, right.mat.colum1),
Vector4.Dot(left.transpose.colum3, right.mat.colum2),
Vector4.Dot(left.transpose.colum3, right.mat.colum3)
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe float Det()
{
InternalTranspose();
fixed (Matrix4x4* _this = &this)
fixed (Mat4* _this = &mat, _trans = &transpose)
{
return internalIO.det_mat4(_this);
return internalIO.det_mat4(_this,_trans);
}
}