daily update on 20230301 by nitload youmu, file struct cahnged and more vec func added
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Math
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct Array2x3:IEquatable<Array2x3>
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public Vec3D row1;
|
||||
[FieldOffset(12)]
|
||||
public Vec3D row2;
|
||||
|
||||
public Array2x3(Vec3D r1, Vec3D r2)
|
||||
{
|
||||
row1 = r1;
|
||||
row2 = r2;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (obj.GetType() != typeof(Array2x3))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Equals((Vec3D)obj);
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(row1, row2);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{row1}\n{row2}";
|
||||
}
|
||||
|
||||
bool IEquatable<Array2x3>.Equals(Array2x3 other)
|
||||
{
|
||||
if (this.GetHashCode() != other.GetHashCode())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return
|
||||
this.row1 == other.row1
|
||||
&& this.row2 == other.row2;
|
||||
}
|
||||
}
|
||||
|
||||
public static Array2x3 operator +(Array2x3 array1, Array2x3 array2)
|
||||
{
|
||||
return new Array2x3(
|
||||
array1.row1 + array2.row1,
|
||||
array1.row2 + array2.row2
|
||||
);
|
||||
}
|
||||
|
||||
public static Array2x3 operator -(Array2x3 array1, Array2x3 array2)
|
||||
{
|
||||
return new Array2x3(
|
||||
array1.row1 - array2.row1,
|
||||
array1.row2 - array2.row2
|
||||
);
|
||||
}
|
||||
|
||||
public static Array2x3 operator *(Array2x3 array, float x)
|
||||
{
|
||||
return new Array2x3(
|
||||
array.row1 * x,
|
||||
array.row2 * x
|
||||
) ;
|
||||
}
|
||||
|
||||
public static Array2x3 operator /(Array2x3 array, float x)
|
||||
{
|
||||
return new Array2x3(
|
||||
array.row1 / x,
|
||||
array.row2 / x
|
||||
);
|
||||
}
|
||||
|
||||
public static unsafe Array2x2 operator *(Array2x3 array1, Array3x2 array2)
|
||||
{
|
||||
float* p1 = &array1.row1.X;
|
||||
float* p2 = &array2.row2.X;
|
||||
|
||||
return new Array2x2(
|
||||
*(p1 + 0) * *(p2 + 0) + *(p1 + 1) * *(p2 + 2) + *(p1 + 2) * *(p2 + 4),
|
||||
*(p1 + 0) * *(p2 + 1) + *(p1 + 1) * *(p2 + 3) + *(p1 + 2) * *(p2 + 5),
|
||||
*(p1 + 3) * *(p2 + 0) + *(p1 + 4) * *(p2 + 2) + *(p1 + 5) * *(p2 + 4),
|
||||
*(p1 + 3) * *(p2 + 1) + *(p1 + 4) * *(p2 + 3) + *(p1 + 5) * *(p2 + 5)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user