daily update on 2024.03.18 by itload youmu
This commit is contained in:
@@ -1,4 +1,34 @@
|
||||
using System;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="matrix3x4.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the “Software”), to deal in the Software without restriction,
|
||||
// including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
// and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and
|
||||
// this permission notice shall be included in all copies
|
||||
// or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED “AS IS”,
|
||||
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -7,9 +37,10 @@ using System.Runtime.InteropServices;
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 7 * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
|
||||
[StructLayout(LayoutKind.Explicit, Size = (7 * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
|
||||
public struct Matrix3x4
|
||||
{
|
||||
|
||||
[FieldOffset(0)] internal Mat4 mat;
|
||||
[FieldOffset(4 * 4 * sizeof(float))] internal Mat3 transpose;
|
||||
[FieldOffset(7 * 4 * sizeof(float))] internal bool isTransposed;
|
||||
@@ -19,16 +50,9 @@ namespace StgSharp.Math
|
||||
[FieldOffset(2 * 4 * sizeof(float))] public vec3d Colum2;
|
||||
[FieldOffset(3 * 4 * sizeof(float))] public vec3d Colum3;
|
||||
|
||||
public Matrix3x4(
|
||||
float a00, float a01, float a02, float a03,
|
||||
float a10, float a11, float a12, float a13,
|
||||
float a20, float a21, float a22, float a23
|
||||
)
|
||||
internal Matrix3x4(Mat4 mat)
|
||||
{
|
||||
mat.colum0 = new Vector4(a00, a10, a20, 0);
|
||||
mat.colum0 = new Vector4(a01, a11, a21, 0);
|
||||
mat.colum0 = new Vector4(a02, a12, a22, 0);
|
||||
mat.colum0 = new Vector4(a03, a13, a23, 0);
|
||||
this.mat = mat;
|
||||
}
|
||||
|
||||
internal Matrix3x4(
|
||||
@@ -44,48 +68,55 @@ namespace StgSharp.Math
|
||||
mat.colum3 = c3;
|
||||
}
|
||||
|
||||
internal Matrix3x4(Mat4 mat)
|
||||
public Matrix3x4(
|
||||
float a00, float a01, float a02, float a03,
|
||||
float a10, float a11, float a12, float a13,
|
||||
float a20, float a21, float a22, float a23
|
||||
)
|
||||
{
|
||||
this.mat = mat;
|
||||
mat.colum0 = new Vector4(a00, a10, a20, 0);
|
||||
mat.colum0 = new Vector4(a01, a11, a21, 0);
|
||||
mat.colum0 = new Vector4(a02, a12, a22, 0);
|
||||
mat.colum0 = new Vector4(a03, a13, a23, 0);
|
||||
}
|
||||
|
||||
public unsafe float this[int rowNum, int columNum]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rowNum > 2 || rowNum < 0)
|
||||
if ((rowNum > 2) || (rowNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if (columNum > 3 || columNum < 0)
|
||||
if ((columNum > 3) || (columNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed (float* p = &this.transpose.m00)
|
||||
{
|
||||
ulong pbit = (ulong)p
|
||||
+ (ulong)sizeof(Vector4) * (ulong)rowNum
|
||||
+ (ulong)sizeof(float) * (ulong)columNum;
|
||||
ulong pbit = ((ulong)p)
|
||||
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
|
||||
+ (((ulong)sizeof(float)) * ((ulong)columNum));
|
||||
return *(float*)pbit;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (rowNum > 2 || rowNum < 0)
|
||||
if ((rowNum > 2) || (rowNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
if (columNum > 3 || columNum < 0)
|
||||
if ((columNum > 3) || (columNum < 0))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columNum));
|
||||
}
|
||||
InternalTranspose();
|
||||
fixed (float* p = &this.transpose.m00)
|
||||
{
|
||||
ulong pbit = (ulong)p
|
||||
+ (ulong)sizeof(Vector4) * (ulong)rowNum
|
||||
+ (ulong)sizeof(float) * (ulong)columNum;
|
||||
ulong pbit = ((ulong)p)
|
||||
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
|
||||
+ (((ulong)sizeof(float)) * ((ulong)columNum));
|
||||
*(float*)pbit = value;
|
||||
}
|
||||
isTransposed = false;
|
||||
@@ -97,25 +128,17 @@ namespace StgSharp.Math
|
||||
if (!isTransposed)
|
||||
{
|
||||
fixed (Mat4* source = &this.mat)
|
||||
fixed (Mat3* target = &this.transpose)
|
||||
{
|
||||
InternalIO.Transpose4to3_internal(source, target);
|
||||
fixed (Mat3* target = &this.transpose)
|
||||
{
|
||||
InternalIO.Transpose4to3_internal(source, target);
|
||||
}
|
||||
}
|
||||
|
||||
isTransposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x4 operator +(Matrix3x4 left, Matrix3x4 right)
|
||||
{
|
||||
return new Matrix3x4(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2,
|
||||
left.mat.colum3 + right.mat.colum3
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x4 operator -(Matrix3x4 left, Matrix3x4 right)
|
||||
{
|
||||
@@ -138,17 +161,6 @@ namespace StgSharp.Math
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x4 operator /(Matrix3x4 mat, float value)
|
||||
{
|
||||
return new Matrix3x4(
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value,
|
||||
mat.mat.colum3 / value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x2 operator *(Matrix3x4 left, Matrix4x2 right)
|
||||
{
|
||||
@@ -206,6 +218,28 @@ namespace StgSharp.Math
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x4 operator /(Matrix3x4 mat, float value)
|
||||
{
|
||||
return new Matrix3x4(
|
||||
mat.mat.colum0 / value,
|
||||
mat.mat.colum1 / value,
|
||||
mat.mat.colum2 / value,
|
||||
mat.mat.colum3 / value
|
||||
);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Matrix3x4 operator +(Matrix3x4 left, Matrix3x4 right)
|
||||
{
|
||||
return new Matrix3x4(
|
||||
left.mat.colum0 + right.mat.colum0,
|
||||
left.mat.colum1 + right.mat.colum1,
|
||||
left.mat.colum2 + right.mat.colum2,
|
||||
left.mat.colum3 + right.mat.colum3
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user