daily update on 2024.03.18 by itload youmu

This commit is contained in:
YoumuLiu
2024-03-19 02:41:04 +08:00
parent 15bf989285
commit 0c50c6282e
200 changed files with 7663 additions and 3455 deletions
+31 -1
View File
@@ -1,4 +1,34 @@
namespace StgSharp.Math
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Cordination.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp.Math
{
internal class Cordination
+51 -16
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="M128.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
@@ -19,35 +49,40 @@ namespace StgSharp.Math
[StructLayout(LayoutKind.Explicit, Pack = 16)]
public unsafe struct M128
{
[FieldOffset(0)] internal Vector4 vec;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Read<T>(int index) where T : struct
{
fixed (Vector4* p = &vec)
return *((T*)(p) + index);
{
return *(((T*)p) + index);
}
}
public override string ToString()
{
return string.Empty;
}
public string ToString(int sample)
{
string str = string.Empty;
for (int i = 0; i < 16; i++)
{
str += $"{Convert.ToString(this.Read<byte>(i), sample)} ";
}
return str;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Write<T>(int index, T value) where T : struct
{
fixed (Vector4* p = &vec)
*((T*)(p) + index) = value;
}
public override string ToString()
{
return "";
}
public string ToString(int sample)
{
string str = "";
for (int i = 0; i < 16; i++)
{
str += $"{Convert.ToString(this.Read<byte>(i), sample)} ";
*(((T*)p) + index) = value;
}
return str;
}
#if NET5_0_OR_GREATER
+31 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="MatInterface.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
+36 -5
View File
@@ -1,20 +1,51 @@
namespace StgSharp.Math
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Vector.Cross.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp.Math
{
public static unsafe partial class Vector
{
public static float Cross(Vec2d vec1, Vec2d vec2)
{
return vec1.X * vec2.Y - vec1.Y * vec2.X;
return (vec1.X * vec2.Y) - (vec1.Y * vec2.X);
}
public static vec3d Cross(vec3d vec1, vec3d vec2)
{
return new vec3d(
vec1.Y * vec2.Z - vec1.Z * vec2.Y,
vec1.X * vec2.Z - vec1.Z * vec2.X,
vec1.X * vec2.Y - vec1.Y * vec2.X
(vec1.Y * vec2.Z) - (vec1.Z * vec2.Y),
(vec1.X * vec2.Z) - (vec1.Z * vec2.X),
(vec1.X * vec2.Y) - (vec1.Y * vec2.X)
);
}
}
}
@@ -1,7 +1,38 @@
namespace StgSharp.Math
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Vector.GetAngle.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp.Math
{
public static unsafe partial class Vector
{
public static float GetAngle(Vec2d vec1, Vec2d vec2)
{
return Scaler.ACos(1
@@ -13,7 +44,7 @@
public static float GetAngle(vec3d vec1, vec3d vec2)
{
return Scaler.ACos(
vec1 * vec2
(vec1 * vec2)
/ (vec1.GetLength() * vec2.GetLength())
);
}
@@ -1,21 +1,52 @@
namespace StgSharp.Math
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Vector.GetLength.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp.Math
{
public static unsafe partial class Vector
{
public static float GetLength(this vec3d vec)
{
return Scaler.Sqrt(
vec.X * vec.X +
vec.Y * vec.Y +
vec.Z * vec.Z
(vec.X * vec.X) +
(vec.Y * vec.Y) +
(vec.Z * vec.Z)
);
}
public static float GetLength(this Vec2d vec)
{
return Scaler.Sqrt(
vec.X * vec.X +
vec.Y * vec.Y
(vec.X * vec.X) +
(vec.Y * vec.Y)
);
}
@@ -1,14 +1,40 @@
using System.Numerics;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Vector.VectorTransform.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System.Numerics;
using System.Runtime.CompilerServices;
namespace StgSharp.Math
{
public unsafe static partial class VectorCalc
public static unsafe partial class VectorCalc
{
public static vec3d To3D(Vec2d vec)
{
return new vec3d(vec.X, vec.Y, 0.0f);
}
public static Vec2d To2D(vec3d vec, CordinatePlain plain)
{
@@ -28,12 +54,17 @@ namespace StgSharp.Math
break;
}
}
public static vec3d To3D(Vec2d vec)
{
return new vec3d(vec.X, vec.Y, 0.0f);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static vec3d To3D(Vector4 vector)
{
return new vec3d(vector);
}
}
+49 -15
View File
@@ -1,4 +1,35 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="mat2.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Math;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -8,6 +39,7 @@ namespace StgSharp
{
internal static unsafe partial class InternalIO
{
#region add
[DllImport(InternalIO.SSC_libname, EntryPoint = "add_Mat2",
@@ -16,6 +48,15 @@ namespace StgSharp
internal static extern Mat2* add_mat2(Mat2* left, Mat2* right);
#endregion
#region deinit mat2
[DllImport(InternalIO.SSC_libname, EntryPoint = "deinit_mat2",
CallingConvention = CallingConvention.Cdecl)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static extern unsafe void deinit_mat2(Mat2* mat);
#endregion
#region sub
@@ -42,14 +83,6 @@ namespace StgSharp
#endregion
#region deinit mat2
[DllImport(InternalIO.SSC_libname, EntryPoint = "deinit_mat2",
CallingConvention = CallingConvention.Cdecl)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static extern unsafe void deinit_mat2(Mat2* mat);
#endregion
}
}
@@ -85,7 +118,7 @@ namespace StgSharp.Math
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override bool Equals(object? obj)
{
return obj is Mat2 mat && Equals(mat);
return (obj is Mat2 mat) && Equals(mat);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -95,16 +128,17 @@ namespace StgSharp.Math
colum1.Equals(other.colum1);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Mat2 left, Mat2 right)
{
return !(left == right);
}
[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);
}
}
}
+40 -7
View File
@@ -1,4 +1,35 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="mat3.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Math;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -34,6 +65,7 @@ namespace StgSharp
#endregion
}
}
@@ -66,7 +98,7 @@ namespace StgSharp.Math
public override bool Equals(object? obj)
{
return obj is Mat3 mat && Equals(mat);
return (obj is Mat3 mat) && Equals(mat);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -77,16 +109,17 @@ namespace StgSharp.Math
colum2.Equals(other.colum2);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Mat3 left, Mat3 right)
{
return !(left == right);
}
[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);
}
}
}
+60 -26
View File
@@ -1,5 +1,36 @@
using StgSharp;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="mat4.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp;
using StgSharp.Math;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -10,6 +41,26 @@ namespace StgSharp
internal static unsafe partial class InternalIO
{
#region deinit_mat4
[DllImport(InternalIO.SSC_libname, EntryPoint = "deinit_mat4",
CallingConvention = CallingConvention.Cdecl)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static extern void deinit_mat4(Mat4* mat);
#endregion
#region det
[DllImport(InternalIO.SSC_libname, EntryPoint = "det_mat4",
CallingConvention = CallingConvention.Cdecl)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static extern unsafe float det_mat4(Mat4* matPtr, Mat4* transpose);
#endregion
#region transpose
[DllImport(InternalIO.SSC_libname, EntryPoint = "transpose4to4",
@@ -27,25 +78,6 @@ namespace StgSharp
#endregion
#region det
[DllImport(InternalIO.SSC_libname, EntryPoint = "det_mat4",
CallingConvention = CallingConvention.Cdecl)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static unsafe extern float det_mat4(Mat4* matPtr, Mat4* transpose);
#endregion
#region deinit_mat4
[DllImport(InternalIO.SSC_libname, EntryPoint = "deinit_mat4",
CallingConvention = CallingConvention.Cdecl)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static extern void deinit_mat4(Mat4* mat);
#endregion
}
@@ -57,6 +89,7 @@ namespace StgSharp.Math
[StructLayout(LayoutKind.Explicit, Size = 16 * sizeof(float))]
public struct Mat4 : IEquatable<Mat4>, IMat
{
[FieldOffset(0)] internal Vector4 colum0;
[FieldOffset(16)] internal Vector4 colum1;
[FieldOffset(32)] internal Vector4 colum2;
@@ -98,7 +131,7 @@ namespace StgSharp.Math
public override bool Equals(object? obj)
{
return obj is Mat4 mat && Equals(mat);
return (obj is Mat4 mat) && Equals(mat);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -110,16 +143,17 @@ namespace StgSharp.Math
colum3.Equals(other.colum3);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Mat4 left, Mat4 right)
{
return !(left == right);
}
[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);
}
}
}
+33 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="mat5.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.InteropServices;
@@ -9,10 +39,12 @@ namespace StgSharp.Math.Linear
[StructLayout(LayoutKind.Explicit, Size = 5 * 4 * sizeof(float))]
public struct mat5 : IMat
{
[FieldOffset(0 * 4 * sizeof(float))] internal Vector4 vec0;
[FieldOffset(1 * 4 * sizeof(float))] internal Vector4 vec1;
[FieldOffset(2 * 4 * sizeof(float))] internal Vector4 vec2;
[FieldOffset(3 * 4 * sizeof(float))] internal Vector4 vec3;
[FieldOffset(4 * 4 * sizeof(float))] internal Vector4 vec4;
}
}
+33 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="mat6.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.InteropServices;
@@ -9,11 +39,13 @@ namespace StgSharp.Math.Linear
[StructLayout(LayoutKind.Sequential)]
public struct mat6 : IMat
{
internal Vector4 vec0;
internal Vector4 vec1;
internal Vector4 vec2;
internal Vector4 vec3;
internal Vector4 vec4;
internal Vector4 vec5;
}
}
+62 -31
View File
@@ -1,12 +1,43 @@
using System.Numerics;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix2x2.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = 2 * 2 * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
[StructLayout(LayoutKind.Explicit, Size = (2 * 2 * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
public struct Matrix2x2 : IMat
{
[FieldOffset(0)]
internal Mat2 mat;
[FieldOffset(2 * 4 * sizeof(float))]
@@ -14,13 +45,11 @@ namespace StgSharp.Math
[FieldOffset(2 * 2 * 4 * sizeof(float))]
internal bool isTransposed;
public Matrix2x2(
float a00, float a01,
float a10, float a11
internal Matrix2x2(
Mat2 mat
)
{
mat.colum0 = new Vector4(a00, a10, 0, 0);
mat.colum1 = new Vector4(a01, a11, 0, 0);
this.mat = mat;
}
internal Matrix2x2(
@@ -32,11 +61,13 @@ namespace StgSharp.Math
mat.colum1 = c1;
}
internal Matrix2x2(
Mat2 mat
public Matrix2x2(
float a00, float a01,
float a10, float a11
)
{
this.mat = mat;
mat.colum0 = new Vector4(a00, a10, 0, 0);
mat.colum1 = new Vector4(a01, a11, 0, 0);
}
public Matrix2x2 Transpose
@@ -48,6 +79,12 @@ namespace StgSharp.Math
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float Det()
{
return (mat.m00 * mat.m11) - (mat.m10 * mat.m01);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void InternalTranspose()
{
@@ -62,16 +99,6 @@ namespace StgSharp.Math
}
}
[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)
{
@@ -90,15 +117,6 @@ namespace StgSharp.Math
);
}
[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)
{
@@ -145,9 +163,22 @@ namespace StgSharp.Math
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float Det()
public static Matrix2x2 operator /(Matrix2x2 mat, float value)
{
return mat.m00 * mat.m11 - mat.m10 * mat.m01;
return new Matrix2x2(
mat.mat.colum0 / value,
mat.mat.colum1 / value
);
}
[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;
}
+79 -45
View File
@@ -1,27 +1,48 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix2x3.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = (3 + 2) * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
[StructLayout(LayoutKind.Explicit, Size = ((3 + 2) * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
public struct Matrix2x3
{
[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
)
{
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(
Vector4 c0,
Vector4 c1,
@@ -33,43 +54,53 @@ namespace StgSharp.Math
mat.colum2 = c2;
}
public Matrix2x3(
float a00, float a01, float a02,
float a10, float a11, float a12
)
{
mat.colum0 = new Vector4(a00, a10, 0, 0);
mat.colum1 = new Vector4(a01, a11, 0, 0);
mat.colum2 = new Vector4(a02, a12, 0, 0);
}
public unsafe float this[int rowNum, int columNum]
{
get
{
if (rowNum > 1 || rowNum < 0)
if ((rowNum > 1) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 2 || columNum < 0)
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;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
return *(float*)pbit;
}
}
set
{
if (rowNum > 1 || rowNum < 0)
if ((rowNum > 1) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 2 || columNum < 0)
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;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
*(float*)pbit = value;
}
isTransposed = false;
@@ -81,24 +112,17 @@ namespace StgSharp.Math
{
if (!isTransposed)
{
fixed(Mat3* source = &this.mat)
fixed(Mat2* target = &this.transpose)
fixed (Mat3* source = &this.mat)
{
InternalIO.Transpose3to2_internal(source, target);
fixed (Mat2* target = &this.transpose)
{
InternalIO.Transpose3to2_internal(source, target);
}
}
isTransposed = true;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x3 operator +(Matrix2x3 left, Matrix2x3 right)
{
return new Matrix2x3(
left.mat.colum0 + right.mat.colum0,
left.mat.colum1 + right.mat.colum1,
left.mat.colum2 + right.mat.colum2
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x3 operator -(Matrix2x3 left, Matrix2x3 right)
@@ -120,16 +144,6 @@ namespace StgSharp.Math
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x3 operator /(Matrix2x3 mat, float value)
{
return new Matrix2x3(
mat.mat.colum0 / value,
mat.mat.colum1 / value,
mat.mat.colum2 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x2 operator *(Matrix2x3 left, Matrix3x2 right)
{
@@ -175,6 +189,26 @@ namespace StgSharp.Math
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x3 operator /(Matrix2x3 mat, float value)
{
return new Matrix2x3(
mat.mat.colum0 / value,
mat.mat.colum1 / value,
mat.mat.colum2 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x3 operator +(Matrix2x3 left, Matrix2x3 right)
{
return new Matrix2x3(
left.mat.colum0 + right.mat.colum0,
left.mat.colum1 + right.mat.colum1,
left.mat.colum2 + right.mat.colum2
);
}
}
+85 -52
View File
@@ -1,13 +1,44 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix2x4.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
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)]
[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;
@@ -17,18 +48,6 @@ namespace StgSharp.Math
[FieldOffset(32)] public Vec2d Colum2;
[FieldOffset(48)] public Vec2d Colum3;
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,
@@ -42,74 +61,84 @@ namespace StgSharp.Math
mat.colum3 = c3;
}
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);
}
public unsafe float this[int rowNum, int columNum]
{
get
{
if (rowNum > 1 || rowNum < 0)
if ((rowNum > 1) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 3 || columNum < 0)
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;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
return *(float*)pbit;
}
}
set
{
if (rowNum > 1 || rowNum < 0)
if ((rowNum > 1) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 3 || columNum < 0)
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;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
*(float*)pbit = value;
}
isTransposed = false;
}
}
public override string ToString()
{
InternalTranspose();
return $"{($"[{mat.m00},{mat.m01},{mat.m02},{mat.m03}],")}{($"[{mat.m10},{mat.m11},{mat.m12},{mat.m13}]")}";
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal unsafe void InternalTranspose()
{
if (!isTransposed)
{
fixed (Mat4* source = &this.mat)
fixed (Mat2* target = &this.transpose)
{
InternalIO.Transpose4to2_internal(source, target);
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)
{
@@ -132,17 +161,6 @@ namespace StgSharp.Math
);
}
[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)
{
@@ -188,11 +206,26 @@ namespace StgSharp.Math
);
}
public override string ToString()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x4 operator /(Matrix2x4 mat, float value)
{
InternalTranspose();
return $"[{mat.m00},{mat.m01},{mat.m02},{mat.m03}]," +
$"[{mat.m10},{mat.m11},{mat.m12},{mat.m13}]";
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 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
);
}
+80 -46
View File
@@ -1,19 +1,59 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix3x2.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
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)]
[StructLayout(LayoutKind.Explicit, Size = (5 * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
public struct Matrix3x2
{
[FieldOffset(0)] internal Mat2 mat;
[FieldOffset(0)] internal vec3d colum0;
[FieldOffset(4 * 4)] internal vec3d colum1;
[FieldOffset(2 * 4 * sizeof(float))] internal Mat3 transpose;
[FieldOffset(5 * 4 * sizeof(float))] internal bool isTransposed;
internal Matrix3x2(
Vector4 c0,
Vector4 c1
)
{
mat.colum0 = c0;
mat.colum1 = c1;
}
public unsafe Matrix3x2(
float a00, float a01,
@@ -30,86 +70,71 @@ namespace StgSharp.Math
#endif
}
internal Matrix3x2(
Vector4 c0,
Vector4 c1
)
{
mat.colum0 = c0;
mat.colum1 = c1;
}
public vec3d VerticalVecMultiply(Vec2d vec)
{
return colum0 * vec.X + colum1 * vec.Y;
}
public unsafe float this[int rowNum, int columNum]
{
get
{
if (rowNum > 2 || rowNum < 0)
if ((rowNum > 2) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 1 || columNum < 0)
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;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
return *(float*)pbit;
}
}
set
{
if (rowNum > 2 || rowNum < 0)
if ((rowNum > 2) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 1 || columNum < 0)
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;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
*(float*)pbit = value;
}
isTransposed = false;
}
}
public vec3d VerticalVecMultiply(Vec2d vec)
{
return (colum0 * vec.X) + (colum1 * vec.Y);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal unsafe void InternalTranspose()
{
if (!isTransposed)
{
fixed (Mat2* source = &this.mat)
fixed (Mat3* target = &this.transpose)
{
InternalIO.Transpose2to3_internal(source, target);
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)
{
@@ -128,15 +153,6 @@ namespace StgSharp.Math
);
}
[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)
{
@@ -194,6 +210,24 @@ namespace StgSharp.Math
);
}
[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, Matrix3x2 right)
{
return new Matrix3x2(
left.mat.colum0 + right.mat.colum0,
left.mat.colum1 + right.mat.colum1
);
}
}
}
+83 -52
View File
@@ -1,13 +1,44 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix3x3.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = 6 * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
[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;
@@ -15,17 +46,6 @@ namespace StgSharp.Math
[FieldOffset(1 * 4 * sizeof(float))] public vec3d Colum1;
[FieldOffset(2 * 4 * sizeof(float))] public vec3d Colum2;
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,
@@ -37,34 +57,45 @@ namespace StgSharp.Math
mat.colum2 = c2;
}
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);
}
public unsafe float this[int rowNum, int columNum]
{
get
{
if (rowNum > 2 || rowNum < 0)
if ((rowNum > 2) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 2 || columNum < 0)
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;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
return *(float*)pbit;
}
}
set
{
if (rowNum > 2 || rowNum < 0)
if ((rowNum > 2) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 2 || columNum < 0)
if ((columNum > 2) || (columNum < 0))
{
InternalIO.InternalWriteLog(
$"Attempt to write unused space in {GetType().Name} {nameof(mat)}",
@@ -74,15 +105,24 @@ namespace StgSharp.Math
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
*(float*)pbit = value;
}
isTransposed = false;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe float Det()
{
fixed (Mat3* mat = &this.mat)
{
return InternalIO.det_mat3(mat);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal unsafe void InternalTranspose()
{
@@ -96,25 +136,6 @@ 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)
{
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)
{
@@ -135,16 +156,6 @@ namespace StgSharp.Math
);
}
[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 vec3d operator *(Matrix3x3 left, vec3d right)
{
@@ -213,6 +224,26 @@ namespace StgSharp.Math
);
}
[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 left, Matrix3x3 right)
{
return new Matrix3x3(
left.mat.colum0 + right.mat.colum0,
left.mat.colum1 + right.mat.colum1,
left.mat.colum2 + right.mat.colum2
);
}
}
}
+81 -47
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix3x4.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Drawing;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -7,9 +37,10 @@ using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = 7 * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
[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;
@@ -19,16 +50,9 @@ namespace StgSharp.Math
[FieldOffset(2 * 4 * sizeof(float))] public vec3d Colum2;
[FieldOffset(3 * 4 * sizeof(float))] public vec3d Colum3;
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
)
internal Matrix3x4(Mat4 mat)
{
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);
this.mat = mat;
}
internal Matrix3x4(
@@ -44,48 +68,55 @@ namespace StgSharp.Math
mat.colum3 = c3;
}
internal Matrix3x4(Mat4 mat)
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
)
{
this.mat = mat;
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);
}
public unsafe float this[int rowNum, int columNum]
{
get
{
if (rowNum > 2 || rowNum < 0)
if ((rowNum > 2) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 3 || columNum < 0)
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;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
return *(float*)pbit;
}
}
set
{
if (rowNum > 2 || rowNum < 0)
if ((rowNum > 2) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 3 || columNum < 0)
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;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
*(float*)pbit = value;
}
isTransposed = false;
@@ -97,25 +128,17 @@ namespace StgSharp.Math
if (!isTransposed)
{
fixed (Mat4* source = &this.mat)
fixed (Mat3* target = &this.transpose)
{
InternalIO.Transpose4to3_internal(source, target);
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)
{
@@ -138,17 +161,6 @@ namespace StgSharp.Math
);
}
[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)
{
@@ -206,6 +218,28 @@ namespace StgSharp.Math
);
}
[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 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
);
}
+95 -61
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix4x2.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -8,13 +38,28 @@ namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = (16 + 8) * sizeof(float) + sizeof(bool), Pack = 16)]
[StructLayout(LayoutKind.Explicit, Size = ((16 + 8) * sizeof(float)) + sizeof(bool), Pack = 16)]
public struct Matrix4x2
{
[FieldOffset(0)] internal Mat2 mat;
[FieldOffset(8 * sizeof(float))] internal Mat4 transpose;
[FieldOffset((16 + 8) * sizeof(float))] internal bool isTransposed;
internal Matrix4x2(Mat2 mat)
{
this.mat = mat;
}
internal Matrix4x2(
Vector4 c0,
Vector4 c1
)
{
mat.colum0 = c0;
mat.colum1 = c1;
}
public Matrix4x2(
float a00, float a01,
@@ -27,71 +72,82 @@ namespace StgSharp.Math
mat.colum1 = new Vector4(a01, a11, a21, a31);
}
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)
if ((rowNum > 3) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 1 || columNum < 0)
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;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
return *(float*)pbit;
}
}
set
{
if (rowNum > 3 || rowNum < 0)
if ((rowNum > 3) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 1 || columNum < 0)
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;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
*(float*)pbit = value;
}
isTransposed = false;
}
}
public override int GetHashCode()
{
return HashCode.Combine(
mat.colum0.GetHashCode(),
mat.colum1.GetHashCode()
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x2 operator +(Matrix4x2 left, Matrix4x2 right)
internal unsafe void InternalTranspose()
{
if (!isTransposed)
{
fixed (Mat2* source = &this.mat)
{
fixed (Mat4* target = &this.transpose)
{
InternalIO.Transpose2to4_internal(source, target);
}
}
isTransposed = true;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x2 operator -(Matrix4x2 left, Matrix4x2 right)
{
return new Matrix4x2(
left.mat.colum0 + right.mat.colum0,
left.mat.colum0 + right.mat.colum0
left.mat.colum0 - right.mat.colum0,
left.mat.colum0 - right.mat.colum0
);
}
@@ -104,24 +160,6 @@ namespace StgSharp.Math
);
}
[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)
{
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)
{
@@ -192,24 +230,20 @@ namespace StgSharp.Math
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal unsafe void InternalTranspose()
public static Matrix4x2 operator /(Matrix4x2 mat, float value)
{
if (!isTransposed)
{
fixed (Mat2* source = &this.mat)
fixed (Mat4* target = &this.transpose)
{
InternalIO.Transpose2to4_internal(source, target);
}
isTransposed = true;
}
return new Matrix4x2(
mat.mat.colum0 / value,
mat.mat.colum1 / value
);
}
public override int GetHashCode()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x2 operator +(Matrix4x2 left, Matrix4x2 right)
{
return HashCode.Combine(
mat.colum0.GetHashCode(),
mat.colum1.GetHashCode()
return new Matrix4x2(
left.mat.colum0 + right.mat.colum0,
left.mat.colum0 + right.mat.colum0
);
}
+100 -65
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix4x3.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -6,9 +36,10 @@ using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = 7 * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
[StructLayout(LayoutKind.Explicit, Size = (7 * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
public struct Matrix4x3 : IEquatable<Matrix4x3>
{
[FieldOffset(0)]
internal Mat3 mat;
@@ -18,6 +49,17 @@ namespace StgSharp.Math
[FieldOffset(7 * 4 * sizeof(float))]
internal bool isTransposed;
internal Matrix4x3(
Vector4 c0,
Vector4 c1,
Vector4 c2
)
{
mat.colum0 = c0;
mat.colum1 = c1;
mat.colum2 = c2;
}
public Matrix4x3(
float a00, float a01, float a02,
float a10, float a11, float a12,
@@ -30,94 +72,85 @@ namespace StgSharp.Math
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)
if ((rowNum > 3) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 2 || columNum < 0)
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;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
return *(float*)pbit;
}
}
set
{
if (rowNum > 3 || rowNum < 0)
if ((rowNum > 3) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 2 || columNum < 0)
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;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
*(float*)pbit = value;
}
isTransposed = false;
}
}
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);
}
public override int GetHashCode()
{
return HashCode.Combine(
mat.colum0.GetHashCode(),
mat.colum1.GetHashCode(),
mat.colum2.GetHashCode()
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal unsafe void InternalTranspose()
{
if (!isTransposed)
{
fixed (Mat3* source = &this.mat)
fixed (Mat4* target = &this.transpose)
{
InternalIO.Transpose3to4_internal(source, target);
fixed (Mat4* target = &this.transpose)
{
InternalIO.Transpose3to4_internal(source, target);
}
}
isTransposed = true;
}
}
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)
{
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)
{
@@ -128,11 +161,6 @@ 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);
@@ -148,16 +176,6 @@ namespace StgSharp.Math
);
}
[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)
{
@@ -230,13 +248,30 @@ namespace StgSharp.Math
);
}
public override int GetHashCode()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x3 operator /(Matrix4x3 mat, float value)
{
return HashCode.Combine(
mat.colum0.GetHashCode(),
mat.colum1.GetHashCode(),
mat.colum2.GetHashCode()
return new Matrix4x3(
mat.mat.colum0 / value,
mat.mat.colum1 / value,
mat.mat.colum2 / value
);
}
[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
);
}
public static bool operator ==(Matrix4x3 left, Matrix4x3 right)
{
return left.Equals(right);
}
}
}
+151 -120
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix4x4.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Drawing;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -8,15 +38,34 @@ using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = 2*16*sizeof(float)+sizeof(bool), Pack = 16)]
[StructLayout(LayoutKind.Explicit, Size = (2 * 16 * sizeof(float)) + sizeof(bool), Pack = 16)]
public struct Matrix4x4 : IEquatable<Matrix4x4>
{
[FieldOffset(0)] internal Mat4 mat;
[FieldOffset(64*sizeof(float))] internal Mat4 transpose;
[FieldOffset(2*64*sizeof(float))]internal bool isTransposed;
[FieldOffset(64 * sizeof(float))] internal Mat4 transpose;
[FieldOffset(2 * 64 * sizeof(float))] internal bool isTransposed;
internal Matrix4x4(Mat4 mat)
{
this.mat = mat;
}
internal Matrix4x4(
Vector4 vec0,
Vector4 vec1,
Vector4 vec2,
Vector4 vec3
)
{
mat.colum0 = vec0;
mat.colum1 = vec1;
mat.colum2 = vec2;
mat.colum3 = vec3;
}
public unsafe Matrix4x4(
float a00, float a01, float a02, float a03,
@@ -36,40 +85,40 @@ namespace StgSharp.Math
{
get
{
if (rowNum>3||rowNum<0)
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;
return *(float*)pbit;
}
}
set
{
if (rowNum > 3 || rowNum < 0)
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 3 || columNum < 0)
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;
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 > 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;
@@ -78,46 +127,73 @@ namespace StgSharp.Math
}
internal Matrix4x4(
Vector4 vec0,
Vector4 vec1,
Vector4 vec2,
Vector4 vec3
)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe float Det()
{
mat.colum0 = vec0;
mat.colum1 = vec1;
mat.colum2 = vec2;
mat.colum3 = vec3;
InternalTranspose();
fixed (Mat4* _this = &mat, _trans = &transpose)
{
return InternalIO.det_mat4(_this, _trans);
}
}
internal Matrix4x4(Mat4 mat)
public override bool Equals(object? obj)
{
this.mat = mat;
return (obj is Matrix4x4 x) && Equals(x);
}
public bool Equals(Matrix4x4 other)
{
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}";
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x4 operator +(Matrix4x4 left, Matrix4x4 right)
internal unsafe void InternalTranspose()
{
return new Matrix4x4(
right.mat.colum0 + left.mat.colum0,
right.mat.colum1 + left.mat.colum1,
right.mat.colum2 + left.mat.colum2,
right.mat.colum3 + left.mat.colum3
);
if (!isTransposed)
{
fixed (Mat4* source = &this.mat, target = &this.transpose)
{
InternalIO.Transpose4to4_internal(source, target);
}
isTransposed = true;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x4 operator -(Matrix4x4 left, Matrix4x4 right)
{
return new Matrix4x4(
right.mat.colum0-left.mat.colum0,
right.mat.colum1-left.mat.colum1,
right.mat.colum2-left.mat.colum2,
right.mat.colum3-left.mat.colum3
right.mat.colum0 - left.mat.colum0,
right.mat.colum1 - left.mat.colum1,
right.mat.colum2 - left.mat.colum2,
right.mat.colum3 - left.mat.colum3
);
}
public static bool operator !=(Matrix4x4 left, Matrix4x4 right)
{
return !(left == right);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x4 operator *(Matrix4x4 mat, float value)
{
@@ -153,21 +229,21 @@ namespace StgSharp.Math
{
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.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.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)
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)
);
}
@@ -199,65 +275,20 @@ 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()
public static unsafe Matrix4x4 operator +(Matrix4x4 left, Matrix4x4 right)
{
InternalTranspose();
fixed (Mat4* _this = &mat, _trans = &transpose)
{
return InternalIO.det_mat4(_this,_trans);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal unsafe void InternalTranspose()
{
if (!isTransposed)
{
fixed (Mat4* source = &this.mat, target = &this.transpose)
{
InternalIO.Transpose4to4_internal(source, target);
}
isTransposed = true;
}
}
public override bool Equals(object? obj)
{
return obj is Matrix4x4 x && Equals(x);
}
public bool Equals(Matrix4x4 other)
{
return mat.Equals(other.mat);
}
public override int GetHashCode()
{
return HashCode.Combine(
mat.colum0.GetHashCode(),
mat.colum1.GetHashCode(),
mat.colum2.GetHashCode(),
mat.colum3.GetHashCode()
return new Matrix4x4(
right.mat.colum0 + left.mat.colum0,
right.mat.colum1 + left.mat.colum1,
right.mat.colum2 + left.mat.colum2,
right.mat.colum3 + left.mat.colum3
);
}
public override string ToString()
public static bool operator ==(Matrix4x4 left, Matrix4x4 right)
{
InternalTranspose();
return $"{transpose.colum0}{transpose.colum1}{transpose.colum2}{transpose.colum3}";
return left.Equals(right);
}
}
+49 -25
View File
@@ -1,4 +1,34 @@
using System.Numerics;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="vec2d.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -22,30 +52,23 @@ namespace StgSharp.Math
[FieldOffset(0)]
internal Vector2 v;
public Vec2d(float x, float y)
{
v = new Vector2(x, y);
}
internal Vec2d(Vector2 vec)
{
v = vec;
}
public static Vec2d Zero
public Vec2d(float x, float y)
{
get { return new Vec2d(0, 0); }
v = new Vector2(x, y);
}
public static Vec2d Unit
{
get { return new Vec2d(1, 1); }
}
public static Vec2d Unit => new Vec2d(1, 1);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vec2d operator +(Vec2d left, Vec2d right)
public static Vec2d Zero => new Vec2d(0, 0);
public float Cross(Vec2d right)
{
return new Vec2d(left.v + right.v);
return (X * right.Y) - (Y * right.X);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -54,6 +77,11 @@ namespace StgSharp.Math
return new Vec2d(left.v - right.v);
}
public static bool operator !=(Vec2d left, Vec2d right)
{
return !(left == right);
}
public static Vec2d operator *(Vec2d vec, float value)
{
return new Vec2d(vec.v * value);
@@ -64,20 +92,16 @@ namespace StgSharp.Math
return new Vec2d(vec.v / value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vec2d operator +(Vec2d left, Vec2d right)
{
return new Vec2d(left.v + right.v);
}
public static bool operator ==(Vec2d left, Vec2d right)
{
return left.v == right.v;
}
public static bool operator !=(Vec2d left, Vec2d right)
{
return !(left == right);
}
public float Cross(Vec2d right)
{
return X * right.Y - Y * right.X;
}
}
}
+125 -88
View File
@@ -1,4 +1,35 @@
using StgSharp.Controlling;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="vec3d.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Controlling;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -10,6 +41,7 @@ namespace StgSharp.Math
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
public struct vec3d : IEquatable<vec3d>
{
[FieldOffset(0)]
internal Vector4 vec;
[FieldOffset(0)]
@@ -19,21 +51,6 @@ namespace StgSharp.Math
[FieldOffset(4)] public float Y;
[FieldOffset(8)] public float Z;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public vec3d Zero()
{
return new vec3d(0, 0, 0);
}
public vec3d(
float x, float y, float z)
{
#if NET5_0_OR_GREATER
Unsafe.SkipInit(out vec);
#endif
v = new Vector3(x, y, z);
}
internal vec3d(Vector4 vector)
{
vec = vector;
@@ -44,6 +61,25 @@ namespace StgSharp.Math
v = vector;
}
public vec3d(
float x, float y, float z)
{
#if NET5_0_OR_GREATER
Unsafe.SkipInit(out vec);
#endif
v = new Vector3(x, y, z);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public vec3d Cross(vec3d right)
{
return new vec3d(
(this.Y * right.Z) - (this.Z * right.Y),
(this.X * right.Z) - (this.Z * right.X),
(this.X * right.Y) - (this.Y * right.X)
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float Dot(vec3d right)
{
@@ -53,75 +89,6 @@ namespace StgSharp.Math
+ vector4.Z;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public vec3d Cross(vec3d right)
{
return new vec3d(
this.Y * right.Z - this.Z * right.Y,
this.X * right.Z - this.Z * right.X,
this.X * right.Y - this.Y * right.X
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d operator +(vec3d left, vec3d right)
{
return new vec3d(
left.vec + right.vec
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float GetMaxValue()
{
float ret = X;
ret = ret > Y ? ret : Y;
ret = ret > Z ? ret : Z;
return ret;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d operator -(vec3d left, vec3d right)
{
return new vec3d(left.v - right.v);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d operator *(vec3d vec, float value)
{
return new vec3d(vec.v * value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d operator /(vec3d vec, float value)
{
return new vec3d(vec.v / value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float operator *(vec3d left, vec3d right)
{
return Vector3.Dot(left.v, right.v);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(vec3d left, vec3d right)
{
return left.v == right.v;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(vec3d left, vec3d right)
{
return left.v != right.v;
}
public string ToString(string sample)
{
return $"[{X.ToString(sample)},{Y.ToString(sample)},{Z.ToString(sample)}]";
}
public bool Equals(vec3d other)
{
return this.vec == other.vec;
@@ -139,21 +106,91 @@ namespace StgSharp.Math
}
}
public unsafe override int GetHashCode()
public override unsafe int GetHashCode()
{
fixed (float* add = &X)
{
return HashCode.Combine(X, Y, Z, (ulong)add);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float GetMaxValue()
{
float ret = X;
ret = (ret > Y) ? ret : Y;
ret = (ret > Z) ? ret : Z;
return ret;
}
public override string ToString()
{
return $"[{X},{Y},{Z}]";
}
public string ToString(string sample)
{
return $"[{X.ToString(sample)},{Y.ToString(sample)},{Z.ToString(sample)}]";
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public vec3d Zero()
{
return new vec3d(0, 0, 0);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d operator -(vec3d left, vec3d right)
{
return new vec3d(left.v - right.v);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(vec3d left, vec3d right)
{
return left.v != right.v;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d operator *(vec3d vec, float value)
{
return new vec3d(vec.v * value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float operator *(vec3d left, vec3d right)
{
return Vector3.Dot(left.v, right.v);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d operator /(vec3d vec, float value)
{
return new vec3d(vec.v / value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d operator +(vec3d left, vec3d right)
{
return new vec3d(
left.vec + right.vec
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(vec3d left, vec3d right)
{
return left.v == right.v;
}
}
public static class Vec3d
{
public static vec3d Unit { get => new vec3d(1, 1, 1); }
public static vec3d Zero { get => new vec3d(0, 0, 0); }
public static vec3d Unit => new vec3d(1, 1, 1);
public static vec3d Zero => new vec3d(0, 0, 0);
}
}
+33 -1
View File
@@ -1,4 +1,34 @@
using StgSharp.Controlling;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Vec4d.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Controlling;
using StgSharp.Math;
using System;
@@ -11,6 +41,7 @@ namespace StgSharp.Math
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
public struct Vec4d
{
[FieldOffset(0)] internal Vector4 vec;
[FieldOffset(0)] internal M128 reg;
@@ -28,5 +59,6 @@ namespace StgSharp.Math
{
return vec.reg;
}
}
}