daily update on 20230228 by nitload youmu
This commit is contained in:
@@ -1,29 +1,28 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
public struct Array3x3
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct Array3x3:IEquatable<Array3x3>
|
||||
{
|
||||
public Vec3D row0;
|
||||
[FieldOffset(0)]
|
||||
public Vec3D row1;
|
||||
[FieldOffset(12)]
|
||||
public Vec3D row2;
|
||||
|
||||
public Vec3D colum0;
|
||||
public Vec3D colum1;
|
||||
public Vec3D colum2;
|
||||
[FieldOffset(24)]
|
||||
public Vec3D row3;
|
||||
|
||||
public Array3x3(Vec3D r0,Vec3D r1,Vec3D r2)
|
||||
{
|
||||
row0 = r0;
|
||||
row1 = r1;
|
||||
row2 = r2;
|
||||
|
||||
colum0 = new Vec3D(r0.X, r1.X, r2.X);
|
||||
colum1 = new Vec3D(r0.Y, r1.Y, r2.Y);
|
||||
colum2 = new Vec3D(r0.Z, r1.Z, r2.Z);
|
||||
row1 = r0;
|
||||
row2 = r1;
|
||||
row3 = r2;
|
||||
}
|
||||
|
||||
public Array3x3(
|
||||
@@ -32,48 +31,132 @@ namespace StgSharp.Math
|
||||
float a31,float a32,float a33
|
||||
)
|
||||
{
|
||||
row0 = new Vec3D(a11, a12, a13);
|
||||
row1 = new Vec3D(a21, a22, a23);
|
||||
row2 = new Vec3D(a31, a32, a33);
|
||||
row1 = new Vec3D(a11, a12, a13);
|
||||
row2 = new Vec3D(a21, a22, a23);
|
||||
row3 = new Vec3D(a31, a32, a33);
|
||||
}
|
||||
|
||||
colum0 = new Vec3D(a11,a21,a31);
|
||||
colum1 = new Vec3D(a12,a22,a32);
|
||||
colum2 = new Vec3D(a13,a23,a33);
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(row1,row2,row3);
|
||||
}
|
||||
|
||||
bool IEquatable<Array3x3>.Equals(Array3x3 other)
|
||||
{
|
||||
if (this.GetHashCode()!=other.GetHashCode())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return
|
||||
this.row1 == other.row1
|
||||
&& this.row2 == other.row2
|
||||
&& this.row3 == other.row3;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj.GetType() != typeof(Vec3D))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Equals((Array3x3)obj);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{row1}\n{row2}\n{row3}";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static bool operator ==(Array3x3 array1, Array3x3 array2)
|
||||
{
|
||||
return array1.Equals(array2);
|
||||
}
|
||||
|
||||
public static bool operator !=(Array3x3 array1, Array3x3 array2)
|
||||
{
|
||||
return !array1.Equals(array2);
|
||||
}
|
||||
|
||||
public static Array3x3 operator +(Array3x3 array1, Array3x3 array2)
|
||||
{
|
||||
return new Array3x3(
|
||||
array1.row0.X + array2.row0.X,
|
||||
array1.row0.Y + array2.row0.Y,
|
||||
array1.row0.Z + array2.row0.Z,
|
||||
|
||||
array1.row1.X + array2.row1.X,
|
||||
array1.row1.Y + array2.row1.Y,
|
||||
array1.row1.Z + array2.row1.Z,
|
||||
|
||||
array1.row2.X + array2.row2.X,
|
||||
array1.row2.Y + array2.row2.Y,
|
||||
array1.row2.Z + array2.row2.Z
|
||||
array1.row2.Z + array2.row2.Z,
|
||||
|
||||
array1.row3.X + array2.row3.X,
|
||||
array1.row3.Y + array2.row3.Y,
|
||||
array1.row3.Z + array2.row3.Z
|
||||
);
|
||||
}
|
||||
|
||||
public static Array3x3 operator -(Array3x3 array1, Array3x3 array2)
|
||||
{
|
||||
return new Array3x3(
|
||||
array1.row0.X - array2.row0.X,
|
||||
array1.row0.Y - array2.row0.Y,
|
||||
array1.row0.Z - array2.row0.Z,
|
||||
|
||||
array1.row1.X - array2.row1.X,
|
||||
array1.row1.Y - array2.row1.Y,
|
||||
array1.row1.Z - array2.row1.Z,
|
||||
|
||||
array1.row2.X - array2.row2.X,
|
||||
array1.row2.Y - array2.row2.Y,
|
||||
array1.row2.Z - array2.row2.Z
|
||||
array1.row2.Z - array2.row2.Z,
|
||||
|
||||
array1.row3.X - array2.row3.X,
|
||||
array1.row3.Y - array2.row3.Y,
|
||||
array1.row3.Z - array2.row3.Z
|
||||
);
|
||||
}
|
||||
|
||||
public static unsafe Array3x3 operator *(Array3x3 array1,Array3x3 array2)
|
||||
{
|
||||
float* p1 = &array1.row2.X;
|
||||
float* p2 = &array2.row2.X;
|
||||
|
||||
return new Array3x3(
|
||||
*(p1 + 0) * *(p2 + 0) + *(p1 + 1) * *(p2 + 3) + *(p1 + 2) * *(p2 + 6),
|
||||
*(p1 + 0) * *(p2 + 1) + *(p1 + 1) * *(p2 + 4) + *(p1 + 2) * *(p2 + 7),
|
||||
*(p1 + 0) * *(p2 + 2) + *(p1 + 1) * *(p2 + 5) + *(p1 + 2) * *(p2 + 8),
|
||||
*(p1 + 3) * *(p2 + 0) + *(p1 + 4) * *(p2 + 3) + *(p1 + 5) * *(p2 + 6),
|
||||
*(p1 + 3) * *(p2 + 1) + *(p1 + 4) * *(p2 + 4) + *(p1 + 5) * *(p2 + 7),
|
||||
*(p1 + 3) * *(p2 + 2) + *(p1 + 4) * *(p2 + 5) + *(p1 + 5) * *(p2 + 8),
|
||||
*(p1 + 6) * *(p2 + 0) + *(p1 + 7) * *(p2 + 3) + *(p1 + 2) * *(p2 + 6),
|
||||
*(p1 + 6) * *(p2 + 1) + *(p1 + 7) * *(p2 + 4) + *(p1 + 2) * *(p2 + 7),
|
||||
*(p1 + 6) * *(p2 + 2) + *(p1 + 7) * *(p2 + 5) + *(p1 + 2) * *(p2 + 8)
|
||||
);
|
||||
}
|
||||
|
||||
public static Array3x3 operator *(Array3x3 array, float x)
|
||||
{
|
||||
return new Array3x3(
|
||||
array.row1 * x,
|
||||
array.row2 * x,
|
||||
array.row3 * x
|
||||
);
|
||||
}
|
||||
|
||||
public static Array3x3 operator /(Array3x3 array, float x)
|
||||
{
|
||||
return new Array3x3(
|
||||
array.row1/x,
|
||||
array.row2/x,
|
||||
array.row3/x
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user