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
+33 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLfixed.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.Runtime.InteropServices;
@@ -10,8 +40,10 @@ namespace StgSharp.Math
[StructLayout(LayoutKind.Explicit, Size = 8)]
public struct GLfixed
{
[FieldOffset(0)] public int All;
[FieldOffset(0)] public short Decimals;
[FieldOffset(4)] public short Inertger;
}
}
+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;
}
}
}
+32 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ACos.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.Runtime.CompilerServices;
namespace StgSharp.Math
@@ -75,5 +105,6 @@ namespace StgSharp.Math
return piby2 - v;
*/
}
}
}
+32 -1
View File
@@ -1,4 +1,34 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ASin.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//
//
// some of the code is rewritten from the AMD code:
// https://github.com/amd/aocl-libm-ose/blob/a43e092b03213eb0e129a1cc129900e6e4475778/src/ref/asinf.c
@@ -89,5 +119,6 @@ namespace StgSharp.Math
return sign * v;
*/
}
}
}
+32 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ATan.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.Runtime.CompilerServices;
namespace StgSharp.Math
@@ -84,5 +114,6 @@ namespace StgSharp.Math
return v;
*/
}
}
}
+33 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BasicOps.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.Globalization;
using System.Runtime.CompilerServices;
@@ -6,6 +36,7 @@ namespace StgSharp.Math
{
public static unsafe partial class Scaler
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe float Abs(float x)
{
@@ -36,5 +67,6 @@ namespace StgSharp.Math
return CultureInfo.CurrentCulture.TextInfo.ListSeparator;
}
}
}
+34 -3
View File
@@ -1,4 +1,34 @@
namespace StgSharp.Math
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Cos.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 partial class Scaler
{
@@ -15,8 +45,9 @@
float refer2 = refer * refer;
return -sinData[a] * (0.1570796327f * refer - 6.459640975e-4f * refer * refer2)
+ cosData[a] * (1 - 0.0123370055f * refer2 + 2.536695709e-5f * refer2 * refer2);
return ((-sinData[a]) * ((0.1570796327f * refer) - (6.459640975e-4f * refer * refer2)))
+ (cosData[a] * ((1 - (0.0123370055f * refer2)) + (2.536695709e-5f * refer2 * refer2)));
}
}
}
+41 -9
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Ctor.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.Runtime.InteropServices;
namespace StgSharp.Math
@@ -7,18 +37,20 @@ namespace StgSharp.Math
public static unsafe partial class Scaler
{
const uint MEM_COMMIT = 0x1000;
const uint MEM_RELEASE = 0x8000;
const uint MEM_RESERVE = 0x2000;
const uint PAGE_EXECUTE_READWRITE = 0x40;
static Scaler()
{
}
[DllImport("Kernel32.dll", EntryPoint = "VirtualAlloc")]
private static extern IntPtr VirtualAlloc(IntPtr address, int size, uint allocType, uint protect);
[DllImport("Kernel32.dll", EntryPoint = "VirtualFree")]
private static extern bool VirtualFree(IntPtr address, int size, uint freeType);
const uint MEM_COMMIT = 0x1000;
const uint MEM_RESERVE = 0x2000;
const uint PAGE_EXECUTE_READWRITE = 0x40;
const uint MEM_RELEASE = 0x8000;
static Scaler()
{
}
}
}
+47 -15
View File
@@ -1,9 +1,40 @@
namespace StgSharp.Math
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Exp.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 Scaler
{
public const float E = 2.718281828f;
/// <summary>
/// Get the value of E ^ x;
/// </summary>
@@ -30,12 +61,12 @@
float z = x, t;
if (x < 0.5f)
{
t = 1.0f + x * (
1.0f + x * (
0.5f + x * (
0.1666666667f + x * (
0.0416666666667f + x *
8.333333333e-3f))));
t = 1.0f + (x * (
1.0f + (x * (
0.5f + (x * (
0.1666666667f + (x * (
0.0416666666667f + (x *
8.333333333e-3f)))))))));
}
else
{
@@ -45,20 +76,20 @@
*/
uint zBit = *(uint*)&z;
uint zBitAbs = zBit & 0b_0111_1111_1111_1111_1111_1111_1111_1111;
uint uintm = (zBitAbs >> 23);
uint uintm = zBitAbs >> 23;
int m = (*(int*)&uintm) - 126;
uint nBit = (zBitAbs & 0b_0000_0000_0111_1111_1111_1111_1111_1111)
+ 0b_0011_1111_0000_0000_0000_0000_0000_0000;
float n = *(float*)&nBit - 1;
float n = (*(float*)&nBit) - 1;
t = 2.718281828f + n * (
2.718281828f + n * (
1.359140914f + n * (
0.4530469714f + n * (
0.1132617429f + n *
0.02265234857f))));
t = 2.718281828f + (n * (
2.718281828f + (n * (
1.359140914f + (n * (
0.4530469714f + (n * (
0.1132617429f + (n *
0.02265234857f)))))))));
for (int i = 0; i < m; i++)
{
@@ -72,5 +103,6 @@
}
return t;
}
}
}
+31 -1
View File
@@ -1,4 +1,34 @@
namespace StgSharp.Math
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Function.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 class Function
{
+38 -8
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Log.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;
namespace StgSharp.Math
{
@@ -41,16 +71,16 @@ namespace StgSharp.Math
input >>= 9;
input += 0b_0011_1111_1000_0000_0000_0000_0000_0000;
float result = *(float*)&input;
uint order = (uint)(result * 100) - 100;
float cache = (result) / (1f + 0.01f * order) - 1;
result = cache * -0.25f + 0.3333333333333f;
result = result * cache - 0.5f;
result = result * cache + 1.0f;
uint order = ((uint)(result * 100)) - 100;
float cache = (result / (1f + (0.01f * order))) - 1;
result = (cache * (-0.25f)) + 0.3333333333333f;
result = (result * cache) - 0.5f;
result = (result * cache) + 1.0f;
result *= cache;
return
f * 0.6931471806f +
(f * 0.6931471806f) +
result +
logArray[order];
}
+50 -18
View File
@@ -1,7 +1,38 @@
namespace StgSharp.Math
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Pow.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 Scaler
{
/// <summary>
/// calculate the value of x^y
/// </summary>
@@ -23,15 +54,15 @@
*
*/
float z, t;
if (x == 1 || y == 0)
if ((x == 1) || (y == 0))
{
return 1;
}
if (x == 1 && y == 0)
if ((x == 1) && (y == 0))
{
return float.PositiveInfinity;
}
if (x==0&&y!=0)
if ((x == 0) && (y != 0))
{
return 0;
}
@@ -47,31 +78,31 @@
if (z < 0.5f)
{
t = 1.0f + z * (
1.0f + z * (
0.5f + z * (
0.1666666667f + z * (
0.0416666666667f + z *
8.333333333e-3f))));
t = 1.0f + (z * (
1.0f + (z * (
0.5f + (z * (
0.1666666667f + (z * (
0.0416666666667f + (z *
8.333333333e-3f)))))))));
}
else
{
uint zBit = *(uint*)&z;
uint zBitAbs = zBit & 0b_0111_1111_1111_1111_1111_1111_1111_1111;
uint uintm = (zBitAbs >> 23);
uint uintm = zBitAbs >> 23;
int m = (*(int*)&uintm) - 126;
uint nBit = (zBitAbs & 0b_0000_0000_0111_1111_1111_1111_1111_1111)
+ 0b_0011_1111_0000_0000_0000_0000_0000_0000;
float n = *(float*)&nBit - 1;
float n = (*(float*)&nBit) - 1;
t = 2.718281828f + n * (
2.718281828f + n * (
1.359140914f + n * (
0.4530469714f + n * (
0.1132617429f + n *
0.02265234857f))));
t = 2.718281828f + (n * (
2.718281828f + (n * (
1.359140914f + (n * (
0.4530469714f + (n * (
0.1132617429f + (n *
0.02265234857f)))))))));
for (int i = 0; i < m; i++)
{
@@ -87,5 +118,6 @@
return t;
}
}
}
+43 -11
View File
@@ -1,4 +1,35 @@
using StgSharp.Controlling;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Random.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.Collections.Generic;
using System.Runtime.CompilerServices;
@@ -16,15 +47,6 @@ namespace StgSharp.Math
= Abs(System.DateTime.UtcNow.GetHashCode());
#endif
/// <summary>
///
/// </summary>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Random()
{
throw new NotImplementedException();
}
/// <summary>
/// returns a random float number between 0 and 1.
@@ -46,7 +68,7 @@ namespace StgSharp.Math
currentSeed = sample;
sample2 *= 1000000;
float result = sample2 - (int)sample2;
float result = sample2 - ((int)sample2);
if (result == 0)
{
currentSeed = sample2 + 0.1f;
@@ -55,6 +77,15 @@ namespace StgSharp.Math
return result;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Random()
{
throw new NotImplementedException();
}
/// <summary>
/// Generates a random seed in int value.
@@ -70,5 +101,6 @@ namespace StgSharp.Math
return *(int*)&seedValue;
}
}
}
+49 -16
View File
@@ -1,11 +1,56 @@
using System.Net.NetworkInformation;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Sin.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.Net.NetworkInformation;
namespace StgSharp.Math
{
public static partial class Scaler
{
public const float Pi = 3.1415926f;
private static readonly float[] cosData =
{
1f, 0.987688341014302f, 0.951056517951169f, 0.891006527837756f, 0.809017000674805f,
0.707106790659974f, 0.587785265298989f, 0.453990516451646f, 0.309017014761716f, 0.156434488858737f,
2.67948965850537E-08f, -0.156434435928723f, -0.309016963794794f, -0.453990468702791f, -0.587785221943935f,
-0.707106752766267f, -0.809016969175515f, -0.891006503508499f, -0.951056501391011f, -0.98768833263101f,
-0.999999999999999f, -0.987688349397591f, -0.951056534511324f, -0.891006552167012f, -0.809017032174094f,
-0.707106828553679f, -0.587785308654041f, -0.4539905642005f, -0.309017065728638f, -0.156434541788751f,
-8.03846893110719E-08f, 0.156434382998709f, 0.309016912827872f, 0.453990420953934f, 0.58778517858888f,
0.707106714872559f, 0.809016937676222f, 0.891006479179238f, 0.951056484830851f, 0.987688324247716f,
};
private static readonly float[] sinData =
{
0f, 0.15643446239373f, 0.309016989278255f, 0.453990492577218f, 0.587785243621462f,
@@ -18,19 +63,6 @@ namespace StgSharp.Math
-0.70710684750053f, -0.587785330331566f, -0.453990588074927f, -0.309017091212098f, -0.156434568253757f,
};
private static readonly float[] cosData =
{
1f, 0.987688341014302f, 0.951056517951169f, 0.891006527837756f, 0.809017000674805f,
0.707106790659974f, 0.587785265298989f, 0.453990516451646f, 0.309017014761716f, 0.156434488858737f,
2.67948965850537E-08f, -0.156434435928723f, -0.309016963794794f, -0.453990468702791f, -0.587785221943935f,
-0.707106752766267f, -0.809016969175515f, -0.891006503508499f, -0.951056501391011f, -0.98768833263101f,
-0.999999999999999f, -0.987688349397591f, -0.951056534511324f, -0.891006552167012f, -0.809017032174094f,
-0.707106828553679f, -0.587785308654041f, -0.4539905642005f, -0.309017065728638f, -0.156434541788751f,
-8.03846893110719E-08f, 0.156434382998709f, 0.309016912827872f, 0.453990420953934f, 0.58778517858888f,
0.707106714872559f, 0.809016937676222f, 0.891006479179238f, 0.951056484830851f, 0.987688324247716f,
};
public static unsafe float Sin(float x)
@@ -45,8 +77,9 @@ namespace StgSharp.Math
float refer2 = refer * refer;
return sinData[a] * (1 - 0.0123370055f * refer2 + 2.536695709e-5f * refer2 * refer2)
+ cosData[a] * (0.1570796327f * refer - 6.459640975e-4f * refer * refer2);
return (sinData[a] * ((1 - (0.0123370055f * refer2)) + (2.536695709e-5f * refer2 * refer2)))
+ (cosData[a] * ((0.1570796327f * refer) - (6.459640975e-4f * refer * refer2)));
}
}
}
+40 -9
View File
@@ -1,16 +1,40 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Sqrt.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.Runtime.CompilerServices;
namespace StgSharp.Math
{
public static partial class Scaler
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Sqrt(float x)
{
return MathF.Sqrt(x);
/**/
}
public static unsafe float SeedSqrt(float x)
{
@@ -73,8 +97,15 @@ namespace StgSharp.Math
e += f;
float result = *(float*)&e;
result = (result + x / result) / 2;
return (result + x / result) / 2;
result = (result + (x / result)) / 2;
return (result + (x / result)) / 2;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Sqrt(float x)
{
return MathF.Sqrt(x);
/**/
}
}
}
+36 -5
View File
@@ -1,4 +1,34 @@
namespace StgSharp.Math
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Tan.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 partial class Scaler
{
@@ -14,11 +44,12 @@
float refer2 = refer * refer;
float sin = (0.1570796327f * refer - 6.459640975e-4f * refer * refer2);
float cos = (1 - 0.0123370055f * refer2 + 2.536695709e-5f * refer2 * refer2);
float sin = (0.1570796327f * refer) - (6.459640975e-4f * refer * refer2);
float cos = (1 - (0.0123370055f * refer2)) + (2.536695709e-5f * refer2 * refer2);
return (sinData[a] * cos + cosData[a] * sin)
/ (cosData[a] * cos - sinData[a] * sin);
return ((sinData[a] * cos) + (cosData[a] * sin))
/ ((cosData[a] * cos) - (sinData[a] * sin));
}
}
}
+43 -9
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glClampf.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.Runtime.InteropServices;
@@ -14,6 +44,7 @@ namespace StgSharp.Math
[StructLayout(LayoutKind.Sequential)]
public struct GLclampf
{
public float value;
public GLclampf(float a)
@@ -21,15 +52,16 @@ namespace StgSharp.Math
value = a;
}
public static explicit operator float(GLclampf v)
{
return v.value;
}
public static explicit operator GLclampf(float v)
{
return new GLclampf(v);
}
public static explicit operator float(GLclampf v)
{
return v.value;
}
}
/// <summary>
@@ -39,6 +71,7 @@ namespace StgSharp.Math
[StructLayout(LayoutKind.Sequential)]
public struct GLclampd
{
public double value;
public GLclampd(double a)
@@ -46,14 +79,15 @@ namespace StgSharp.Math
value = a;
}
public static explicit operator double(GLclampd v)
{
return v.value;
}
public static explicit operator GLclampd(double v)
{
return new GLclampd(v);
}
public static explicit operator double(GLclampd v)
{
return v.value;
}
}
}
+37 -5
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glHalfNV.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.Runtime.InteropServices;
@@ -11,6 +41,7 @@ namespace StgSharp.Math
[StructLayout(LayoutKind.Explicit, Size = 16)]
public struct GLhalfNV
{
[FieldOffset(0)] public short binary;
public GLhalfNV(short bin)
@@ -18,14 +49,15 @@ namespace StgSharp.Math
binary = bin;
}
public static explicit operator GLhalfNV(short x)
{
return new GLhalfNV(x);
}
public static explicit operator short(GLhalfNV x)
{
return x.binary;
}
public static explicit operator GLhalfNV(short x)
{
return new GLhalfNV(x);
}
}
}