daily update on 20230830
This commit is contained in:
@@ -58,7 +58,7 @@ namespace StgSharp
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 12 * sizeof(float), Pack = 16)]
|
||||
internal struct Mat2
|
||||
internal struct Mat2 : IEquatable<Mat2>
|
||||
{
|
||||
|
||||
[FieldOffset(0)] internal Vector4 colum0;
|
||||
@@ -84,21 +84,28 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static Mat2 Add(Mat2 left, Mat2 right)
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return new Mat2(
|
||||
left.colum0 + right.colum0,
|
||||
left.colum1 + right.colum1
|
||||
);
|
||||
return obj is Mat2 mat && Equals(mat);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static Mat2 Sub(Mat2 left, Mat2 right)
|
||||
public bool Equals(Mat2 other)
|
||||
{
|
||||
return new Mat2(
|
||||
left.colum0 - right.colum0,
|
||||
left.colum1 - right.colum1
|
||||
);
|
||||
return colum0.Equals(other.colum0) &&
|
||||
colum1.Equals(other.colum1);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Mat2 left, Mat2 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Mat2 left, Mat2 right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using StgSharp.Math;
|
||||
using StgSharp.StgSharp.Math;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp
|
||||
@@ -9,6 +9,14 @@ namespace StgSharp
|
||||
internal static unsafe partial class internalIO
|
||||
{
|
||||
|
||||
#region det
|
||||
|
||||
[DllImport("StgsharpGraphic", EntryPoint = "det_mat3",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe float det_mat3(Mat3* mat);
|
||||
|
||||
#endregion
|
||||
|
||||
#region transpose
|
||||
|
||||
@@ -34,7 +42,7 @@ namespace StgSharp
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 12 * sizeof(float), Pack = 16)]
|
||||
internal struct Mat3
|
||||
internal struct Mat3 : IEquatable<Mat3>
|
||||
{
|
||||
|
||||
[FieldOffset(0)] internal Vector4 colum0;
|
||||
@@ -56,4 +64,29 @@ namespace StgSharp.Math
|
||||
[FieldOffset(10 * sizeof(float))] internal float m22;
|
||||
[FieldOffset(11 * sizeof(float))] internal float m32;
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is Mat3 mat && Equals(mat);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Equals(Mat3 other)
|
||||
{
|
||||
return colum0.Equals(other.colum0) &&
|
||||
colum1.Equals(other.colum1) &&
|
||||
colum2.Equals(other.colum2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Mat3 left, Mat3 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Mat3 left, Mat3 right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,68 +10,6 @@ namespace StgSharp
|
||||
internal static unsafe partial class internalIO
|
||||
{
|
||||
|
||||
#region add_mat4
|
||||
|
||||
#if NET7_0_OR_GREATER
|
||||
#else
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "addmat4",
|
||||
#endif
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe Mat4* add_mat4(
|
||||
ref Mat4 mat1, ref Mat4 Mat2);
|
||||
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "addmat4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe Mat4* add_mat4(
|
||||
Mat4* mat1, Mat4* Mat2);
|
||||
|
||||
#endregion
|
||||
|
||||
#region sub_mat4
|
||||
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "sub_mat4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static unsafe extern Mat4* sub_mat4(
|
||||
ref Mat4 mat1, ref Mat4 Mat2);
|
||||
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "Mat4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static unsafe extern Mat4* sub_mat4(
|
||||
Mat4* mat1, Mat4* Mat2);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region mul
|
||||
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "mul_const",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static unsafe extern Mat4* mul_const(
|
||||
Mat4* mat, float value);
|
||||
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "mul_const",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
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)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe Mat4* mul_4_4(Mat4* left, Mat4* right);
|
||||
|
||||
#endregion
|
||||
|
||||
#region transpose
|
||||
|
||||
[DllImport("StgsharpGraphic", EntryPoint = "transpose4to4",
|
||||
@@ -100,10 +38,6 @@ namespace StgSharp
|
||||
|
||||
#region deinit_mat4
|
||||
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "deinit_mat4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern void deinit_mat4(ref Mat4 mat);
|
||||
|
||||
[DllImport("StgSharpGraphic", EntryPoint = "deinit_mat4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
@@ -121,7 +55,7 @@ namespace StgSharp.Math
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16 * sizeof(float))]
|
||||
public struct Mat4
|
||||
internal struct Mat4 : IEquatable<Mat4>
|
||||
{
|
||||
[FieldOffset(0)] internal Vector4 colum0;
|
||||
[FieldOffset(16)] internal Vector4 colum1;
|
||||
@@ -162,27 +96,30 @@ namespace StgSharp.Math
|
||||
this.colum3 = colum3;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static Mat4 add(Mat4 left, Mat4 right)
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return new Mat4(
|
||||
left.colum0 + right.colum0,
|
||||
left.colum1 + right.colum1,
|
||||
left.colum2 + right.colum2,
|
||||
left.colum3 + right.colum3
|
||||
);
|
||||
return obj is Mat4 mat && Equals(mat);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static Mat4 sub(Mat4 left, Mat4 right)
|
||||
public bool Equals(Mat4 other)
|
||||
{
|
||||
return new Mat4(
|
||||
left.colum0 - right.colum0,
|
||||
left.colum1 - right.colum1,
|
||||
left.colum2 - right.colum2,
|
||||
left.colum3 - right.colum3
|
||||
);
|
||||
return colum0.Equals(other.colum0) &&
|
||||
colum1.Equals(other.colum1) &&
|
||||
colum2.Equals(other.colum2) &&
|
||||
colum3.Equals(other.colum3);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Mat4 left, Mat4 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Mat4 left, Mat4 right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +144,11 @@ namespace StgSharp.Math
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public float Det()
|
||||
{
|
||||
return mat.m00 * mat.m11 - mat.m10 * mat.m01;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -91,6 +91,15 @@ namespace StgSharp.Math
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe float Det()
|
||||
{
|
||||
fixed (Mat3* mat = &this.mat)
|
||||
{
|
||||
return internalIO.det_mat3(mat);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x3 operator +(Matrix3x3 left, Matrix3x3 right)
|
||||
{
|
||||
@@ -189,10 +198,5 @@ namespace StgSharp.Math
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +206,13 @@ namespace StgSharp.Math
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(
|
||||
mat.colum0.GetHashCode(),
|
||||
mat.colum1.GetHashCode()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -6,7 +7,7 @@ using System.Runtime.InteropServices;
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 7*4*sizeof(float)+ sizeof(bool),Pack =16 )]
|
||||
public struct Matrix4x3
|
||||
public struct Matrix4x3 : IEquatable<Matrix4x3>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
internal Mat3 mat;
|
||||
@@ -97,6 +98,17 @@ namespace StgSharp.Math
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is Matrix4x3 x && Equals(x);
|
||||
}
|
||||
|
||||
public bool Equals(Matrix4x3 other)
|
||||
{
|
||||
return EqualityComparer<Mat3>.Default.Equals(mat, other.mat);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix4x3 operator +(Matrix4x3 left, Matrix4x3 right)
|
||||
{
|
||||
@@ -118,6 +130,16 @@ namespace StgSharp.Math
|
||||
|
||||
}
|
||||
|
||||
public static bool operator ==(Matrix4x3 left, Matrix4x3 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(Matrix4x3 left, Matrix4x3 right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix4x3 operator *(Matrix4x3 mat, float value)
|
||||
{
|
||||
@@ -210,6 +232,14 @@ namespace StgSharp.Math
|
||||
);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(
|
||||
mat.colum0.GetHashCode(),
|
||||
mat.colum1.GetHashCode(),
|
||||
mat.colum2.GetHashCode()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,9 +3,6 @@ using System.Drawing;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
|
||||
@@ -103,7 +100,10 @@ namespace StgSharp.Math
|
||||
public static unsafe Matrix4x4 operator +(Matrix4x4 left, Matrix4x4 right)
|
||||
{
|
||||
return new Matrix4x4(
|
||||
Mat4.add( right.mat,left.mat)
|
||||
right.mat.colum0 + left.mat.colum0,
|
||||
right.mat.colum1 + left.mat.colum1,
|
||||
right.mat.colum2 + left.mat.colum2,
|
||||
right.mat.colum3 + left.mat.colum3
|
||||
);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,10 @@ namespace StgSharp.Math
|
||||
public static unsafe Matrix4x4 operator -(Matrix4x4 left, Matrix4x4 right)
|
||||
{
|
||||
return new Matrix4x4(
|
||||
Mat4.sub(right.mat, left.mat)
|
||||
right.mat.colum0-left.mat.colum0,
|
||||
right.mat.colum1-left.mat.colum1,
|
||||
right.mat.colum2-left.mat.colum2,
|
||||
right.mat.colum3-left.mat.colum3
|
||||
);
|
||||
}
|
||||
|
||||
@@ -196,7 +199,15 @@ namespace StgSharp.Math
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public static bool operator ==(Matrix4x4 left, Matrix4x4 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(Matrix4x4 left, Matrix4x4 right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe float Det()
|
||||
@@ -223,21 +234,32 @@ namespace StgSharp.Math
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
InternalTranspose();
|
||||
return
|
||||
$"{transpose.colum0}\n" +
|
||||
$"{transpose.colum1}\n" +
|
||||
$"{transpose.colum2}\n" +
|
||||
$"{transpose.colum3}";
|
||||
|
||||
return obj is Matrix4x4 x && Equals(x);
|
||||
}
|
||||
|
||||
public bool Equals(Matrix4x4 other)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return mat.Equals(other.mat);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(
|
||||
mat.colum0.GetHashCode(),
|
||||
mat.colum1.GetHashCode(),
|
||||
mat.colum2.GetHashCode(),
|
||||
mat.colum3.GetHashCode()
|
||||
);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
InternalTranspose();
|
||||
return $"{transpose.colum0}{transpose.colum1}{transpose.colum2}{transpose.colum3}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user