daily update on 20230829 by nitload youmu
This commit is contained in:
@@ -1,122 +1,151 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
/*
|
||||
public class Matrix2x2
|
||||
[StructLayout(LayoutKind.Explicit, Size = 2 * 2 * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
|
||||
public struct Matrix2x2
|
||||
{
|
||||
public static Matrix2x2 Unit
|
||||
= new Matrix2x2(
|
||||
1,0,
|
||||
0,1
|
||||
);
|
||||
|
||||
internal M128Map _map;
|
||||
|
||||
internal IntPtr _colum0Ptr;
|
||||
internal IntPtr _colum1Ptr;
|
||||
|
||||
private bool _isTranpsed;
|
||||
private Matrix2x2 _transpose;
|
||||
[FieldOffset(0)]
|
||||
internal Mat2 mat;
|
||||
[FieldOffset(2 * 4 * sizeof(float))]
|
||||
internal Mat2 transpose;
|
||||
[FieldOffset(2 * 2 * 4 * sizeof(float))]
|
||||
internal bool isTransposed;
|
||||
|
||||
public Matrix2x2(
|
||||
float a00, float a01,
|
||||
float a10, float a11
|
||||
)
|
||||
)
|
||||
{
|
||||
_colum0Ptr = internalIO.load_internal(a00, a10, 0, 0);
|
||||
_colum0Ptr = internalIO.load_internal(a01, a11, 0, 0);
|
||||
|
||||
_transpose = new Matrix2x2(this);
|
||||
mat.colum0 = new Vector4(a00,a10,0,0);
|
||||
mat.colum1 = new Vector4(a01,a11,0,0);
|
||||
}
|
||||
|
||||
internal Matrix2x2(
|
||||
IntPtr colum0Ptr,
|
||||
IntPtr colum1Ptr
|
||||
Vector4 c0,
|
||||
Vector4 c1
|
||||
)
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
}
|
||||
|
||||
internal Matrix2x2(
|
||||
Mat2 mat
|
||||
)
|
||||
{
|
||||
_colum0Ptr = colum0Ptr;
|
||||
_colum1Ptr = colum1Ptr;
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
internal Matrix2x2(Matrix2x2 transpose)
|
||||
public Matrix2x2 Transpose
|
||||
{
|
||||
_transpose = transpose;
|
||||
}
|
||||
|
||||
public unsafe Matrix2x2 Transpose(TransposeMode transposeMode)
|
||||
{
|
||||
if (_isTranpsed)
|
||||
get
|
||||
{
|
||||
(*(M128*)_transpose._colum0Ptr).single_0 = (*(M128*)_colum0Ptr).single_0;
|
||||
(*(M128*)_transpose._colum1Ptr).single_0 = (*(M128*)_colum0Ptr).single_1;
|
||||
|
||||
(*(M128*)_transpose._colum0Ptr).single_1 = (*(M128*)_colum1Ptr).single_0;
|
||||
(*(M128*)_transpose._colum1Ptr).single_1 = (*(M128*)_colum1Ptr).single_1;
|
||||
}
|
||||
|
||||
switch (transposeMode)
|
||||
{
|
||||
case TransposeMode.New:
|
||||
return new Matrix2x2(
|
||||
internalIO.load_cpy_internal(_transpose._colum0Ptr),
|
||||
internalIO.load_cpy_internal(_transpose._colum1Ptr)
|
||||
);
|
||||
break;
|
||||
case TransposeMode.Copy:
|
||||
return _transpose;
|
||||
break;
|
||||
default:
|
||||
throw new Exception();
|
||||
break;
|
||||
InternalTranspose();
|
||||
return new Matrix2x2(this.transpose);
|
||||
}
|
||||
}
|
||||
|
||||
public static Matrix2x2 operator +(Matrix2x2 matrix1, Matrix2x2 matrix2)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void InternalTranspose()
|
||||
{
|
||||
return new Matrix2x2(
|
||||
internalIO.addps_internal(matrix1._colum0Ptr, matrix2._colum0Ptr),
|
||||
internalIO.addps_internal(matrix1._colum1Ptr, matrix2._colum1Ptr)
|
||||
);
|
||||
}
|
||||
|
||||
public static Matrix2x2 operator -(Matrix2x2 matrix1, Matrix2x2 matrix2)
|
||||
{
|
||||
return new Matrix2x2(
|
||||
internalIO.subps_internal(matrix1._colum0Ptr, matrix2._colum0Ptr),
|
||||
internalIO.subps_internal(matrix1._colum1Ptr, matrix2._colum1Ptr)
|
||||
);
|
||||
}
|
||||
|
||||
public static Matrix2x2 operator *(Matrix2x2 matrix1, float value)
|
||||
{
|
||||
return new Matrix2x2(
|
||||
internalIO.mulps_const_internal(matrix1._colum0Ptr, value),
|
||||
internalIO.mulps_const_internal(matrix1._colum1Ptr, value)
|
||||
);
|
||||
}
|
||||
|
||||
public static Matrix2x2 operator /(Matrix2x2 matrix1, float value)
|
||||
{
|
||||
return new Matrix2x2(
|
||||
internalIO.divps_const_internal(matrix1._colum0Ptr, value),
|
||||
internalIO.divps_const_internal(matrix1._colum1Ptr, value)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
~Matrix2x2()
|
||||
{
|
||||
if (_map == null)
|
||||
if (!isTransposed)
|
||||
{
|
||||
internalIO.deinitM128_internal(_colum0Ptr);
|
||||
internalIO.deinitM128_internal(_colum1Ptr);
|
||||
transpose = mat;
|
||||
float cache = transpose.m10;
|
||||
transpose.m10 = transpose.m01;
|
||||
transpose.m01 = cache;
|
||||
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix2x2 operator +(Matrix2x2 left, Matrix2x2 right)
|
||||
{
|
||||
Mat2* refmat = internalIO.add_mat2(&left.mat, &right.mat);
|
||||
Matrix2x2 ret = new Matrix2x2(*refmat);
|
||||
internalIO.deinit_mat2(refmat);
|
||||
return ret;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x2 operator -(Matrix2x2 left, Matrix2x2 right)
|
||||
{
|
||||
return new Matrix2x2(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x2 operator *(Matrix2x2 mat, float value)
|
||||
{
|
||||
return new Matrix2x2(
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x2 operator /(Matrix2x2 mat, float value)
|
||||
{
|
||||
return new Matrix2x2(
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x2 operator *(Matrix2x2 left, Matrix2x2 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix2x2(
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x3 operator *(Matrix2x2 left, Matrix2x3 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix2x3(
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x4 operator *(Matrix2x2 left, Matrix2x4 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix2x4(
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**/
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user