88 lines
2.4 KiB
C#
88 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
|
|
namespace StgSharp.Math
|
|
{
|
|
[StructLayout(LayoutKind.Explicit)]
|
|
public struct Matrix3x2:IEquatable<Matrix3x2>
|
|
{
|
|
[FieldOffset(0)]
|
|
public Vec2D row1;
|
|
[FieldOffset(8)]
|
|
public Vec2D row2;
|
|
[FieldOffset(16)]
|
|
public Vec2D row3;
|
|
|
|
public Matrix3x2(Vec2D r1,Vec2D r2,Vec2D r3)
|
|
{
|
|
row1= r1;
|
|
row2= r2;
|
|
row3= r3;
|
|
}
|
|
bool IEquatable<Matrix3x2>.Equals(Matrix3x2 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(Matrix3x2))
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
return this.Equals((Matrix3x2)obj);
|
|
}
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return HashCode.Combine(row1, row2, row3);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{row1}\n{row2}\n{row3}";
|
|
}
|
|
|
|
public static unsafe Matrix3x3 operator *(Matrix3x2 array1, Matrix3x2 array2)
|
|
{
|
|
float* p1 = &array1.row1.X;
|
|
float* p2 = &array2.row2.X;
|
|
|
|
Matrix2x2 a11 = new Matrix2x2();
|
|
|
|
return new Matrix3x3(
|
|
*(p1 + 0) * *(p2 + 0) + *(p1 + 1) * *(p2 + 3),
|
|
*(p1 + 0) * *(p2 + 1) + *(p1 + 1) * *(p2 + 4),
|
|
*(p1 + 0) * *(p2 + 2) + *(p1 + 1) * *(p2 + 5),
|
|
*(p1 + 2) * *(p2 + 0) + *(p1 + 3) * *(p2 + 3),
|
|
*(p1 + 2) * *(p2 + 1) + *(p1 + 3) * *(p2 + 4),
|
|
*(p1 + 2) * *(p2 + 2) + *(p1 + 3) * *(p2 + 5),
|
|
*(p1 + 4) * *(p2 + 0) + *(p1 + 5) * *(p2 + 3),
|
|
*(p1 + 4) * *(p2 + 1) + *(p1 + 5) * *(p2 + 4),
|
|
*(p1 + 4) * *(p2 + 2) + *(p1 + 5) * *(p2 + 5)
|
|
);
|
|
}
|
|
|
|
}
|
|
}
|