daily update on 20230829 by nitload youmu
This commit is contained in:
@@ -28,10 +28,10 @@ namespace StgSharp
|
||||
|
||||
}
|
||||
|
||||
internal static void InitM128map(Pool target)
|
||||
internal static void InitVector4map(Pool target)
|
||||
{
|
||||
M128Map map = new M128Map();
|
||||
TimeLine.GetCurrentPool()._m128mapContainer.Add(map);
|
||||
Vector4Map map = new Vector4Map();
|
||||
TimeLine.GetCurrentPool()._Vector4mapContainer.Add(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,31 +18,31 @@ namespace StgSharp
|
||||
/**/
|
||||
}
|
||||
|
||||
internal static M128Map GetAvailabem128map()
|
||||
internal static Vector4Map GetAvailabeVector4map()
|
||||
{
|
||||
Pool p = TimeLine.GetCurrentPool();
|
||||
M128Map lastMap = p._m128mapContainer.Tail;
|
||||
Vector4Map lastMap = p._Vector4mapContainer.Tail;
|
||||
|
||||
if (lastMap.isFull)
|
||||
{
|
||||
lastMap = new M128Map();
|
||||
p._m128mapContainer.Add(lastMap);
|
||||
lastMap = new Vector4Map();
|
||||
p._Vector4mapContainer.Add(lastMap);
|
||||
}
|
||||
|
||||
return lastMap;
|
||||
}
|
||||
|
||||
internal static long GetAvailableM128ptr()
|
||||
internal static long GetAvailableVector4ptr()
|
||||
{
|
||||
Pool p = TimeLine.GetCurrentPool();
|
||||
M128Map lastMap = p._m128mapContainer.Tail;
|
||||
Vector4Map lastMap = p._Vector4mapContainer.Tail;
|
||||
|
||||
if (lastMap.isFull)
|
||||
{
|
||||
lastMap = new M128Map();
|
||||
p._m128mapContainer.Add(lastMap);
|
||||
lastMap = new Vector4Map();
|
||||
p._Vector4mapContainer.Add(lastMap);
|
||||
}
|
||||
long ptr = lastMap.RegistManagedM128Ptr();
|
||||
long ptr = lastMap.RegistManagedVector4Ptr();
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@@ -7,15 +7,15 @@ namespace StgSharp
|
||||
{
|
||||
internal static partial class internalIO
|
||||
{
|
||||
[DllImport("StgSharpGraphic.dll",EntryPoint = "loadGLApi",
|
||||
[DllImport("StgSharpGraphic",EntryPoint = "loadGLApi",
|
||||
CallingConvention = CallingConvention.Cdecl,CharSet =CharSet.Ansi)]
|
||||
internal static extern GraphicIOPack InternalInitGraphicApi();
|
||||
|
||||
[DllImport("StgSharpGraphic.dll",EntryPoint = "initGL",
|
||||
[DllImport("StgSharpGraphic",EntryPoint = "initGL",
|
||||
CallingConvention = CallingConvention.Cdecl,CharSet = CharSet.Ansi)]
|
||||
internal static extern unsafe void InternalInitGL();
|
||||
|
||||
[DllImport("StgSharpGraphic.dll",EntryPoint = "initGLAD",
|
||||
[DllImport("StgSharpGraphic",EntryPoint = "initGLAD",
|
||||
CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
||||
internal static extern unsafe int InternalInitGLAD();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Graphics
|
||||
@@ -9,7 +10,7 @@ namespace StgSharp.Graphics
|
||||
{
|
||||
public int width;
|
||||
public int height;
|
||||
public M128 color;
|
||||
public Vector4 color;
|
||||
public byte[] name;
|
||||
}
|
||||
|
||||
@@ -44,7 +45,7 @@ namespace StgSharp.Graphics
|
||||
}
|
||||
|
||||
/*
|
||||
public M128 Color
|
||||
public Vector4 Color
|
||||
{
|
||||
get => info.color;
|
||||
set => info.color = value;
|
||||
|
||||
@@ -103,5 +103,11 @@ namespace StgSharp
|
||||
counter.QuickSub();
|
||||
return counter;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace StgSharp
|
||||
{
|
||||
public class Pool
|
||||
{
|
||||
internal LinkedList<M128Map> _m128mapContainer;
|
||||
internal LinkedList<Vector4Map> _Vector4mapContainer;
|
||||
internal LinkedList<IPlainGeometry> _geometryContainer;
|
||||
internal LinkedList<IEntity> _bulletContainer;
|
||||
internal LinkedList<IEntity> _awardContainer;
|
||||
@@ -29,7 +29,7 @@ namespace StgSharp
|
||||
|
||||
private void initContainers()
|
||||
{
|
||||
_m128mapContainer = new LinkedList<M128Map>();
|
||||
_Vector4mapContainer = new LinkedList<Vector4Map>();
|
||||
_bulletContainer = new LinkedList<IEntity>();
|
||||
_awardContainer = new LinkedList<IEntity>();
|
||||
_enemyContainer = new LinkedList<IEntity>();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -14,21 +15,21 @@ namespace StgSharp
|
||||
|
||||
#region load
|
||||
|
||||
[DllImport(dllName: "StgSharpGraphic.dll", EntryPoint = "load",
|
||||
[DllImport(dllName: "StgSharpGraphic", EntryPoint = "load",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern ref M128 load_internal(float x,float y, float z, float w);
|
||||
internal static extern ref Vector4 load_internal(float x,float y, float z, float w);
|
||||
|
||||
[DllImport(dllName: "StgSharpGraphic.dll", EntryPoint = "load",
|
||||
[DllImport(dllName: "StgSharpGraphic", EntryPoint = "load",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static unsafe extern M128* loadptr_internal(float x, float y, float z, float w);
|
||||
internal static unsafe extern Vector4* loadptr_internal(float x, float y, float z, float w);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll",EntryPoint = "load_matmap",
|
||||
[DllImport("StgSharpGraphic",EntryPoint = "load_matmap",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern IntPtr load_mat(IntPtr c0, IntPtr c1, IntPtr c2, IntPtr c3);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "load_cpy",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "load_cpy",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern IntPtr load_cpy_internal(IntPtr ptr);
|
||||
|
||||
@@ -37,11 +38,11 @@ namespace StgSharp
|
||||
|
||||
#region add sub
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "addps",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "addps",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern IntPtr addps_internal(IntPtr ptr1, IntPtr ptr2);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "subps",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "subps",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern IntPtr subps_internal(IntPtr ptr1, IntPtr ptr2);
|
||||
|
||||
@@ -49,63 +50,67 @@ namespace StgSharp
|
||||
|
||||
#region mulps
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "mulps",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "mulps",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern IntPtr mulps_internal(IntPtr ptr1, IntPtr ptr2);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "mulps_const",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "mulps_const",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern IntPtr mulps_const_internal(IntPtr ptr, float value);
|
||||
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "mulps_sum",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "mulps_sum",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern float mulps_sum_internal(IntPtr ptr1, IntPtr ptr2);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "mulps_sum",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "mulps_sum",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe float mulps_sum_internal(M128* ptr1, M128* ptr2);
|
||||
internal static extern unsafe float mulps_sum_internal(Vector4* ptr1, Vector4* ptr2);
|
||||
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "mulps_sum",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe float mulps_sum_internal(Vec4d* ptr1, Vec4d* ptr2);
|
||||
|
||||
#endregion
|
||||
|
||||
#region div
|
||||
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "mulps",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "mulps",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern IntPtr divps_internal(IntPtr ptr1, IntPtr ptr2);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "divps_const",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "divps_const",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern IntPtr divps_const_internal(IntPtr ptr, float value);
|
||||
|
||||
#endregion
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "sqrtss_const",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "sqrtss_const",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern float sqrtss_const_internal(float a);
|
||||
|
||||
|
||||
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "set_m128ptr_default",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "set_Vector4ptr_default",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern IntPtr set_m128ptr_default_internal();
|
||||
internal static extern IntPtr set_Vector4ptr_default_internal();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#region deinit m128
|
||||
#region deinit Vector4
|
||||
|
||||
[DllImport(
|
||||
"msvcrt.dll",
|
||||
EntryPoint = "_aligned_free",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe void deinit_internal(M128* ptr);
|
||||
internal static extern unsafe void deinit_internal(Vector4* ptr);
|
||||
|
||||
[DllImport(
|
||||
"msvcrt.dll",
|
||||
@@ -130,23 +135,23 @@ namespace StgSharp
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe void deinit_internal(Mat4* ptr);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "deinitM128",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "deinitVector4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern void deinitM128_internal(ref M128 vec);
|
||||
internal static extern void deinitVector4_internal(ref Vector4 vec);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "deinitM128",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "deinitVector4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void deinitM128_internal(M128* vec);
|
||||
internal static extern unsafe void deinitVector4_internal(Vector4* vec);
|
||||
|
||||
#endregion
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "deinit_matmapPtr_sse",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "deinit_matmapPtr_sse",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern void deinitMatmapPtr_sse_internal(ref M128matMap mapPtr);
|
||||
internal static extern void deinitMatmapPtr_sse_internal(ref Vector4Map mapPtr);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "deinit_matmap_sse",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "deinit_matmap_sse",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern void deinitMatmap_sse_internal(ref M128matMap mapPtr);
|
||||
internal static extern void deinitMatmap_sse_internal(ref Vector4Map mapPtr);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
using StgSharp;
|
||||
using StgSharp.Control;
|
||||
using StgSharp.Logic;
|
||||
using System.Data;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public unsafe class M128Map
|
||||
public unsafe class Vector4Map
|
||||
{
|
||||
public readonly long mapID;
|
||||
internal long mapPtr;
|
||||
internal readonly StgSharp.LinkedListNode<long> _unusedM128Header;
|
||||
internal readonly StgSharp.LinkedListNode<long> _unusedVector4Header;
|
||||
private const int mapSize = 30 * 30;
|
||||
|
||||
internal StgSharp.LinkedList<long> m128Map =
|
||||
internal StgSharp.LinkedList<long> vector4Map =
|
||||
new StgSharp.LinkedList<long>();
|
||||
|
||||
public bool isFull
|
||||
{
|
||||
get
|
||||
{
|
||||
return _unusedM128Header == m128Map._hook;
|
||||
return _unusedVector4Header == vector4Map._hook;
|
||||
}
|
||||
}
|
||||
|
||||
public M128Map()
|
||||
public Vector4Map()
|
||||
{
|
||||
mapPtr = (long)(Marshal.AllocHGlobal(sizeof(M128)*mapSize)+15);
|
||||
mapPtr = (long)(Marshal.AllocHGlobal(sizeof(Vector4)*mapSize)+15);
|
||||
|
||||
long firstM128ptr = (mapPtr / 16 + 1) * 16;
|
||||
long firstVector4ptr = (mapPtr / 16 + 1) * 16;
|
||||
|
||||
m128Map.Add(0);
|
||||
_unusedM128Header = m128Map._hook._next;
|
||||
vector4Map.Add(0);
|
||||
_unusedVector4Header = vector4Map._hook._next;
|
||||
|
||||
for (int i = 0; i < 4*30*30*4; i+=16)
|
||||
{
|
||||
m128Map.Add(firstM128ptr+i);
|
||||
vector4Map.Add(firstVector4ptr+i);
|
||||
}
|
||||
|
||||
mapID = Calc.RandomSeed();
|
||||
}
|
||||
|
||||
internal long RegistManagedM128Ptr()
|
||||
internal long RegistManagedVector4Ptr()
|
||||
{
|
||||
LinkedListNode<long> m128 = _unusedM128Header._next;
|
||||
LinkedListNode<long> m128Previous = _unusedM128Header._previous;
|
||||
LinkedListNode<long> Vector4 = _unusedVector4Header._next;
|
||||
LinkedListNode<long> Vector4Previous = _unusedVector4Header._previous;
|
||||
|
||||
m128._next._previous = _unusedM128Header.Next;
|
||||
m128Previous._next = m128;
|
||||
m128._previous = m128Previous;
|
||||
_unusedM128Header._next = m128._next;
|
||||
m128._next = _unusedM128Header;
|
||||
_unusedM128Header._previous = m128;
|
||||
Vector4._next._previous = _unusedVector4Header.Next;
|
||||
Vector4Previous._next = Vector4;
|
||||
Vector4._previous = Vector4Previous;
|
||||
_unusedVector4Header._next = Vector4._next;
|
||||
Vector4._next = _unusedVector4Header;
|
||||
_unusedVector4Header._previous = Vector4;
|
||||
|
||||
return m128._value;
|
||||
return Vector4._value;
|
||||
|
||||
}
|
||||
|
||||
internal void RecycleManagedM128Ptr()
|
||||
internal void RecycleManagedVector4Ptr()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ namespace StgSharp.Math
|
||||
|
||||
public static unsafe partial class SSE
|
||||
{
|
||||
public static int M128Size = 16;
|
||||
public static int Vector4Size = 16;
|
||||
|
||||
internal static IntPtr defaultM128Ptr =
|
||||
internalIO.set_m128ptr_default_internal();
|
||||
internal static IntPtr defaultVector4Ptr =
|
||||
internalIO.set_Vector4ptr_default_internal();
|
||||
|
||||
|
||||
internal static IntPtr defaultM256Ptr;
|
||||
|
||||
@@ -5,63 +5,4 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct M128matMap
|
||||
{
|
||||
internal IntPtr colum0Ptr;
|
||||
internal IntPtr colum1Ptr;
|
||||
internal IntPtr colum2Ptr;
|
||||
internal IntPtr colum3Ptr;
|
||||
|
||||
internal M128matMap(
|
||||
IntPtr c0ptr,
|
||||
IntPtr c1ptr,
|
||||
IntPtr c2ptr,
|
||||
IntPtr c3ptr
|
||||
)
|
||||
{
|
||||
colum0Ptr = c0ptr;
|
||||
colum1Ptr = c1ptr;
|
||||
colum2Ptr = c2ptr;
|
||||
colum3Ptr = c3ptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
|
||||
internal struct M128
|
||||
{
|
||||
[FieldOffset(0)] internal float single_0;
|
||||
[FieldOffset(4)] internal float single_1;
|
||||
[FieldOffset(8)] internal float single_2;
|
||||
[FieldOffset(12)] internal float single_3;
|
||||
|
||||
[FieldOffset(0)] internal int int32_0;
|
||||
[FieldOffset(4)] internal int int32_1;
|
||||
[FieldOffset(8)] internal int int32_2;
|
||||
[FieldOffset(12)] internal int int32_3;
|
||||
|
||||
[FieldOffset(0)] internal long int64_0;
|
||||
[FieldOffset(8)] internal long int64_1;
|
||||
|
||||
[FieldOffset(0)] internal IntPtr ptr_0;
|
||||
[FieldOffset(8)] internal IntPtr ptr_1;
|
||||
|
||||
[FieldOffset(0)] internal long double_0;
|
||||
[FieldOffset(8)] internal long double_1;
|
||||
|
||||
internal M128(float x,float y,float z,float w)
|
||||
{
|
||||
single_0 = x;
|
||||
single_1 = y;
|
||||
single_2 = z;
|
||||
single_3 = w;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{single_0}\t{single_1}\t{single_2}\t{single_3}";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,26 +9,26 @@ namespace StgSharp.Math
|
||||
|
||||
public static unsafe float Multiple(Vec3d vec1, Vec3d vec2)
|
||||
{
|
||||
IntPtr retPtr = internalIO.mulps_internal(vec1._m128Ptr,vec2._m128Ptr);
|
||||
IntPtr retPtr = internalIO.mulps_internal(vec1._Vector4Ptr,vec2._Vector4Ptr);
|
||||
|
||||
M128 m128 = *(M128*)retPtr;
|
||||
Vector4 Vector4 = *(Vector4*)retPtr;
|
||||
Marshal.FreeHGlobal(retPtr);
|
||||
return
|
||||
m128.single_0 +
|
||||
m128.single_1 +
|
||||
m128.single_2;
|
||||
Vector4.single_0 +
|
||||
Vector4.single_1 +
|
||||
Vector4.single_2;
|
||||
}
|
||||
|
||||
public static unsafe float Multiple(Vec4d vec1,Vec3d vec2)
|
||||
{
|
||||
IntPtr retPtr = internalIO.mulps_internal(vec1._m128Ptr,vec2._m128Ptr);
|
||||
M128 m128 = *(M128*)retPtr;
|
||||
IntPtr retPtr = internalIO.mulps_internal(vec1._Vector4Ptr,vec2._Vector4Ptr);
|
||||
Vector4 Vector4 = *(Vector4*)retPtr;
|
||||
Marshal.FreeHGlobal(retPtr);
|
||||
return
|
||||
m128.single_0 +
|
||||
m128.single_1 +
|
||||
m128.single_2 +
|
||||
m128.single_3;
|
||||
Vector4.single_0 +
|
||||
Vector4.single_1 +
|
||||
Vector4.single_2 +
|
||||
Vector4.single_3;
|
||||
}
|
||||
|
||||
public static Matrix2x2 Multiple(Matrix2x2 matrix1, Matrix2x2 matrix2)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
@@ -36,6 +36,11 @@ namespace StgSharp
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe void Transpose2to4_internal(Mat2* source, Mat4* target);
|
||||
|
||||
[DllImport("StgsharpGraphic", EntryPoint = "transmpose2to3",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe void Transpose2to3_internal(Mat2* source, Mat3* target);
|
||||
|
||||
#endregion
|
||||
|
||||
#region deinit mat2
|
||||
@@ -56,8 +61,8 @@ namespace StgSharp.Math
|
||||
internal struct Mat2
|
||||
{
|
||||
|
||||
[FieldOffset(0)] internal M128 colum0;
|
||||
[FieldOffset(4 * sizeof(float))] internal M128 colum1;
|
||||
[FieldOffset(0)] internal Vector4 colum0;
|
||||
[FieldOffset(4 * sizeof(float))] internal Vector4 colum1;
|
||||
|
||||
[FieldOffset(0 * sizeof(float))] internal float m00;
|
||||
[FieldOffset(1 * sizeof(float))] internal float m10;
|
||||
@@ -69,5 +74,31 @@ namespace StgSharp.Math
|
||||
[FieldOffset(6 * sizeof(float))] internal float m21;
|
||||
[FieldOffset(7 * sizeof(float))] internal float m31;
|
||||
|
||||
internal Mat2(
|
||||
Vector4 c0,
|
||||
Vector4 c1
|
||||
)
|
||||
{
|
||||
colum0 = c0;
|
||||
colum1 = c1;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static Mat2 Add(Mat2 left, Mat2 right)
|
||||
{
|
||||
return new Mat2(
|
||||
left.colum0 + right.colum0,
|
||||
left.colum1 + right.colum1
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static Mat2 Sub(Mat2 left, Mat2 right)
|
||||
{
|
||||
return new Mat2(
|
||||
left.colum0 - right.colum0,
|
||||
left.colum1 - right.colum1
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,45 @@
|
||||
using StgSharp.Math;
|
||||
using StgSharp.StgSharp.Math;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static unsafe partial class internalIO
|
||||
{
|
||||
|
||||
|
||||
#region transpose
|
||||
|
||||
[DllImport("StgsharpGraphic", EntryPoint = "transpose3to4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose3to4_internal(Mat3* source, Mat4* target);
|
||||
|
||||
[DllImport("StgsharpGra[hic", EntryPoint = "transpose3to4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose3to3_internal(Mat3* source, Mat3* target);
|
||||
|
||||
[DllImport("StgsharpGra[hic", EntryPoint = "transpose3to2",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose3to2_internal(Mat3* source, Mat2* target);
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 12*sizeof(float),Pack = 16)]
|
||||
internal struct mat3
|
||||
[StructLayout(LayoutKind.Explicit, Size = 12 * sizeof(float), Pack = 16)]
|
||||
internal struct Mat3
|
||||
{
|
||||
|
||||
[FieldOffset(0)] internal M128 colum0;
|
||||
[FieldOffset(4 * sizeof(float))] internal M128 colum1;
|
||||
[FieldOffset(8 * sizeof(float))] internal M128 colum2;
|
||||
[FieldOffset(0)] internal Vector4 colum0;
|
||||
[FieldOffset(4 * sizeof(float))] internal Vector4 colum1;
|
||||
[FieldOffset(8 * sizeof(float))] internal Vector4 colum2;
|
||||
|
||||
[FieldOffset(0 * sizeof(float))] internal float m00;
|
||||
[FieldOffset(1 * sizeof(float))] internal float m10;
|
||||
@@ -30,4 +57,3 @@ namespace StgSharp.Math
|
||||
[FieldOffset(11 * sizeof(float))] internal float m32;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using StgSharp;
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
@@ -13,51 +14,56 @@ namespace StgSharp
|
||||
|
||||
#if NET7_0_OR_GREATER
|
||||
#else
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "addmat4",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "addmat4",
|
||||
#endif
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe StgSharp.Math.Mat4* add_mat4(
|
||||
ref StgSharp.Math.Mat4 mat1, ref StgSharp.Math.Mat4 Mat2);
|
||||
internal static extern unsafe Mat4* add_mat4(
|
||||
ref Mat4 mat1, ref Mat4 Mat2);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "addmat4",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "addmat4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe StgSharp.Math.Mat4* add_mat4(
|
||||
StgSharp.Math.Mat4* mat1, StgSharp.Math.Mat4* Mat2);
|
||||
internal static extern unsafe Mat4* add_mat4(
|
||||
Mat4* mat1, Mat4* Mat2);
|
||||
|
||||
#endregion
|
||||
|
||||
#region sub_mat4
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "sub_mat4",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "sub_mat4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static unsafe extern StgSharp.Math.Mat4* sub_mat4(
|
||||
ref StgSharp.Math.Mat4 mat1, ref StgSharp.Math.Mat4 Mat2);
|
||||
internal static unsafe extern Mat4* sub_mat4(
|
||||
ref Mat4 mat1, ref Mat4 Mat2);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "StgSharp.Math.Mat4",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "Mat4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static unsafe extern StgSharp.Math.Mat4* sub_mat4(
|
||||
StgSharp.Math.Mat4* mat1, StgSharp.Math.Mat4* Mat2);
|
||||
internal static unsafe extern Mat4* sub_mat4(
|
||||
Mat4* mat1, Mat4* Mat2);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region mul
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "mul_const",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "mul_const",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static unsafe extern StgSharp.Math.Mat4* mul_const(
|
||||
StgSharp.Math.Mat4* mat, float value);
|
||||
internal static unsafe extern Mat4* mul_const(
|
||||
Mat4* mat, float value);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "mul_const",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "mul_const",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static unsafe extern StgSharp.Math.Mat4* mul_const(
|
||||
ref StgSharp.Math.Mat4 mat, float value);
|
||||
internal static unsafe extern Mat4* mul_const(
|
||||
ref Mat4 mat, float value);
|
||||
|
||||
[DllImport("StgsharpGraphic", EntryPoint = "mul_4_2",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe Mat2* mul_4_2(Mat4* left, Mat2* right);
|
||||
|
||||
[DllImport("StgsharpGraphic", EntryPoint = "mul_4_4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
@@ -68,13 +74,17 @@ namespace StgSharp
|
||||
|
||||
#region transpose
|
||||
|
||||
[DllImport("StgsharpGraphic.dll", EntryPoint = "transpose4to4",
|
||||
[DllImport("StgsharpGraphic", EntryPoint = "transpose4to4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose4to4_internal(Mat4* source, Mat4* target);
|
||||
|
||||
[DllImport("StgsharpGraphic.dll", EntryPoint = "transpose4to4",
|
||||
[DllImport("StgsharpGraphic", EntryPoint = "transpose4to3",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose4to4_internal(ref Mat4* source, ref Mat4* target);
|
||||
internal static extern unsafe void Transpose4to3_internal(Mat4* source, Mat3* target);
|
||||
|
||||
[DllImport("StgsharpGraphic", EntryPoint = "transpose4to2",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose4to2_internal(Mat4* source, Mat2* target);
|
||||
|
||||
|
||||
#endregion
|
||||
@@ -84,21 +94,21 @@ namespace StgSharp
|
||||
[DllImport("StgsharpGraphic", EntryPoint = "det_mat4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static unsafe extern float det_mat4(Matrix4x4* matPtr);
|
||||
internal static unsafe extern float det_mat4(Mat4* matPtr, Mat4* transpose);
|
||||
|
||||
#endregion
|
||||
|
||||
#region deinit_mat4
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "deinit_mat4",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "deinit_mat4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern void deinit_mat4(ref StgSharp.Math.Mat4 mat);
|
||||
internal static extern void deinit_mat4(ref Mat4 mat);
|
||||
|
||||
[DllImport("StgSharpGraphic.dll", EntryPoint = "deinit_mat4",
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "deinit_mat4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern void deinit_mat4(StgSharp.Math.Mat4* mat);
|
||||
internal static extern void deinit_mat4(Mat4* mat);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -113,30 +123,66 @@ namespace StgSharp.Math
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16 * sizeof(float))]
|
||||
public struct Mat4
|
||||
{
|
||||
[FieldOffset(0)] internal M128 colum0;
|
||||
[FieldOffset(16)] internal M128 colum1;
|
||||
[FieldOffset(32)] internal M128 colum2;
|
||||
[FieldOffset(48)] internal M128 colum3;
|
||||
[FieldOffset(0)] internal Vector4 colum0;
|
||||
[FieldOffset(16)] internal Vector4 colum1;
|
||||
[FieldOffset(32)] internal Vector4 colum2;
|
||||
[FieldOffset(48)] internal Vector4 colum3;
|
||||
|
||||
[FieldOffset(0)] public float a00;
|
||||
[FieldOffset(4)] public float a10;
|
||||
[FieldOffset(8)] public float a20;
|
||||
[FieldOffset(12)] public float a30;
|
||||
[FieldOffset(0)] public float m00;
|
||||
[FieldOffset(4)] public float m10;
|
||||
[FieldOffset(8)] public float m20;
|
||||
[FieldOffset(12)] public float m30;
|
||||
|
||||
[FieldOffset(16)] public float a01;
|
||||
[FieldOffset(20)] public float a11;
|
||||
[FieldOffset(24)] public float a21;
|
||||
[FieldOffset(28)] public float a31;
|
||||
[FieldOffset(16)] public float m01;
|
||||
[FieldOffset(20)] public float m11;
|
||||
[FieldOffset(24)] public float m21;
|
||||
[FieldOffset(28)] public float m31;
|
||||
|
||||
[FieldOffset(32)] public float a02;
|
||||
[FieldOffset(36)] public float a12;
|
||||
[FieldOffset(40)] public float a22;
|
||||
[FieldOffset(44)] public float a32;
|
||||
[FieldOffset(32)] public float m02;
|
||||
[FieldOffset(36)] public float m12;
|
||||
[FieldOffset(40)] public float m22;
|
||||
[FieldOffset(44)] public float m32;
|
||||
|
||||
[FieldOffset(48)] public float a03;
|
||||
[FieldOffset(52)] public float a13;
|
||||
[FieldOffset(56)] public float a23;
|
||||
[FieldOffset(60)] public float a33;
|
||||
[FieldOffset(48)] public float m03;
|
||||
[FieldOffset(52)] public float m13;
|
||||
[FieldOffset(56)] public float m23;
|
||||
[FieldOffset(60)] public float m33;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal Mat4(
|
||||
Vector4 colum0,
|
||||
Vector4 colum1,
|
||||
Vector4 colum2,
|
||||
Vector4 colum3
|
||||
)
|
||||
{
|
||||
this.colum0 = colum0;
|
||||
this.colum1 = colum1;
|
||||
this.colum2 = colum2;
|
||||
this.colum3 = colum3;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static Mat4 add(Mat4 left, Mat4 right)
|
||||
{
|
||||
return new Mat4(
|
||||
left.colum0 + right.colum0,
|
||||
left.colum1 + right.colum1,
|
||||
left.colum2 + right.colum2,
|
||||
left.colum3 + right.colum3
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static Mat4 sub(Mat4 left, Mat4 right)
|
||||
{
|
||||
return new Mat4(
|
||||
left.colum0 - right.colum0,
|
||||
left.colum1 - right.colum1,
|
||||
left.colum2 - right.colum2,
|
||||
left.colum3 - right.colum3
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**/
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**/
|
||||
}
|
||||
|
||||
@@ -1,12 +1,197 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = (4 + 2) * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
|
||||
public struct Matrix2x4
|
||||
{
|
||||
[FieldOffset(0)] internal Mat4 mat;
|
||||
[FieldOffset(4 * 4 * sizeof(float))] internal Mat2 transpose;
|
||||
[FieldOffset(6 * 4 * sizeof(float))] internal bool isTransposed;
|
||||
|
||||
public Matrix2x4(
|
||||
float a00, float a01,float a02,float a03,
|
||||
float a10, float a11,float a12,float a13
|
||||
)
|
||||
{
|
||||
mat.colum0 = new Vector4(a00, a10, 0, 0);
|
||||
mat.colum1 = new Vector4(a01, a11, 0, 0);
|
||||
mat.colum2 = new Vector4(a02, a12, 0, 0);
|
||||
mat.colum3 = new Vector4(a03, a13, 0, 0);
|
||||
}
|
||||
|
||||
internal Matrix2x4(
|
||||
Vector4 c0,
|
||||
Vector4 c1,
|
||||
Vector4 c2,
|
||||
Vector4 c3
|
||||
)
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
mat.colum2 = c2;
|
||||
mat.colum3 = c3;
|
||||
}
|
||||
|
||||
public unsafe float this[int rowNum, int columNum]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowNum > 1 || rowNum < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if (columNum > 3 || 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 > 3 || 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 (Mat4* source = &this.mat)
|
||||
fixed (Mat2* target = &this.transpose)
|
||||
{
|
||||
internalIO.Transpose4to2_internal(source, target);
|
||||
}
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x4 operator +(Matrix2x4 left, Matrix2x4 right)
|
||||
{
|
||||
return new Matrix2x4(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2,
|
||||
left.mat.colum3 + right.mat.colum3
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x4 operator -(Matrix2x4 left, Matrix2x4 right)
|
||||
{
|
||||
return new Matrix2x4(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum1 - right.mat.colum1,
|
||||
left.mat.colum2 - right.mat.colum2,
|
||||
left.mat.colum3 - right.mat.colum3
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x4 operator *(Matrix2x4 mat, float value)
|
||||
{
|
||||
return new Matrix2x4(
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value,
|
||||
mat.mat.colum3 * value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x4 operator /(Matrix2x4 mat, float value)
|
||||
{
|
||||
return new Matrix2x4(
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value,
|
||||
mat.mat.colum3 / value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix2x2 operator *(Matrix2x4 left, Matrix4x2 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 *(Matrix2x4 left, Matrix4x3 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 *(Matrix2x4 left, Matrix4x4 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)
|
||||
);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
InternalTranspose();
|
||||
return $"[{mat.m00},{mat.m01},{mat.m02},{mat.m03}]," +
|
||||
$"[{mat.m10},{mat.m11},{mat.m12},{mat.m13}]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,187 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 5 * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
|
||||
public struct Matrix3x2
|
||||
{
|
||||
[FieldOffset(0)] internal Mat2 mat;
|
||||
[FieldOffset(2 * 4 * sizeof(float))] internal Mat3 transpose;
|
||||
[FieldOffset(5 * 4 * sizeof(float))] internal bool isTransposed;
|
||||
|
||||
|
||||
public Matrix3x2(
|
||||
float a00, float a01,
|
||||
float a10, float a11,
|
||||
float a20, float a21
|
||||
)
|
||||
{
|
||||
mat.colum0 = new Vector4(a00, a10, a20, 0);
|
||||
mat.colum0 = new Vector4(a01, a11, a21, 0);
|
||||
}
|
||||
|
||||
internal Matrix3x2(
|
||||
Vector4 c0,
|
||||
Vector4 c1
|
||||
)
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
}
|
||||
|
||||
public unsafe float this[int rowNum, int columNum]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowNum > 2 || rowNum < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if (columNum > 1 || 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 > 2 || rowNum < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if (columNum > 1 || 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 (Mat2* source = &this.mat)
|
||||
fixed (Mat3* target = &this.transpose)
|
||||
{
|
||||
internalIO.Transpose2to3_internal(source, target);
|
||||
}
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 operator +(Matrix3x2 left, Matrix3x2 right)
|
||||
{
|
||||
return new Matrix3x2(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 operator -(Matrix3x2 left, Matrix3x2 right)
|
||||
{
|
||||
return new Matrix3x2(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum1 - right.mat.colum1
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 operator *(Matrix3x2 mat, float value)
|
||||
{
|
||||
return new Matrix3x2(
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 operator /(Matrix3x2 mat, float value)
|
||||
{
|
||||
return new Matrix3x2(
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 operator *(Matrix3x2 left, Matrix2x2 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix3x2(
|
||||
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),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x3 operator *(Matrix3x2 left, Matrix2x3 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix3x3(
|
||||
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),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x4 operator *(Matrix3x2 left, Matrix2x4 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix3x4(
|
||||
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),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum3)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,198 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public class Matrix3x3
|
||||
[StructLayout(LayoutKind.Explicit, Size = 6 * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
|
||||
public struct Matrix3x3
|
||||
{
|
||||
[FieldOffset(0)] internal Mat3 mat;
|
||||
[FieldOffset(3 * 4 * sizeof(float))] internal Mat3 transpose;
|
||||
[FieldOffset(6 * 4 * sizeof(float))] internal bool isTransposed;
|
||||
|
||||
|
||||
public Matrix3x3(
|
||||
float a00,float a01,float a02,
|
||||
float a10,float a11,float a12,
|
||||
float a20,float a21,float a22
|
||||
)
|
||||
{
|
||||
mat.colum0 = new Vector4(a00,a10,a20,0);
|
||||
mat.colum1 = new Vector4(a01,a11,a21,0);
|
||||
mat.colum2 = new Vector4(a02,a12,a22,0);
|
||||
}
|
||||
|
||||
internal Matrix3x3(
|
||||
Vector4 c0,
|
||||
Vector4 c1,
|
||||
Vector4 c2
|
||||
)
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
mat.colum2 = c2;
|
||||
}
|
||||
|
||||
public unsafe float this[int rowNum, int columNum]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowNum > 2 || 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 > 2 || 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, target = &this.transpose)
|
||||
{
|
||||
internalIO.Transpose3to3_internal(source, target);
|
||||
}
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x3 operator +(Matrix3x3 left, Matrix3x3 right)
|
||||
{
|
||||
return new Matrix3x3(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x3 operator -(Matrix3x3 left, Matrix3x3 right)
|
||||
{
|
||||
return new Matrix3x3(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum1 - right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x3 operator *(Matrix3x3 mat, float value)
|
||||
{
|
||||
return new Matrix3x3(
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x3 operator /(Matrix3x3 mat, float value)
|
||||
{
|
||||
return new Matrix3x3(
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 operator *(Matrix3x3 left, Matrix3x2 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix3x2(
|
||||
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),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2,right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2,right.mat.colum1)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x3 operator *(Matrix3x3 left, Matrix3x3 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix3x3(
|
||||
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),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2,right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2,right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2,right.mat.colum2)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x4 operator *(Matrix3x3 left, Matrix3x4 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix3x4(
|
||||
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),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2,right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2,right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2,right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum2,right.mat.colum3)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,206 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public class Matrix3x4
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 7*4*sizeof(float)+ sizeof(bool),Pack = 16)]
|
||||
public struct Matrix3x4
|
||||
{
|
||||
[FieldOffset(0)] internal Mat4 mat;
|
||||
[FieldOffset(4*4*sizeof(float))] internal Mat3 transpose;
|
||||
[FieldOffset(7 * 4 * sizeof(float))] internal bool isTransposed;
|
||||
|
||||
public Matrix3x4(
|
||||
float a00, float a01, float a02, float a03,
|
||||
float a10, float a11, float a12, float a13,
|
||||
float a20, float a21, float a22, float a23
|
||||
)
|
||||
{
|
||||
mat.colum0 = new Vector4(a00, a10, a20, 0);
|
||||
mat.colum0 = new Vector4(a01, a11, a21, 0);
|
||||
mat.colum0 = new Vector4(a02, a12, a22, 0);
|
||||
mat.colum0 = new Vector4(a03, a13, a23, 0);
|
||||
}
|
||||
|
||||
internal Matrix3x4(
|
||||
Vector4 c0,
|
||||
Vector4 c1,
|
||||
Vector4 c2,
|
||||
Vector4 c3
|
||||
)
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
mat.colum2 = c2;
|
||||
mat.colum3 = c3;
|
||||
}
|
||||
|
||||
internal Matrix3x4(Mat4 mat)
|
||||
{
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
public unsafe float this[int rowNum, int columNum]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowNum > 2 || rowNum < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if (columNum > 3 || 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 > 2 || rowNum < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if (columNum > 3 || 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;
|
||||
}
|
||||
}
|
||||
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if (!isTransposed)
|
||||
{
|
||||
fixed(Mat4* source = &this.mat)
|
||||
fixed(Mat3* target = &this.transpose)
|
||||
{
|
||||
internalIO.Transpose4to3_internal(source, target);
|
||||
}
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x4 operator +(Matrix3x4 left, Matrix3x4 right)
|
||||
{
|
||||
return new Matrix3x4(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2,
|
||||
left.mat.colum3 + right.mat.colum3
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x4 operator -(Matrix3x4 left, Matrix3x4 right)
|
||||
{
|
||||
return new Matrix3x4(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum1 - right.mat.colum1,
|
||||
left.mat.colum2 - right.mat.colum2,
|
||||
left.mat.colum3 - right.mat.colum3
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x4 operator *(Matrix3x4 mat, float value)
|
||||
{
|
||||
return new Matrix3x4(
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value,
|
||||
mat.mat.colum3 * value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x4 operator /(Matrix3x4 mat, float value)
|
||||
{
|
||||
return new Matrix3x4(
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value,
|
||||
mat.mat.colum3 / value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 operator *(Matrix3x4 left, Matrix4x2 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix3x2(
|
||||
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),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x3 operator *(Matrix3x4 left, Matrix4x3 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix3x3(
|
||||
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),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x4 operator *(Matrix3x4 left, Matrix4x4 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix3x4(
|
||||
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),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum3)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using static StgSharp.Graphics.GLFWwndconfig;
|
||||
|
||||
namespace StgSharp.Math
|
||||
@@ -13,66 +14,200 @@ namespace StgSharp.Math
|
||||
{
|
||||
[FieldOffset(0)] internal Mat2 mat;
|
||||
[FieldOffset(8 * sizeof(float))] internal Mat4 transpose;
|
||||
[FieldOffset((16 + 8) * sizeof(float))] internal bool isTranspose;
|
||||
[FieldOffset((16 + 8) * sizeof(float))] internal bool isTransposed;
|
||||
|
||||
|
||||
unsafe public Matrix4x2(
|
||||
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);
|
||||
mat.colum0 = new Vector4(a00, a10, a20, a30);
|
||||
mat.colum1 = new Vector4(a01, a11, a21, a31);
|
||||
}
|
||||
|
||||
unsafe internal Matrix4x2(Mat2 mat)
|
||||
|
||||
internal Matrix4x2(
|
||||
Vector4 c0,
|
||||
Vector4 c1
|
||||
)
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
}
|
||||
|
||||
internal Matrix4x2(Mat2 mat)
|
||||
{
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public unsafe float this[int rowNum, int columNum]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowNum > 3 || rowNum < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if (columNum > 1 || 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 > 3 || rowNum < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if (columNum > 1 || 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)]
|
||||
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;
|
||||
return new Matrix4x2(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum0 + right.mat.colum0
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix4x2 operator *(Matrix4x2 mat, float value)
|
||||
{
|
||||
return new Matrix4x2(
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix4x2 operator /(Matrix4x2 mat, float value)
|
||||
{
|
||||
return new Matrix4x2(
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value
|
||||
);
|
||||
}
|
||||
|
||||
[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;
|
||||
return new Matrix4x2(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum0 - right.mat.colum0
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix4x2 operator *(Matrix4x2 left, Matrix2x2 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix4x2(
|
||||
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),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum1)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix4x3 operator *(Matrix4x2 left, Matrix2x3 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix4x3(
|
||||
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),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum2)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix4x4 operator *(Matrix4x2 left, Matrix2x4 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix4x4(
|
||||
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.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),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum2)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if (!isTranspose)
|
||||
if (!isTransposed)
|
||||
{
|
||||
fixed (Mat2* source = &this.mat)
|
||||
fixed (Mat4* target = &this.transpose)
|
||||
{
|
||||
internalIO.Transpose2to4_internal(source, target);
|
||||
}
|
||||
|
||||
isTranspose = true;
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,216 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public class Matrix4x3
|
||||
[StructLayout(LayoutKind.Explicit, Size = 7*4*sizeof(float)+ sizeof(bool),Pack =16 )]
|
||||
public struct Matrix4x3
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
internal Mat3 mat;
|
||||
[FieldOffset(3 * 4 * sizeof(float))]
|
||||
internal Mat4 transpose;
|
||||
[FieldOffset(7 * 4 * sizeof(float))]
|
||||
internal bool isTransposed;
|
||||
|
||||
public Matrix4x3(
|
||||
float a00, float a01, float a02,
|
||||
float a10, float a11, float a12,
|
||||
float a20, float a21, float a22,
|
||||
float a30, float a31, float a32
|
||||
)
|
||||
{
|
||||
mat.colum0 = new Vector4(a00, a10, a20, a30);
|
||||
mat.colum1 = new Vector4(a01, a11, a21, a31);
|
||||
mat.colum2 = new Vector4(a02, a12, a22, a32);
|
||||
}
|
||||
|
||||
internal Matrix4x3(
|
||||
Vector4 c0,
|
||||
Vector4 c1,
|
||||
Vector4 c2
|
||||
)
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
mat.colum2 = c2;
|
||||
}
|
||||
|
||||
public unsafe float this[int rowNum, int columNum]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowNum > 3 || 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 > 3 || 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 (Mat4* target = &this.transpose)
|
||||
{
|
||||
internalIO.Transpose3to4_internal(source, target);
|
||||
|
||||
}
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix4x3 operator +(Matrix4x3 left, Matrix4x3 right)
|
||||
{
|
||||
return new Matrix4x3(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix4x3 operator -(Matrix4x3 left, Matrix4x3 right)
|
||||
{
|
||||
return new Matrix4x3(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum1 - right.mat.colum1,
|
||||
left.mat.colum2 - right.mat.colum2
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix4x3 operator *(Matrix4x3 mat, float value)
|
||||
{
|
||||
return new Matrix4x3(
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix4x3 operator /(Matrix4x3 mat, float value)
|
||||
{
|
||||
return new Matrix4x3(
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix4x2 operator *(Matrix4x3 left, Matrix3x2 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix4x2(
|
||||
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),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum1)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix4x3 operator *(Matrix4x3 left, Matrix3x3 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix4x3(
|
||||
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),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum2)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix4x4 operator *(Matrix4x3 left, Matrix3x4 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix4x4(
|
||||
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),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum3),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum3)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -28,22 +28,10 @@ namespace StgSharp.Math
|
||||
float a30, float a31, float a32, float a33
|
||||
)
|
||||
{
|
||||
M128* c0ref = internalIO.loadptr_internal(a00, a10, a20, a30);
|
||||
M128* c1ref = internalIO.loadptr_internal(a01, a11, a21, a31);
|
||||
M128* c2ref = internalIO.loadptr_internal(a02, a12, a22, a32);
|
||||
M128* c3ref = internalIO.loadptr_internal(a03, a13, a23, a33);
|
||||
|
||||
mat.colum0 = *c0ref;
|
||||
mat.colum1 = *c1ref;
|
||||
mat.colum2 = *c2ref;
|
||||
mat.colum3 = *c3ref;
|
||||
|
||||
/**/
|
||||
internalIO.deinitM128_internal(c0ref);
|
||||
internalIO.deinitM128_internal(c1ref);
|
||||
internalIO.deinitM128_internal(c2ref);
|
||||
internalIO.deinitM128_internal(c3ref);
|
||||
/**/
|
||||
mat.colum0 = new Vector4(a00, a10, a20, a30);
|
||||
mat.colum0 = new Vector4(a01, a11, a21, a31);
|
||||
mat.colum0 = new Vector4(a02, a12, a22, a32);
|
||||
mat.colum0 = new Vector4(a03, a13, a23, a33);
|
||||
|
||||
}
|
||||
|
||||
@@ -60,22 +48,44 @@ namespace StgSharp.Math
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed (float* p = &this.transpose.a00 )
|
||||
fixed (float* p = &this.transpose.m00 )
|
||||
{
|
||||
ulong pbit = (ulong)p
|
||||
+ (ulong)sizeof(M128) * (ulong)rowNum
|
||||
+ (ulong)sizeof(Vector4) * (ulong)rowNum
|
||||
+ (ulong)sizeof(float) * (ulong)columNum;
|
||||
return *(float*)pbit;
|
||||
}
|
||||
|
||||
}
|
||||
set
|
||||
{
|
||||
|
||||
if (rowNum > 3 || rowNum < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if (columNum > 3 || 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
internal Matrix4x4(
|
||||
ref M128 vec0,
|
||||
ref M128 vec1,
|
||||
ref M128 vec2,
|
||||
ref M128 vec3
|
||||
Vector4 vec0,
|
||||
Vector4 vec1,
|
||||
Vector4 vec2,
|
||||
Vector4 vec3
|
||||
)
|
||||
{
|
||||
mat.colum0 = vec0;
|
||||
@@ -90,67 +100,111 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix4x4 operator +(Matrix4x4 mat1, Matrix4x4 Mat2)
|
||||
public static unsafe Matrix4x4 operator +(Matrix4x4 left, Matrix4x4 right)
|
||||
{
|
||||
Mat4* refret = internalIO.add_mat4(ref mat1.mat, ref Mat2.mat);
|
||||
Matrix4x4 ret = new Matrix4x4(*refret);
|
||||
internalIO.deinit_mat4(refret);
|
||||
return ret;
|
||||
return new Matrix4x4(
|
||||
Mat4.add( right.mat,left.mat)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix4x4 operator -(Matrix4x4 mat1, Matrix4x4 Mat2)
|
||||
public static unsafe Matrix4x4 operator -(Matrix4x4 left, Matrix4x4 right)
|
||||
{
|
||||
Mat4* refret = internalIO.sub_mat4(ref mat1.mat, ref Mat2.mat);
|
||||
Matrix4x4 ret = new Matrix4x4(*refret);
|
||||
internalIO.deinit_mat4(refret);
|
||||
return ret;
|
||||
return new Matrix4x4(
|
||||
Mat4.sub(right.mat, left.mat)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix4x4 operator *(Matrix4x4 mat, float value)
|
||||
{
|
||||
Mat4* refret = internalIO.mul_const(ref mat.mat, value);
|
||||
Matrix4x4 ret = new Matrix4x4(*refret);
|
||||
internalIO.deinit_mat4(refret);
|
||||
return ret;
|
||||
return new Matrix4x4(
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value,
|
||||
mat.mat.colum3 * value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix4x2 operator *(Matrix4x4 left, Matrix4x2 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
Mat4 tr = left.transpose;
|
||||
return new Matrix4x2(
|
||||
internalIO.mulps_sum_internal(&tr.colum0, &right.mat.colum0),
|
||||
internalIO.mulps_sum_internal(&tr.colum0, &right.mat.colum1),
|
||||
internalIO.mulps_sum_internal(&tr.colum1, &right.mat.colum0),
|
||||
internalIO.mulps_sum_internal(&tr.colum1, &right.mat.colum1),
|
||||
internalIO.mulps_sum_internal(&tr.colum2, &right.mat.colum0),
|
||||
internalIO.mulps_sum_internal(&tr.colum2, &right.mat.colum1),
|
||||
internalIO.mulps_sum_internal(&tr.colum3, &right.mat.colum0),
|
||||
internalIO.mulps_sum_internal(&tr.colum3, &right.mat.colum1)
|
||||
);
|
||||
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),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum1)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix4x4 operator *(Matrix4x4 left, Matrix4x4 right)
|
||||
public static Matrix4x3 operator *(Matrix4x4 left, Matrix4x3 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
Mat4* p = internalIO.mul_4_4(&left.transpose, &right.mat);
|
||||
Matrix4x4 ret = new Matrix4x4(*p);
|
||||
internalIO.deinit_mat4(p);
|
||||
return ret;
|
||||
return new Matrix4x3(
|
||||
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),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2,right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2,right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2,right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3,right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3,right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum3,right.mat.colum2)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix4x4 operator *(Matrix4x4 left, Matrix4x4 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix4x4(
|
||||
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),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum3),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum3)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe float Det()
|
||||
{
|
||||
InternalTranspose();
|
||||
fixed (Matrix4x4* _this = &this)
|
||||
fixed (Mat4* _this = &mat, _trans = &transpose)
|
||||
{
|
||||
return internalIO.det_mat4(_this);
|
||||
return internalIO.det_mat4(_this,_trans);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace StgSharp.Math
|
||||
public float Y;
|
||||
|
||||
[FieldOffset(0)]
|
||||
internal M128 vec;
|
||||
internal Vector4 vec;
|
||||
|
||||
public Vec2d(float x, float y)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using StgSharp.Control;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace StgSharp.Math
|
||||
public struct Vec3d
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
internal M128 vec;
|
||||
internal Vector4 vec;
|
||||
|
||||
[FieldOffset(0)] public float X;
|
||||
[FieldOffset(4)] public float Y;
|
||||
@@ -72,5 +72,12 @@ namespace StgSharp.Math
|
||||
vec1.Z * vec2.Z;
|
||||
}
|
||||
|
||||
public string ToString(string sample)
|
||||
{
|
||||
return $"{this.X}\t{this.Y}\t{this.Z}\t";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using StgSharp.Control;
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
@@ -9,7 +9,7 @@ namespace StgSharp.Math
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
|
||||
public struct Vec4d
|
||||
{
|
||||
[FieldOffset(0)] internal M128 vec;
|
||||
[FieldOffset(0)] internal Vector4 vec;
|
||||
|
||||
[FieldOffset(0)]public float X;
|
||||
[FieldOffset(4)]public float Y;
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="..\StgSharpGraphic.dll">
|
||||
<None Update="..\StgSharpGraphic">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
Binary file not shown.
@@ -162,12 +162,6 @@
|
||||
Vec2Ds in StgSharp are defaultly usaed as colum vector.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:StgSharp.Math.Vec4d.#ctor(System.IntPtr)">
|
||||
<summary>
|
||||
internal constructor to recive a pointer of the M128 value
|
||||
</summary>
|
||||
<param name="value"></param>
|
||||
</member>
|
||||
<member name="M:StgSharp.Math.Calc.ASin(System.Single)">
|
||||
<summary>
|
||||
Reurns the value of ArcSin(x)
|
||||
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
a481b6da709e541cf6f2d458de164b157415491e
|
||||
f6acdcb7485571fc33859ff7052c64de7abcc14b
|
||||
|
||||
Binary file not shown.
@@ -162,12 +162,6 @@
|
||||
Vec2Ds in StgSharp are defaultly usaed as colum vector.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:StgSharp.Math.Vec4d.#ctor(System.IntPtr)">
|
||||
<summary>
|
||||
internal constructor to recive a pointer of the M128 value
|
||||
</summary>
|
||||
<param name="value"></param>
|
||||
</member>
|
||||
<member name="M:StgSharp.Math.Calc.ASin(System.Single)">
|
||||
<summary>
|
||||
Reurns the value of ArcSin(x)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -26,6 +26,7 @@
|
||||
],
|
||||
"sources": {
|
||||
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
||||
"C:\\Program Files\\dotnet\\library-packs": {},
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
|
||||
@@ -159,6 +159,7 @@
|
||||
],
|
||||
"sources": {
|
||||
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
||||
"C:\\Program Files\\dotnet\\library-packs": {},
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "LkDSeyeGIzwEX93A0bihMviHOggcsL8tMl89DOcWOldIkA/gZCDUU1UH3ksMLOCGXi+sVGG+kz4l8+2AIbLJ1Q==",
|
||||
"dgSpecHash": "nyq9v8WRAFwIjz8I9Gv9vf0PpGAcnjjNKfzoUjZTNrikCVkWYQ0og9Fjs/Iji8EwIym3cvVShDpL3VAfbdckRQ==",
|
||||
"success": true,
|
||||
"projectFilePath": "D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\源代码\\StgSharp\\StgSharp.csproj",
|
||||
"expectedPackageFiles": [
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user