79 lines
2.2 KiB
C#
79 lines
2.2 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
using static StgSharp.Graphics.GLFWwndconfig;
|
|
|
|
namespace StgSharp.Math
|
|
{
|
|
|
|
|
|
[StructLayout(LayoutKind.Explicit,Size = (16 + 8) * sizeof(float) + sizeof(bool), Pack = 16)]
|
|
public struct Matrix4x2
|
|
{
|
|
[FieldOffset(0)] internal Mat2 mat;
|
|
[FieldOffset(8 * sizeof(float))] internal Mat4 transpose;
|
|
[FieldOffset((16 + 8) * sizeof(float))] internal bool isTranspose;
|
|
|
|
|
|
unsafe public Matrix4x2(
|
|
float a00,float a01,
|
|
float a10,float a11,
|
|
float a20,float a21,
|
|
float a30,float a31
|
|
)
|
|
{
|
|
M128* c0ref = internalIO.loadptr_internal(a00, a10, a20, a30);
|
|
M128* c1ref = internalIO.loadptr_internal(a01, a11, a21, a31);
|
|
|
|
mat.colum0 = *c0ref;
|
|
mat.colum1 = *c1ref;
|
|
|
|
/**/
|
|
internalIO.deinitM128_internal(c0ref);
|
|
internalIO.deinitM128_internal(c1ref);
|
|
}
|
|
|
|
unsafe internal Matrix4x2(Mat2 mat)
|
|
{
|
|
this.mat = mat;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static unsafe Matrix4x2 operator +(Matrix4x2 left, Matrix4x2 right)
|
|
{
|
|
Mat2* p = internalIO.add_mat2(&left.mat, &right.mat);
|
|
Matrix4x2 ret = new Matrix4x2(*p);
|
|
internalIO.deinit_mat2(p);
|
|
return ret;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static unsafe Matrix4x2 operator -(Matrix4x2 left, Matrix4x2 right)
|
|
{
|
|
Mat2* p = internalIO.sub_mat2(&left.mat, &right.mat);
|
|
Matrix4x2 ret = new Matrix4x2(*p);
|
|
internalIO.deinit_mat2(p);
|
|
return ret;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
internal unsafe void InternalTranspose()
|
|
{
|
|
if (!isTranspose)
|
|
{
|
|
fixed (Mat2* source = &this.mat)
|
|
fixed (Mat4* target = &this.transpose)
|
|
{
|
|
internalIO.Transpose2to4_internal(source, target);
|
|
}
|
|
|
|
isTranspose = true;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|