146 lines
3.9 KiB
C#
146 lines
3.9 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace StgSharp.Math
|
|
{
|
|
public enum TransposeMode
|
|
{
|
|
New,
|
|
Copy
|
|
}
|
|
|
|
|
|
|
|
public unsafe class Matrix4x4:IDisposable
|
|
{
|
|
|
|
|
|
public static readonly Matrix4x4 Unit
|
|
= new Matrix4x4(
|
|
1,0,0,0,
|
|
0,1,0,0,
|
|
0,0,1,0,
|
|
0,0,0,1
|
|
);
|
|
|
|
|
|
internal M128Map M128Map;
|
|
|
|
//pointers of 4 colums are collected
|
|
//in the array referred by these pointer.
|
|
internal M128matMap _matMap;
|
|
|
|
|
|
//define if this matrix has correctly stored its transpose matrix
|
|
internal bool isTransposed = false;
|
|
|
|
//store the transpose mat of this one to avoid calculate again
|
|
internal M128matMap _transpose;
|
|
|
|
private bool disposedValue;
|
|
|
|
internal Matrix4x4()
|
|
{
|
|
_matMap = new M128matMap(
|
|
internalIO.load_internal(0, 0, 0, 0),
|
|
internalIO.load_internal(0, 0, 0, 0),
|
|
internalIO.load_internal(0, 0, 0, 0),
|
|
internalIO.load_internal(0, 0, 0, 0)
|
|
);
|
|
|
|
}
|
|
|
|
//constructor used to transform a matMap from C to a Matrix class,
|
|
//the original matMap will be cleaned up after transformation
|
|
internal Matrix4x4(
|
|
ref M128matMap matMap
|
|
)
|
|
{
|
|
_matMap = matMap;
|
|
internalIO .deinitMatmap_sse_internal( ref matMap );
|
|
|
|
}
|
|
|
|
internal Matrix4x4(
|
|
IntPtr c0Ptr,
|
|
IntPtr c1Ptr,
|
|
IntPtr c2Ptr,
|
|
IntPtr c3Ptr
|
|
)
|
|
{
|
|
_matMap = new M128matMap(c0Ptr,c1Ptr,c2Ptr,c3Ptr);
|
|
}
|
|
|
|
public Matrix4x4(
|
|
float a00,float a01,float a02,float a03,
|
|
float a10,float a11,float a12,float a13,
|
|
float a20,float a21,float a22,float a23,
|
|
float a30,float a31,float a32,float a33
|
|
)
|
|
{
|
|
_matMap = new M128matMap(
|
|
internalIO.load_internal(a00, a10, a20, a30),
|
|
internalIO.load_internal(a01, a11, a21, a31),
|
|
internalIO.load_internal(a02, a12, a22, a32),
|
|
internalIO.load_internal(a03, a13, a23, a33)
|
|
);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Matrix4x4 Transpose
|
|
{
|
|
get {
|
|
if (isTransposed)
|
|
{
|
|
internalIO.deinitMatmap_sse_internal(ref _transpose);
|
|
|
|
}
|
|
return new Matrix4x4(
|
|
internalIO.load_cpy_internal(_transpose.colum0Ptr),
|
|
internalIO.load_cpy_internal(_transpose.colum1Ptr),
|
|
internalIO.load_cpy_internal(_transpose.colum2Ptr),
|
|
internalIO.load_cpy_internal(_transpose.colum3Ptr)
|
|
);
|
|
}
|
|
}
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
{
|
|
if (!disposedValue)
|
|
{
|
|
if (disposing)
|
|
{
|
|
// TODO: 释放托管状态(托管对象)
|
|
}
|
|
|
|
// TODO: 释放未托管的资源(未托管的对象)并重写终结器
|
|
// TODO: 将大型字段设置为 null
|
|
disposedValue = true;
|
|
}
|
|
}
|
|
|
|
// // TODO: 仅当“Dispose(bool disposing)”拥有用于释放未托管资源的代码时才替代终结器
|
|
// ~Matrix4x4()
|
|
// {
|
|
// // 不要更改此代码。请将清理代码放入“Dispose(bool disposing)”方法中
|
|
// Dispose(disposing: false);
|
|
// }
|
|
|
|
public void Dispose()
|
|
{
|
|
// 不要更改此代码。请将清理代码放入“Dispose(bool disposing)”方法中
|
|
Dispose(disposing: true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|
|
|
|
|
|
}
|