129 lines
4.0 KiB
C#
129 lines
4.0 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace StgSharp.Math
|
|
{
|
|
public class Matrix4x2
|
|
{
|
|
internal M128Map _map;
|
|
|
|
internal IntPtr _colum0Ptr;
|
|
internal IntPtr _colum1Ptr;
|
|
|
|
private bool _isTransposed;
|
|
private Matrix2x4 _transpose;
|
|
|
|
public Matrix4x2(
|
|
float a00, float a01,
|
|
float a10, float a11,
|
|
float a20, float a21,
|
|
float a30, float a31
|
|
)
|
|
{
|
|
_colum0Ptr = internalIO.load_internal(a00,a10,a20,a30);
|
|
_colum0Ptr = internalIO.load_internal(a01,a11,a21,a31);
|
|
|
|
_transpose = new Matrix2x4(this);
|
|
}
|
|
|
|
public Matrix4x2(
|
|
IntPtr colum0Ptr,
|
|
IntPtr colum1Ptr
|
|
)
|
|
{
|
|
_colum0Ptr = colum0Ptr;
|
|
_colum1Ptr = colum1Ptr;
|
|
|
|
_transpose = new Matrix2x4(this);
|
|
}
|
|
|
|
public Matrix4x2(Matrix2x4 transpose)
|
|
{
|
|
_transpose = transpose;
|
|
}
|
|
|
|
public unsafe Matrix2x4 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._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;
|
|
|
|
}
|
|
|
|
switch (transposeMode)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|