daily update on 20230829 by nitload youmu
This commit is contained in:
@@ -1,133 +1,182 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
|
||||
/*
|
||||
public class Matrix2x3
|
||||
[StructLayout(LayoutKind.Explicit, Size = (3 + 2) * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
|
||||
public struct Matrix2x3
|
||||
{
|
||||
internal M128Map _map;
|
||||
|
||||
internal IntPtr _colum0Ptr;
|
||||
internal IntPtr _colum1Ptr;
|
||||
internal IntPtr _colum2Ptr;
|
||||
|
||||
private bool _isTransposed;
|
||||
private Matrix3x2 _transpose;
|
||||
[FieldOffset(0)] internal Mat3 mat;
|
||||
[FieldOffset(3 * 4 * sizeof(float))] internal Mat2 transpose;
|
||||
[FieldOffset(5 * 4 * sizeof(float))] internal bool isTransposed;
|
||||
|
||||
public Matrix2x3(
|
||||
float a00, float a01, float a02,
|
||||
float a10, float a11, float a12
|
||||
float a00,float a01,float a02,
|
||||
float a10,float a11,float a12
|
||||
)
|
||||
{
|
||||
_colum0Ptr = internalIO.load_internal(a00,a10,0,0);
|
||||
_colum0Ptr = internalIO.load_internal(a01,a11,0,0);
|
||||
_colum0Ptr = internalIO.load_internal(a02,a12,0,0);
|
||||
|
||||
_transpose = new Matrix3x2(this);
|
||||
mat.colum0 = new Vector4(a00, a10, 0, 0);
|
||||
mat.colum1 = new Vector4(a01, a11, 0, 0);
|
||||
mat.colum2 = new Vector4(a02, a12, 0, 0);
|
||||
}
|
||||
|
||||
internal Matrix2x3(
|
||||
IntPtr colum0Ptr,
|
||||
IntPtr colum1Ptr,
|
||||
IntPtr colum2Ptr
|
||||
Vector4 c0,
|
||||
Vector4 c1,
|
||||
Vector4 c2
|
||||
)
|
||||
{
|
||||
_colum0Ptr = colum0Ptr;
|
||||
_colum1Ptr = colum1Ptr;
|
||||
_colum2Ptr = colum2Ptr;
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
mat.colum2 = c2;
|
||||
}
|
||||
|
||||
_transpose = new Matrix3x2(this);
|
||||
public unsafe float this[int rowNum, int columNum]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowNum > 1 || rowNum < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if (columNum > 2 || 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;
|
||||
return *(float*)pbit;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (rowNum > 1 || rowNum < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if (columNum > 2 || 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;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if (!isTransposed)
|
||||
{
|
||||
fixed(Mat3* source = &this.mat)
|
||||
fixed(Mat2* target = &this.transpose)
|
||||
{
|
||||
internalIO.Transpose3to2_internal(source, target);
|
||||
}
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public Matrix2x3(Matrix3x2 transpose)
|
||||
{
|
||||
_transpose = transpose;
|
||||
}
|
||||
|
||||
public unsafe Matrix3x2 Transpose(TransposeMode transposeMode)
|
||||
{
|
||||
if (_isTransposed)
|
||||
{
|
||||
(*(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;
|
||||
|
||||
(*(M128*)_transpose._colum0Ptr).single_2 = (*(M128*)_colum2Ptr).single_0;
|
||||
(*(M128*)_transpose._colum1Ptr).single_2 = (*(M128*)_colum2Ptr).single_1;
|
||||
|
||||
_isTransposed = true;
|
||||
}
|
||||
switch (transposeMode)
|
||||
{
|
||||
case TransposeMode.New:
|
||||
return new Matrix3x2(
|
||||
_transpose._colum0Ptr,
|
||||
_transpose._colum1Ptr
|
||||
);
|
||||
break;
|
||||
case TransposeMode.Copy:
|
||||
return _transpose;
|
||||
break;
|
||||
default:
|
||||
throw new Exception();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static Matrix2x3 operator +(Matrix2x3 matrix1, Matrix2x3 matrix2)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x3 operator +(Matrix2x3 left, Matrix2x3 right)
|
||||
{
|
||||
return new Matrix2x3(
|
||||
internalIO.addps_internal(matrix1._colum0Ptr,matrix2._colum0Ptr),
|
||||
internalIO.addps_internal(matrix1._colum1Ptr,matrix2._colum1Ptr),
|
||||
internalIO.addps_internal(matrix1._colum2Ptr,matrix2._colum2Ptr)
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2
|
||||
);
|
||||
}
|
||||
|
||||
public static Matrix2x3 operator -(Matrix2x3 matrix1, Matrix2x3 matrix2)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x3 operator -(Matrix2x3 left, Matrix2x3 right)
|
||||
{
|
||||
return new Matrix2x3(
|
||||
internalIO.subps_internal(matrix1._colum0Ptr, matrix2._colum0Ptr),
|
||||
internalIO.subps_internal(matrix1._colum1Ptr, matrix2._colum1Ptr),
|
||||
internalIO.subps_internal(matrix1._colum2Ptr, matrix2._colum2Ptr)
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum1 - right.mat.colum1,
|
||||
left.mat.colum2 - right.mat.colum2
|
||||
);
|
||||
}
|
||||
|
||||
public static Matrix2x3 operator *(Matrix2x3 matrix, float value)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x3 operator *(Matrix2x3 mat, float value)
|
||||
{
|
||||
return new Matrix2x3(
|
||||
internalIO.mulps_const_internal(matrix._colum0Ptr, value),
|
||||
internalIO.mulps_const_internal(matrix._colum1Ptr, value),
|
||||
internalIO.mulps_const_internal(matrix._colum2Ptr, value)
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value
|
||||
);
|
||||
}
|
||||
|
||||
public static Matrix2x3 operator /(Matrix2x3 matrix, float value)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x3 operator /(Matrix2x3 mat, float value)
|
||||
{
|
||||
return new Matrix2x3(
|
||||
internalIO.divps_const_internal(matrix._colum0Ptr, value),
|
||||
internalIO.divps_const_internal(matrix._colum1Ptr, value),
|
||||
internalIO.divps_const_internal(matrix._colum2Ptr, value)
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value
|
||||
);
|
||||
}
|
||||
|
||||
~Matrix2x3()
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x2 operator *(Matrix2x3 left, Matrix3x2 right)
|
||||
{
|
||||
if (_map == null)
|
||||
{
|
||||
internalIO.deinitM128_internal(_colum0Ptr);
|
||||
internalIO.deinitM128_internal(_colum1Ptr);
|
||||
internalIO.deinitM128_internal(_colum2Ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
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.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x3 operator *(Matrix2x3 left, Matrix3x3 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.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x4 operator *(Matrix2x3 left, Matrix3x4 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.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)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user