c-o
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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
|
||||
{
|
||||
|
||||
public enum CoordinatePlain
|
||||
{
|
||||
XY,
|
||||
YZ,
|
||||
XZ,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public interface IVector
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public interface IMat
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix22.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)]
|
||||
public struct Matrix22 : IMat
|
||||
{
|
||||
|
||||
[FieldOffset(2 * 2 * 4 * sizeof(float))]
|
||||
internal bool isTransposed;
|
||||
|
||||
[FieldOffset(0)]
|
||||
internal Mat2 mat;
|
||||
[FieldOffset(2 * 4 * sizeof(float))]
|
||||
internal Mat2 transpose;
|
||||
|
||||
internal Matrix22(
|
||||
Mat2 mat
|
||||
)
|
||||
{
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
internal Matrix22(
|
||||
Vector4 c0,
|
||||
Vector4 c1
|
||||
)
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
}
|
||||
|
||||
public Matrix22(
|
||||
float a00, float a01,
|
||||
float a10, float a11
|
||||
)
|
||||
{
|
||||
mat.colum0 = new Vector4(a00, a10, 0, 0);
|
||||
mat.colum1 = new Vector4(a01, a11, 0, 0);
|
||||
}
|
||||
|
||||
public Matrix22 Transpose
|
||||
{
|
||||
get
|
||||
{
|
||||
InternalTranspose();
|
||||
return new Matrix22(this.transpose);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public float Det()
|
||||
{
|
||||
return (mat.m00 * mat.m11) - (mat.m10 * mat.m01);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void InternalTranspose()
|
||||
{
|
||||
if (!isTransposed)
|
||||
{
|
||||
transpose = mat;
|
||||
float cache = transpose.m10;
|
||||
transpose.m10 = transpose.m01;
|
||||
transpose.m01 = cache;
|
||||
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix22 operator -(Matrix22 left, Matrix22 right)
|
||||
{
|
||||
return new Matrix22(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix22 operator *(Matrix22 mat, float value)
|
||||
{
|
||||
return new Matrix22(
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix22 operator *(Matrix22 left, Matrix22 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix22(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix23 operator *(Matrix22 left, Matrix23 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix23(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix24 operator *(Matrix22 left, Matrix24 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix24(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum3),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum3)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix22 operator /(Matrix22 mat, float value)
|
||||
{
|
||||
return new Matrix22(
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix22 operator +(Matrix22 left, Matrix22 right)
|
||||
{
|
||||
Mat2* refmat = InternalIO.add_mat2(&left.mat, &right.mat);
|
||||
Matrix22 ret = new Matrix22(*refmat);
|
||||
InternalIO.deinit_mat2(refmat);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix23.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)]
|
||||
public struct Matrix23 : IMat
|
||||
{
|
||||
|
||||
[FieldOffset(5 * 4 * sizeof(float))] internal bool isTransposed;
|
||||
[FieldOffset(3 * 4 * sizeof(float))] internal Mat2 transpose;
|
||||
|
||||
[FieldOffset(0)] internal Mat3 mat;
|
||||
|
||||
internal Matrix23(
|
||||
Vector4 c0,
|
||||
Vector4 c1,
|
||||
Vector4 c2
|
||||
)
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
mat.colum2 = c2;
|
||||
}
|
||||
|
||||
public Matrix23(
|
||||
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))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if ((columNum > 2) || (columNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed (float* p = &this.transpose.m00)
|
||||
{
|
||||
ulong pbit = ((ulong)p)
|
||||
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
|
||||
+ (((ulong)sizeof(float)) * ((ulong)columNum));
|
||||
return *(float*)pbit;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if ((rowNum > 1) || (rowNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if ((columNum > 2) || (columNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed (float* p = &this.transpose.m00)
|
||||
{
|
||||
ulong pbit = ((ulong)p)
|
||||
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
|
||||
+ (((ulong)sizeof(float)) * ((ulong)columNum));
|
||||
*(float*)pbit = value;
|
||||
}
|
||||
isTransposed = false;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if (!isTransposed)
|
||||
{
|
||||
fixed (Mat3* source = &this.mat)
|
||||
{
|
||||
fixed (Mat2* target = &this.transpose)
|
||||
{
|
||||
InternalIO.Transpose3to2_internal(source, target);
|
||||
}
|
||||
}
|
||||
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix23 operator -(Matrix23 left, Matrix23 right)
|
||||
{
|
||||
return new Matrix23(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum1 - right.mat.colum1,
|
||||
left.mat.colum2 - right.mat.colum2
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix23 operator *(Matrix23 mat, float value)
|
||||
{
|
||||
return new Matrix23(
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix22 operator *(Matrix23 left, Matrix32 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix22(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix23 operator *(Matrix23 left, Matrix33 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix23(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix24 operator *(Matrix23 left, Matrix34 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix24(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum3),
|
||||
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum3)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix23 operator /(Matrix23 mat, float value)
|
||||
{
|
||||
return new Matrix23(
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix23 operator +(Matrix23 left, Matrix23 right)
|
||||
{
|
||||
return new Matrix23(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix24.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)]
|
||||
public struct Matrix24 : IMat
|
||||
{
|
||||
|
||||
[FieldOffset(6 * 4 * sizeof(float))] internal bool isTransposed;
|
||||
[FieldOffset(4 * 4 * sizeof(float))] internal Mat2 transpose;
|
||||
|
||||
[FieldOffset(0)] internal Mat4 mat;
|
||||
|
||||
[FieldOffset(0)] public vec2d Colum0;
|
||||
[FieldOffset(16)] public vec2d Colum1;
|
||||
[FieldOffset(32)] public vec2d Colum2;
|
||||
[FieldOffset(48)] public vec2d Colum3;
|
||||
|
||||
internal Matrix24(
|
||||
Vector4 c0,
|
||||
Vector4 c1,
|
||||
Vector4 c2,
|
||||
Vector4 c3
|
||||
)
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
mat.colum2 = c2;
|
||||
mat.colum3 = c3;
|
||||
}
|
||||
|
||||
|
||||
public Matrix24(
|
||||
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))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if ((columNum > 3) || (columNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed (float* p = &this.transpose.m00)
|
||||
{
|
||||
ulong pbit = ((ulong)p)
|
||||
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
|
||||
+ (((ulong)sizeof(float)) * ((ulong)columNum));
|
||||
return *(float*)pbit;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if ((rowNum > 1) || (rowNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if ((columNum > 3) || (columNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed (float* p = &this.transpose.m00)
|
||||
{
|
||||
ulong pbit = ((ulong)p)
|
||||
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
|
||||
+ (((ulong)sizeof(float)) * ((ulong)columNum));
|
||||
*(float*)pbit = value;
|
||||
}
|
||||
isTransposed = false;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix24 operator -(Matrix24 left, Matrix24 right)
|
||||
{
|
||||
return new Matrix24(
|
||||
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 Matrix24 operator *(Matrix24 mat, float value)
|
||||
{
|
||||
return new Matrix24(
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value,
|
||||
mat.mat.colum3 * value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix22 operator *(Matrix24 left, Matrix42 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix22(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix23 operator *(Matrix24 left, Matrix43 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix23(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix24 operator *(Matrix24 left, Matrix44 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix24(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum3),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum3)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix24 operator /(Matrix24 mat, float value)
|
||||
{
|
||||
return new Matrix24(
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value,
|
||||
mat.mat.colum3 / value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix24 operator +(Matrix24 left, Matrix24 right)
|
||||
{
|
||||
return new Matrix24(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2,
|
||||
left.mat.colum3 + right.mat.colum3
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix32.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)]
|
||||
public struct Matrix32 : IMat
|
||||
{
|
||||
|
||||
[FieldOffset(5 * 4 * sizeof(float))] internal bool isTransposed;
|
||||
|
||||
[FieldOffset(0)] internal Mat2 mat;
|
||||
[FieldOffset(2 * 4 * sizeof(float))] internal Mat3 transpose;
|
||||
|
||||
[FieldOffset(0)] internal vec3d colum0;
|
||||
[FieldOffset(4 * 4)] internal vec3d colum1;
|
||||
|
||||
internal Matrix32(
|
||||
Vector4 c0,
|
||||
Vector4 c1
|
||||
)
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
}
|
||||
|
||||
|
||||
public unsafe Matrix32(
|
||||
float a00, float a01,
|
||||
float a10, float a11,
|
||||
float a20, float a21
|
||||
)
|
||||
{
|
||||
#if NET5_0_OR_GREATER
|
||||
Unsafe.SkipInit(out colum0);
|
||||
Unsafe.SkipInit(out colum1);
|
||||
Unsafe.SkipInit(out transpose);
|
||||
#endif
|
||||
mat.colum0 = new Vector4(a00, a10, a20, 0);
|
||||
mat.colum1 = new Vector4(a01, a11, a21, 0);
|
||||
}
|
||||
|
||||
public unsafe float this[int rowNum, int columNum]
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((rowNum > 2) || (rowNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if ((columNum > 1) || (columNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed (float* p = &this.transpose.m00)
|
||||
{
|
||||
ulong pbit = ((ulong)p)
|
||||
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
|
||||
+ (((ulong)sizeof(float)) * ((ulong)columNum));
|
||||
return *(float*)pbit;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if ((rowNum > 2) || (rowNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if ((columNum > 1) || (columNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed (float* p = &this.transpose.m00)
|
||||
{
|
||||
ulong pbit = ((ulong)p)
|
||||
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
|
||||
+ (((ulong)sizeof(float)) * ((ulong)columNum));
|
||||
*(float*)pbit = value;
|
||||
}
|
||||
isTransposed = false;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix32 operator -(Matrix32 left, Matrix32 right)
|
||||
{
|
||||
return new Matrix32(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum1 - right.mat.colum1
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix32 operator *(Matrix32 mat, float value)
|
||||
{
|
||||
return new Matrix32(
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix32 operator *(Matrix32 left, Matrix22 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix32(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix33 operator *(Matrix32 left, Matrix23 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix33(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix34 operator *(Matrix32 left, Matrix24 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix34(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum3),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum3),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum3)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix32 operator /(Matrix32 mat, float value)
|
||||
{
|
||||
return new Matrix32(
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix32 operator +(Matrix32 left, Matrix32 right)
|
||||
{
|
||||
return new Matrix32(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix33.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)]
|
||||
public struct Matrix33 : IMat
|
||||
{
|
||||
|
||||
[FieldOffset(6 * 4 * sizeof(float))] internal bool isTransposed;
|
||||
|
||||
[FieldOffset(0)] internal Mat3 mat;
|
||||
[FieldOffset(3 * 4 * sizeof(float))] internal Mat3 transpose;
|
||||
[FieldOffset(0 * 4 * sizeof(float))] public vec3d Colum0;
|
||||
[FieldOffset(1 * 4 * sizeof(float))] public vec3d Colum1;
|
||||
[FieldOffset(2 * 4 * sizeof(float))] public vec3d Colum2;
|
||||
|
||||
internal Matrix33(
|
||||
Vector4 c0,
|
||||
Vector4 c1,
|
||||
Vector4 c2
|
||||
)
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
mat.colum2 = c2;
|
||||
}
|
||||
|
||||
public Matrix33(
|
||||
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))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if ((columNum > 2) || (columNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed (float* p = &this.transpose.m00)
|
||||
{
|
||||
ulong pbit = ((ulong)p)
|
||||
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
|
||||
+ (((ulong)sizeof(float)) * ((ulong)columNum));
|
||||
return *(float*)pbit;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if ((rowNum > 2) || (rowNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if ((columNum > 2) || (columNum < 0))
|
||||
{
|
||||
InternalIO.InternalWriteLog(
|
||||
$"Attempt to write unused space in {GetType().Name} {nameof(mat)}",
|
||||
LogType.Error
|
||||
);
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed (float* p = &this.transpose.m00)
|
||||
{
|
||||
ulong pbit = ((ulong)p)
|
||||
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
|
||||
+ (((ulong)sizeof(float)) * ((ulong)columNum));
|
||||
*(float*)pbit = value;
|
||||
}
|
||||
isTransposed = false;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe float Det()
|
||||
{
|
||||
fixed (Mat3* mat = &this.mat)
|
||||
{
|
||||
return InternalIO.det_mat3(mat);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if (!isTransposed)
|
||||
{
|
||||
fixed (Mat3* source = &this.mat, target = &this.transpose)
|
||||
{
|
||||
InternalIO.Transpose3to3_internal(source, target);
|
||||
}
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix33 operator -(Matrix33 left, Matrix33 right)
|
||||
{
|
||||
return new Matrix33(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum1 - right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix33 operator *(Matrix33 mat, float value)
|
||||
{
|
||||
return new Matrix33(
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static vec3d operator *(Matrix33 left, vec3d right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new vec3d(
|
||||
Vector4.Dot(left.transpose.colum0, right.vec),
|
||||
Vector4.Dot(left.transpose.colum1, right.vec),
|
||||
Vector4.Dot(left.transpose.colum2, right.vec)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix32 operator *(Matrix33 left, Matrix32 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix32(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix33 operator *(Matrix33 left, Matrix33 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix33(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix34 operator *(Matrix33 left, Matrix34 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix34(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum3),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum3),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum3)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix33 operator /(Matrix33 mat, float value)
|
||||
{
|
||||
return new Matrix33(
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix33 operator +(Matrix33 left, Matrix33 right)
|
||||
{
|
||||
return new Matrix33(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix34.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;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = (7 * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
|
||||
public struct Matrix34 : IMat
|
||||
{
|
||||
|
||||
[FieldOffset(7 * 4 * sizeof(float))] internal bool isTransposed;
|
||||
[FieldOffset(4 * 4 * sizeof(float))] internal Mat3 transpose;
|
||||
|
||||
[FieldOffset(0)] internal Mat4 mat;
|
||||
|
||||
[FieldOffset(0 * 4 * sizeof(float))] public vec3d Colum0;
|
||||
[FieldOffset(1 * 4 * sizeof(float))] public vec3d Colum1;
|
||||
[FieldOffset(2 * 4 * sizeof(float))] public vec3d Colum2;
|
||||
[FieldOffset(3 * 4 * sizeof(float))] public vec3d Colum3;
|
||||
|
||||
internal Matrix34(Mat4 mat)
|
||||
{
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
internal Matrix34(
|
||||
Vector4 c0,
|
||||
Vector4 c1,
|
||||
Vector4 c2,
|
||||
Vector4 c3
|
||||
)
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
mat.colum2 = c2;
|
||||
mat.colum3 = c3;
|
||||
}
|
||||
|
||||
public Matrix34(
|
||||
float a00, float a01, float a02, float a03,
|
||||
float a10, float a11, float a12, float a13,
|
||||
float a20, float a21, float a22, float a23
|
||||
)
|
||||
{
|
||||
mat.colum0 = new Vector4(a00, a10, a20, 0);
|
||||
mat.colum0 = new Vector4(a01, a11, a21, 0);
|
||||
mat.colum0 = new Vector4(a02, a12, a22, 0);
|
||||
mat.colum0 = new Vector4(a03, a13, a23, 0);
|
||||
}
|
||||
|
||||
public unsafe float this[int rowNum, int columNum]
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((rowNum > 2) || (rowNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if ((columNum > 3) || (columNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed (float* p = &this.transpose.m00)
|
||||
{
|
||||
ulong pbit = ((ulong)p)
|
||||
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
|
||||
+ (((ulong)sizeof(float)) * ((ulong)columNum));
|
||||
return *(float*)pbit;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if ((rowNum > 2) || (rowNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if ((columNum > 3) || (columNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed (float* p = &this.transpose.m00)
|
||||
{
|
||||
ulong pbit = ((ulong)p)
|
||||
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
|
||||
+ (((ulong)sizeof(float)) * ((ulong)columNum));
|
||||
*(float*)pbit = value;
|
||||
}
|
||||
isTransposed = false;
|
||||
}
|
||||
}
|
||||
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if (!isTransposed)
|
||||
{
|
||||
fixed (Mat4* source = &this.mat)
|
||||
{
|
||||
fixed (Mat3* target = &this.transpose)
|
||||
{
|
||||
InternalIO.Transpose4to3_internal(source, target);
|
||||
}
|
||||
}
|
||||
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix34 operator -(Matrix34 left, Matrix34 right)
|
||||
{
|
||||
return new Matrix34(
|
||||
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 Matrix34 operator *(Matrix34 mat, float value)
|
||||
{
|
||||
return new Matrix34(
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value,
|
||||
mat.mat.colum3 * value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix32 operator *(Matrix34 left, Matrix42 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix32(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix33 operator *(Matrix34 left, Matrix43 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix33(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix34 operator *(Matrix34 left, Matrix44 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix34(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum3),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum3),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum3)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix34 operator /(Matrix34 mat, float value)
|
||||
{
|
||||
return new Matrix34(
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value,
|
||||
mat.mat.colum3 / value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix34 operator +(Matrix34 left, Matrix34 right)
|
||||
{
|
||||
return new Matrix34(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2,
|
||||
left.mat.colum3 + right.mat.colum3
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix42.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 = ((16 + 8) * sizeof(float)) + sizeof(bool), Pack = 16)]
|
||||
public struct Matrix42 : IMat
|
||||
{
|
||||
|
||||
[FieldOffset((16 + 8) * sizeof(float))] internal bool isTransposed;
|
||||
|
||||
[FieldOffset(0)] internal Mat2 mat;
|
||||
[FieldOffset(8 * sizeof(float))] internal Mat4 transpose;
|
||||
|
||||
internal Matrix42(Mat2 mat)
|
||||
{
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
internal Matrix42(
|
||||
Vector4 c0,
|
||||
Vector4 c1
|
||||
)
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
}
|
||||
|
||||
|
||||
public Matrix42(
|
||||
float a00, float a01,
|
||||
float a10, float a11,
|
||||
float a20, float a21,
|
||||
float a30, float a31
|
||||
)
|
||||
{
|
||||
mat.colum0 = new Vector4(a00, a10, a20, a30);
|
||||
mat.colum1 = new Vector4(a01, a11, a21, a31);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public unsafe float this[int rowNum, int columNum]
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((rowNum > 3) || (rowNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if ((columNum > 1) || (columNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed (float* p = &this.transpose.m00)
|
||||
{
|
||||
ulong pbit = ((ulong)p)
|
||||
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
|
||||
+ (((ulong)sizeof(float)) * ((ulong)columNum));
|
||||
return *(float*)pbit;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if ((rowNum > 3) || (rowNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if ((columNum > 1) || (columNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed (float* p = &this.transpose.m00)
|
||||
{
|
||||
ulong pbit = ((ulong)p)
|
||||
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
|
||||
+ (((ulong)sizeof(float)) * ((ulong)columNum));
|
||||
*(float*)pbit = value;
|
||||
}
|
||||
isTransposed = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(
|
||||
mat.colum0.GetHashCode(),
|
||||
mat.colum1.GetHashCode()
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
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 Matrix42 operator -(Matrix42 left, Matrix42 right)
|
||||
{
|
||||
return new Matrix42(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum0 - right.mat.colum0
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix42 operator *(Matrix42 mat, float value)
|
||||
{
|
||||
return new Matrix42(
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix42 operator *(Matrix42 left, Matrix22 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix42(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum1)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix43 operator *(Matrix42 left, Matrix23 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix43(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum2)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix44 operator *(Matrix42 left, Matrix24 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix44(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum2)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix42 operator /(Matrix42 mat, float value)
|
||||
{
|
||||
return new Matrix42(
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix42 operator +(Matrix42 left, Matrix42 right)
|
||||
{
|
||||
return new Matrix42(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum0 + right.mat.colum0
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix43.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;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = (7 * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
|
||||
public struct Matrix43 : IEquatable<Matrix43>, IMat
|
||||
{
|
||||
|
||||
[FieldOffset(7 * 4 * sizeof(float))]
|
||||
internal bool isTransposed;
|
||||
|
||||
[FieldOffset(0)]
|
||||
internal Mat3 mat;
|
||||
|
||||
[FieldOffset(3 * 4 * sizeof(float))]
|
||||
internal Mat4 transpose;
|
||||
|
||||
internal Matrix43(
|
||||
Vector4 c0,
|
||||
Vector4 c1,
|
||||
Vector4 c2
|
||||
)
|
||||
{
|
||||
mat.colum0 = c0;
|
||||
mat.colum1 = c1;
|
||||
mat.colum2 = c2;
|
||||
}
|
||||
|
||||
public Matrix43(
|
||||
float a00, float a01, float a02,
|
||||
float a10, float a11, float a12,
|
||||
float a20, float a21, float a22,
|
||||
float a30, float a31, float a32
|
||||
)
|
||||
{
|
||||
mat.colum0 = new Vector4(a00, a10, a20, a30);
|
||||
mat.colum1 = new Vector4(a01, a11, a21, a31);
|
||||
mat.colum2 = new Vector4(a02, a12, a22, a32);
|
||||
}
|
||||
|
||||
public unsafe float this[int rowNum, int columNum]
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((rowNum > 3) || (rowNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if ((columNum > 2) || (columNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed (float* p = &this.transpose.m00)
|
||||
{
|
||||
ulong pbit = ((ulong)p)
|
||||
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
|
||||
+ (((ulong)sizeof(float)) * ((ulong)columNum));
|
||||
return *(float*)pbit;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if ((rowNum > 3) || (rowNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if ((columNum > 2) || (columNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed (float* p = &this.transpose.m00)
|
||||
{
|
||||
ulong pbit = ((ulong)p)
|
||||
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
|
||||
+ (((ulong)sizeof(float)) * ((ulong)columNum));
|
||||
*(float*)pbit = value;
|
||||
}
|
||||
isTransposed = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return (obj is Matrix43 x) && Equals(x);
|
||||
}
|
||||
|
||||
public bool Equals(Matrix43 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);
|
||||
}
|
||||
}
|
||||
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix43 operator -(Matrix43 left, Matrix43 right)
|
||||
{
|
||||
return new Matrix43(
|
||||
left.mat.colum0 - right.mat.colum0,
|
||||
left.mat.colum1 - right.mat.colum1,
|
||||
left.mat.colum2 - right.mat.colum2
|
||||
);
|
||||
}
|
||||
|
||||
public static bool operator !=(Matrix43 left, Matrix43 right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix43 operator *(Matrix43 mat, float value)
|
||||
{
|
||||
return new Matrix43(
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix42 operator *(Matrix43 left, Matrix32 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix42(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum1)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix43 operator *(Matrix43 left, Matrix33 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix43(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum2)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix44 operator *(Matrix43 left, Matrix34 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix44(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum3),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum3),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum3),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum3)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix43 operator /(Matrix43 mat, float value)
|
||||
{
|
||||
return new Matrix43(
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix43 operator +(Matrix43 left, Matrix43 right)
|
||||
{
|
||||
return new Matrix43(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2
|
||||
);
|
||||
}
|
||||
|
||||
public static bool operator ==(Matrix43 left, Matrix43 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,351 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Matrix44.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.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = (2 * 16 * sizeof(float)) + sizeof(bool), Pack = 16)]
|
||||
public unsafe struct Matrix44 : IEquatable<Matrix44>, IMat
|
||||
{
|
||||
|
||||
[FieldOffset(2 * 64 * sizeof(float))] internal bool isTransposed;
|
||||
|
||||
[FieldOffset(0)] internal Mat4 mat;
|
||||
[FieldOffset(16 * sizeof(float))] internal Mat4 transpose;
|
||||
[FieldOffset(0 * sizeof(float))] internal vec4d colum0;
|
||||
[FieldOffset(4 * sizeof(float))] internal vec4d colum1;
|
||||
[FieldOffset(8 * sizeof(float))] internal vec4d colum2;
|
||||
[FieldOffset(12 * sizeof(float))] internal vec4d colum3;
|
||||
|
||||
internal Matrix44(Mat4 mat)
|
||||
{
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
internal Matrix44(
|
||||
Vector4 vec0,
|
||||
Vector4 vec1,
|
||||
Vector4 vec2,
|
||||
Vector4 vec3
|
||||
)
|
||||
{
|
||||
mat.colum0 = vec0;
|
||||
mat.colum1 = vec1;
|
||||
mat.colum2 = vec2;
|
||||
mat.colum3 = vec3;
|
||||
}
|
||||
|
||||
|
||||
public unsafe Matrix44(
|
||||
float a00, float a01, float a02, float a03,
|
||||
float a10, float a11, float a12, float a13,
|
||||
float a20, float a21, float a22, float a23,
|
||||
float a30, float a31, float a32, float a33
|
||||
)
|
||||
{
|
||||
mat.colum0 = new Vector4(a00, a10, a20, a30);
|
||||
mat.colum1 = new Vector4(a01, a11, a21, a31);
|
||||
mat.colum2 = new Vector4(a02, a12, a22, a32);
|
||||
mat.colum3 = new Vector4(a03, a13, a23, a33);
|
||||
|
||||
}
|
||||
|
||||
public unsafe float this[int rowNum, int columNum]
|
||||
{
|
||||
get
|
||||
{
|
||||
#if DEBUG
|
||||
if ((rowNum > 3) || (rowNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if ((columNum > 3) || (columNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
#endif
|
||||
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 DEBUG
|
||||
if ((rowNum > 3) || (rowNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if ((columNum > 3) || (columNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
#endif
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Matrix44 Transpose
|
||||
{
|
||||
get
|
||||
{
|
||||
InternalTranspose();
|
||||
return new Matrix44(this.transpose);
|
||||
}
|
||||
}
|
||||
|
||||
public static Matrix44 Unit
|
||||
=> new Matrix44(
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1
|
||||
);
|
||||
public static Matrix44 WNegativeUnit
|
||||
=> new Matrix44(
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, -1
|
||||
);
|
||||
|
||||
public static Matrix44 XNegativeUnit
|
||||
=> new Matrix44(
|
||||
-1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1
|
||||
);
|
||||
public static Matrix44 YNegativeUnit
|
||||
=> new Matrix44(
|
||||
1, 0, 0, 0,
|
||||
0, -1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1
|
||||
);
|
||||
|
||||
public static Matrix44 ZNegativeUnit
|
||||
=> new Matrix44(
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, -1, 0,
|
||||
0, 0, 0, 1
|
||||
);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe float Det()
|
||||
{
|
||||
InternalTranspose();
|
||||
fixed (Mat4* _this = &mat, _trans = &transpose)
|
||||
{
|
||||
return InternalIO.det_mat4(_this, _trans);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return (obj is Matrix44 x) && Equals(x);
|
||||
}
|
||||
|
||||
public bool Equals(Matrix44 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)]
|
||||
internal unsafe void InternalTranspose()
|
||||
{
|
||||
if (!isTransposed)
|
||||
{
|
||||
fixed (Mat4* source = &mat, target = &transpose)
|
||||
{
|
||||
InternalIO.Transpose4to4_internal(source, target);
|
||||
}
|
||||
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix44 operator -(Matrix44 left, Matrix44 right)
|
||||
{
|
||||
return new Matrix44(
|
||||
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 !=(Matrix44 left, Matrix44 right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix44 operator *(Matrix44 mat, float value)
|
||||
{
|
||||
return new Matrix44(
|
||||
mat.mat.colum0 * value,
|
||||
mat.mat.colum1 * value,
|
||||
mat.mat.colum2 * value,
|
||||
mat.mat.colum3 * value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix42 operator *(Matrix44 left, Matrix42 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix42(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum1)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix43 operator *(Matrix44 left, Matrix43 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix43(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum2)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix44 operator *(Matrix44 left, Matrix44 right)
|
||||
{
|
||||
left.InternalTranspose();
|
||||
return new Matrix44(
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum0, right.mat.colum3),
|
||||
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum1, right.mat.colum3),
|
||||
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum2, right.mat.colum3),
|
||||
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum1),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum2),
|
||||
Vector4.Dot(left.transpose.colum3, right.mat.colum3)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe Matrix44 operator +(Matrix44 left, Matrix44 right)
|
||||
{
|
||||
return new Matrix44(
|
||||
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 ==(Matrix44 left, Matrix44 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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 Linear
|
||||
{
|
||||
|
||||
public static float Cross(vec2d vec1, vec2d vec2)
|
||||
{
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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 Linear
|
||||
{
|
||||
|
||||
public static float GetAngle(vec2d vec1, vec2d vec2)
|
||||
{
|
||||
return Scaler.ACos(1
|
||||
//vec1.multiple(vec2)
|
||||
/ (vec1.GetLength() * vec2.GetLength())
|
||||
);
|
||||
}
|
||||
|
||||
public static float GetAngle(vec3d vec1, vec3d vec2)
|
||||
{
|
||||
return Scaler.ACos(
|
||||
(vec1 * vec2)
|
||||
/ (vec1.GetLength() * vec2.GetLength())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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 Linear
|
||||
{
|
||||
|
||||
public static float GetLength(this vec3d vec)
|
||||
{
|
||||
return Scaler.Sqrt(vec.Dot(vec));
|
||||
}
|
||||
|
||||
public static float GetLength(this vec2d vec)
|
||||
{
|
||||
return Scaler.Sqrt(vec.Dot(vec));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using StgSharp.Data;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static partial class Linear
|
||||
{
|
||||
public static unsafe void Normalize(ref vec4d source, ref vec4d target)
|
||||
{
|
||||
Vector4 s = source.vec;
|
||||
Vector4 t = target.vec;
|
||||
|
||||
s = Vector4.Normalize(s);
|
||||
|
||||
float dotProduct = Vector4.Dot(s, t);
|
||||
Vector4 projection = Vector4.Multiply(s, t);
|
||||
|
||||
t -= projection;
|
||||
|
||||
source.vec = s;
|
||||
target.vec = t;
|
||||
}
|
||||
|
||||
public static unsafe void Normalize(ref vec3d source, ref vec3d target)
|
||||
{
|
||||
Vector3 s = source.v;
|
||||
Vector3 t = target.v;
|
||||
|
||||
s = Vector3.Normalize(s);
|
||||
Vector3 projection = Vector3.Dot(t, s) / Vector3.Dot(s, s) * s;
|
||||
t -= projection;
|
||||
t = Vector3.Normalize(t);
|
||||
|
||||
source.v = s;
|
||||
target.v = t;
|
||||
}
|
||||
|
||||
public static vec4d Normalize(vec4d vec)
|
||||
{
|
||||
return new vec4d() { vec = Vector4.Normalize(vec.vec) };
|
||||
}
|
||||
public static vec3d Normalize(vec3d vec)
|
||||
{
|
||||
return new vec3d() { vec = Vector4.Normalize(vec.vec) };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Vector.Orthogonalize.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.Data;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
|
||||
internal static partial class InternalIO
|
||||
{
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "normalize",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Normalize(M128* source, M128* target);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static partial class Linear
|
||||
{
|
||||
|
||||
public static vec4d Orthogonalize(vec4d vec)
|
||||
{
|
||||
return new vec4d { vec = Vector4.Normalize(vec.vec) };
|
||||
}
|
||||
public static vec3d Orthogonalize(vec3d vec)
|
||||
{
|
||||
return new vec3d { vec = Vector4.Normalize(vec.vec) };
|
||||
}
|
||||
public static unsafe void Orthogonalize(ref vec4d source, ref vec4d target)
|
||||
{
|
||||
Vector4 s = source.vec;
|
||||
Vector4 t = target.vec;
|
||||
|
||||
s = Vector4.Normalize(s);
|
||||
|
||||
float dotProduct = Vector4.Dot(s, t);
|
||||
Vector4 projection = Vector4.Multiply(s, t);
|
||||
|
||||
t -= projection;
|
||||
|
||||
source.vec = s;
|
||||
target.vec = t;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Orthogonalize two <see cref="vec3d"/>s, let their length be 1
|
||||
/// and perpendicular to each other.
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="target"></param>
|
||||
public static unsafe void Orthogonalize(ref vec3d source, ref vec3d target)
|
||||
{
|
||||
Vector3 s = source.v;
|
||||
Vector3 t = target.v;
|
||||
|
||||
s = Vector3.Normalize(s);
|
||||
Vector3 projection = (Vector3.Dot(t, s) / Vector3.Dot(s, s)) * s;
|
||||
t -= projection;
|
||||
t = Vector3.Normalize(t);
|
||||
|
||||
source.v = s;
|
||||
target.v = t;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static unsafe partial class InternalIO
|
||||
{
|
||||
|
||||
#region add
|
||||
|
||||
[DllImport(InternalIO.SSC_libName, EntryPoint = "add_Mat2",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
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
|
||||
|
||||
[DllImport(InternalIO.SSC_libName, EntryPoint = "sub_mat2",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe Mat2* sub_mat2(Mat2* left, Mat2* right);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region transpose
|
||||
|
||||
|
||||
[DllImport(InternalIO.SSC_libName, EntryPoint = "transpose2to4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe void Transpose2to4_internal(Mat2* source, Mat4* target);
|
||||
|
||||
[DllImport(InternalIO.SSC_libName, EntryPoint = "transpose2to3",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe void Transpose2to3_internal(Mat2* source, Mat3* target);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 12 * sizeof(float), Pack = 16)]
|
||||
internal struct Mat2 : IEquatable<Mat2>
|
||||
{
|
||||
|
||||
[FieldOffset(0 * sizeof(float))] internal float m00;
|
||||
[FieldOffset(4 * sizeof(float))] internal float m01;
|
||||
[FieldOffset(1 * sizeof(float))] internal float m10;
|
||||
[FieldOffset(5 * sizeof(float))] internal float m11;
|
||||
[FieldOffset(2 * sizeof(float))] internal float m20;
|
||||
[FieldOffset(6 * sizeof(float))] internal float m21;
|
||||
[FieldOffset(3 * sizeof(float))] internal float m30;
|
||||
[FieldOffset(7 * sizeof(float))] internal float m31;
|
||||
|
||||
[FieldOffset(0)] internal Vector4 colum0;
|
||||
[FieldOffset(4 * sizeof(float))] internal Vector4 colum1;
|
||||
|
||||
internal Mat2(
|
||||
Vector4 c0,
|
||||
Vector4 c1
|
||||
)
|
||||
{
|
||||
colum0 = c0;
|
||||
colum1 = c1;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return (obj is Mat2 mat) && Equals(mat);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Equals(Mat2 other)
|
||||
{
|
||||
return colum0.Equals(other.colum0) &&
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static unsafe partial class InternalIO
|
||||
{
|
||||
|
||||
#region det
|
||||
|
||||
[DllImport(InternalIO.SSC_libName, EntryPoint = "det_mat3",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern unsafe float det_mat3(Mat3* mat);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region transpose
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "transpose3to4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose3to4_internal(Mat3* source, Mat4* target);
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "transpose3to3",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose3to3_internal(Mat3* source, Mat3* target);
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "transpose3to2",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose3to2_internal(Mat3* source, Mat2* target);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 12 * sizeof(float), Pack = 16)]
|
||||
public struct Mat3 : IEquatable<Mat3>, IMat
|
||||
{
|
||||
|
||||
[FieldOffset(0 * sizeof(float))] internal float m00;
|
||||
|
||||
[FieldOffset(4 * sizeof(float))] internal float m01;
|
||||
|
||||
[FieldOffset(8 * sizeof(float))] internal float m02;
|
||||
[FieldOffset(1 * sizeof(float))] internal float m10;
|
||||
[FieldOffset(5 * sizeof(float))] internal float m11;
|
||||
[FieldOffset(9 * sizeof(float))] internal float m12;
|
||||
[FieldOffset(2 * sizeof(float))] internal float m20;
|
||||
[FieldOffset(6 * sizeof(float))] internal float m21;
|
||||
[FieldOffset(10 * sizeof(float))] internal float m22;
|
||||
[FieldOffset(3 * sizeof(float))] internal float m30;
|
||||
[FieldOffset(7 * sizeof(float))] internal float m31;
|
||||
[FieldOffset(11 * sizeof(float))] internal float m32;
|
||||
|
||||
[FieldOffset(0)] internal Vector4 colum0;
|
||||
[FieldOffset(4 * sizeof(float))] internal Vector4 colum1;
|
||||
[FieldOffset(8 * sizeof(float))] internal Vector4 colum2;
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return (obj is Mat3 mat) && Equals(mat);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Equals(Mat3 other)
|
||||
{
|
||||
return colum0.Equals(other.colum0) &&
|
||||
colum1.Equals(other.colum1) &&
|
||||
colum2.Equals(other.colum2);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Mat3 left, Mat3 right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Mat3 left, Mat3 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
internal static unsafe partial class InternalIO
|
||||
{
|
||||
|
||||
#region deinit_mat4
|
||||
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "deinit_mat4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static extern void deinit_mat4(Mat4* mat);
|
||||
|
||||
#endregion
|
||||
|
||||
#region det
|
||||
|
||||
[DllImport(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(SSC_libName, EntryPoint = "transpose4to4",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose4to4_internal(Mat4* source, Mat4* target);
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "transpose4to3",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose4to3_internal(Mat4* source, Mat3* target);
|
||||
|
||||
[DllImport(SSC_libName, EntryPoint = "transpose4to2",
|
||||
CallingConvention = CallingConvention.Cdecl)]
|
||||
internal static extern unsafe void Transpose4to2_internal(Mat4* source, Mat2* target);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
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;
|
||||
[FieldOffset(48)] internal Vector4 colum3;
|
||||
|
||||
[FieldOffset(0)] public float m00;
|
||||
|
||||
[FieldOffset(16)] public float m01;
|
||||
|
||||
[FieldOffset(32)] public float m02;
|
||||
|
||||
[FieldOffset(48)] public float m03;
|
||||
[FieldOffset(4)] public float m10;
|
||||
[FieldOffset(20)] public float m11;
|
||||
[FieldOffset(36)] public float m12;
|
||||
[FieldOffset(52)] public float m13;
|
||||
[FieldOffset(8)] public float m20;
|
||||
[FieldOffset(24)] public float m21;
|
||||
[FieldOffset(40)] public float m22;
|
||||
[FieldOffset(56)] public float m23;
|
||||
[FieldOffset(12)] public float m30;
|
||||
[FieldOffset(28)] public float m31;
|
||||
[FieldOffset(44)] public float m32;
|
||||
[FieldOffset(60)] public float m33;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal Mat4(
|
||||
Vector4 colum0,
|
||||
Vector4 colum1,
|
||||
Vector4 colum2,
|
||||
Vector4 colum3
|
||||
)
|
||||
{
|
||||
this.colum0 = colum0;
|
||||
this.colum1 = colum1;
|
||||
this.colum2 = colum2;
|
||||
this.colum3 = colum3;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return (obj is Mat4 mat) && Equals(mat);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Equals(Mat4 other)
|
||||
{
|
||||
return colum0.Equals(other.colum0) &&
|
||||
colum1.Equals(other.colum1) &&
|
||||
colum2.Equals(other.colum2) &&
|
||||
colum3.Equals(other.colum3);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Mat4 left, Mat4 right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Mat4 left, Mat4 right)
|
||||
{
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[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;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[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;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
/// <summary>
|
||||
/// A two dimension vector defined by two elements.
|
||||
/// Vec2Ds in StgSharp are default used as colum vector.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
|
||||
public struct vec2d:IVector
|
||||
{
|
||||
|
||||
[FieldOffset(0)] internal unsafe fixed float num[2];
|
||||
|
||||
[FieldOffset(0)]
|
||||
internal Vector2 v;
|
||||
|
||||
[FieldOffset(0)]
|
||||
internal Vector4 vec;
|
||||
|
||||
[FieldOffset(0)]
|
||||
public float X;
|
||||
[FieldOffset(4)]
|
||||
public float Y;
|
||||
|
||||
internal vec2d(Vector2 vec)
|
||||
{
|
||||
v = vec;
|
||||
}
|
||||
internal vec2d(Vector4 vec)
|
||||
{
|
||||
this.vec = vec;
|
||||
}
|
||||
|
||||
public vec2d(float x, float y)
|
||||
{
|
||||
v = new Vector2(x, y);
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public float Cross(vec2d right)
|
||||
{
|
||||
return (X * right.Y) - (Y * right.X);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public float Dot(vec2d vec)
|
||||
{
|
||||
return Vector2.Dot(v, vec.v);
|
||||
}
|
||||
|
||||
[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 == right);
|
||||
}
|
||||
|
||||
public static vec2d operator *(vec2d vec, float value)
|
||||
{
|
||||
return new vec2d(vec.v * value);
|
||||
}
|
||||
|
||||
public static vec2d operator /(vec2d vec, float value)
|
||||
{
|
||||
return new vec2d(vec.v / value);
|
||||
}
|
||||
public static vec2d operator *(float value, vec2d vec)
|
||||
{
|
||||
return new vec2d(vec.v * value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static vec2d operator +(vec2d left, vec2d right)
|
||||
{
|
||||
return new vec2d(left.v + right.v);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(vec2d left, vec2d right)
|
||||
{
|
||||
return left.v == right.v;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator vec2d((float, float) tuple)
|
||||
{
|
||||
return new vec2d(tuple.Item1, tuple.Item2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Vec2d
|
||||
{
|
||||
|
||||
public static vec2d Unit => new vec2d(1, 1);
|
||||
|
||||
public static vec2d Zero => new vec2d(0, 0);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.Data;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.AccessControl;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
|
||||
public struct vec3d : IEquatable<vec3d>, IVector
|
||||
{
|
||||
|
||||
[FieldOffset(0)] internal unsafe fixed float num[3];
|
||||
[FieldOffset(0)]
|
||||
internal M128 reg;
|
||||
|
||||
[FieldOffset(0)]
|
||||
internal Vector3 v;
|
||||
|
||||
[FieldOffset(0)]
|
||||
internal Vector4 vec;
|
||||
|
||||
[FieldOffset(0)] public float X;
|
||||
[FieldOffset(4)] public float Y;
|
||||
[FieldOffset(8)] public float Z;
|
||||
|
||||
internal vec3d(Vector4 vector)
|
||||
{
|
||||
vec = vector;
|
||||
}
|
||||
|
||||
internal vec3d(Vector3 vector)
|
||||
{
|
||||
v = vector;
|
||||
}
|
||||
|
||||
public vec3d(vec2d xy, float z)
|
||||
{
|
||||
vec = xy.vec;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
public vec3d(
|
||||
float x, float y, float z)
|
||||
{
|
||||
#if NET5_0_OR_GREATER
|
||||
Unsafe.SkipInit(out vec);
|
||||
#endif
|
||||
v = new Vector3(x, y, z);
|
||||
}
|
||||
|
||||
public vec3d XYZ
|
||||
{
|
||||
get { return new vec3d(v); }
|
||||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public float Dot(vec3d right)
|
||||
{
|
||||
return Vector3.Dot(v, right.v);
|
||||
}
|
||||
|
||||
public bool Equals(vec3d other)
|
||||
{
|
||||
return this.vec == other.vec;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is vec3d)
|
||||
{
|
||||
return this == (vec3d)obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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 vec)
|
||||
{
|
||||
return new vec3d(-vec.vec);
|
||||
}
|
||||
|
||||
[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;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe implicit operator vec3d((float, float, float) tuple)
|
||||
{
|
||||
vec3d v = *(vec3d*)&tuple;
|
||||
v.vec.W = 0.0f;
|
||||
return v;
|
||||
}
|
||||
|
||||
public unsafe vec2d XY
|
||||
{
|
||||
get => new vec2d(this.vec);
|
||||
set
|
||||
{
|
||||
fixed (Vector3* vptr = &v)
|
||||
{
|
||||
*(Vector2*)vptr = value.v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Vec3d
|
||||
{
|
||||
|
||||
public static vec3d One => new vec3d(1, 1, 1);
|
||||
public static vec3d UnitX => new vec3d(1, 0, 0);
|
||||
public static vec3d UnitY => new vec3d(0, 1, 0);
|
||||
|
||||
public static vec3d UnitZ => new vec3d(0, 0, 1);
|
||||
public static vec3d Zero => new vec3d(0, 0, 0);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static vec3d Cross(vec3d left, vec3d right)
|
||||
{
|
||||
return Linear.Cross(left, right);
|
||||
}
|
||||
|
||||
public static bool IsParallel(vec3d left, vec3d right)
|
||||
{
|
||||
return Cross(left, right) == Zero;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// 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.Data;
|
||||
using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Data.Common;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public static class Vec4d
|
||||
{
|
||||
|
||||
public static vec4d One
|
||||
{
|
||||
get => new vec4d(Vector4.One);
|
||||
}
|
||||
public static vec4d Zero
|
||||
{
|
||||
get => new vec4d(Vector4.Zero);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
|
||||
public struct vec4d : IEquatable<vec4d>, IVector
|
||||
{
|
||||
|
||||
[FieldOffset(0)] internal unsafe fixed float num[4];
|
||||
|
||||
[FieldOffset(0)] internal M128 reg;
|
||||
|
||||
[FieldOffset(0)] internal Vector4 vec;
|
||||
[FieldOffset(12)] public float W;
|
||||
|
||||
[FieldOffset(0)] public float X;
|
||||
[FieldOffset(4)] public float Y;
|
||||
[FieldOffset(8)] public float Z;
|
||||
|
||||
internal vec4d(Vector4 v)
|
||||
{
|
||||
vec = v;
|
||||
}
|
||||
|
||||
public vec4d(vec3d v, float w)
|
||||
{
|
||||
vec = v.vec;
|
||||
W = w;
|
||||
}
|
||||
|
||||
public vec4d(float x, float y, float z, float w)
|
||||
{
|
||||
vec = new Vector4(x, y, z, w);
|
||||
}
|
||||
|
||||
public unsafe vec3d XYZ
|
||||
{
|
||||
get => new vec3d(vec);
|
||||
set
|
||||
{
|
||||
float w = W;
|
||||
vec = value.vec;
|
||||
W = w;
|
||||
}
|
||||
}
|
||||
public unsafe vec2d XY
|
||||
{
|
||||
get => new vec2d(vec);
|
||||
set
|
||||
{
|
||||
X = value.X;
|
||||
Y = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is vec4d v) ? (v == this) : false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return vec.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return vec.ToString();
|
||||
}
|
||||
|
||||
public static bool operator !=(vec4d left, vec4d right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static vec4d operator *(Matrix44 mat, vec4d vec)
|
||||
{
|
||||
mat.InternalTranspose();
|
||||
return new vec4d(
|
||||
Vector4.Dot(mat.transpose.colum0, vec.vec),
|
||||
Vector4.Dot(mat.transpose.colum1, vec.vec),
|
||||
Vector4.Dot(mat.transpose.colum2, vec.vec),
|
||||
Vector4.Dot(mat.transpose.colum3, vec.vec)
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static vec4d operator +(vec4d left, vec4d right)
|
||||
{
|
||||
return new vec4d(left.vec + right.vec);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static vec4d operator -(vec4d left, vec4d right)
|
||||
{
|
||||
return new vec4d(left.vec - right.vec);
|
||||
}
|
||||
|
||||
public static bool operator ==(vec4d left, vec4d right)
|
||||
{
|
||||
return left.vec == right.vec;
|
||||
}
|
||||
|
||||
public static implicit operator M128(vec4d vec)
|
||||
{
|
||||
return vec.reg;
|
||||
}
|
||||
|
||||
bool IEquatable<vec4d>.Equals(vec4d other)
|
||||
{
|
||||
return vec == other.vec;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static vec4d Subtract(vec4d left, vec4d right)
|
||||
{
|
||||
return left - right;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static vec4d Add(vec4d left, vec4d right)
|
||||
{
|
||||
return left + right;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user