daily update on 20230724 by nitload youmu, bigM128map added

This commit is contained in:
Nitload
2023-07-24 22:50:19 +08:00
parent 80cdd610ce
commit e11c88b051
135 changed files with 1733 additions and 9965 deletions
@@ -4,8 +4,8 @@
{
public static float GetAngle(vec2d vec1, vec2d vec2)
{
return Calc.ACos(
vec1.multiple(vec2)
return Calc.ACos(1
//vec1.multiple(vec2)
/ (vec1.GetLength() * vec2.GetLength())
);
}
@@ -2,6 +2,15 @@
{
public static unsafe partial class VectorCalc
{
public static unsafe Matrix4x4 Multiple(
Matrix4x4 matrix1, Matrix4x4 matrix2
)
{
return default;
}
/*
private static float getMatrixMember(float* p1, float* p2)
{
float result = 0;
@@ -1029,7 +1038,7 @@
new vec4d(u6.row2.X, u6.row2.Y, u7.row2.X, u7.row2.Y)
);
}
/**/
}
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Math
{
public static unsafe partial class VectorCalc
{
}
}
@@ -7,16 +7,6 @@
return new vec3d(vec.X, vec.Y, 0.0f);
}
public static vec4d To4D(this vec2d Vec)
{
return new vec4d(Vec.X, Vec.Y, 0, 0);
}
public static vec4d To4D(this vec3d vec)
{
return new vec4d(vec.X, vec.Y, vec.Z, 0);
}
public static vec2d To2D(vec3d vec, CordinatePlain plain)
{
switch (plain)
@@ -3,101 +3,4 @@ using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct matrix2x4 : IEquatable<matrix2x4>
{
[FieldOffset(0)]
public vec4d row1;
[FieldOffset(16)]
public vec4d row2;
public matrix2x4(vec4d r1, vec4d r2)
{
row1 = r1;
row2 = r2;
}
public matrix2x4(
float a11, float a12, float a13, float a14,
float a21, float a22, float a23, float a24
)
{
row1 = new vec4d(a11, a12, a13, a14);
row2 = new vec4d(a21, a22, a23, a24);
}
public bool Equals(matrix2x4 other)
{
if (this.GetHashCode() != other.GetHashCode())
{
return false;
}
else
{
return this.row1 == other.row1
&& this.row2 == other.row2;
}
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
else if (obj.GetType() != typeof(matrix2x4))
{
return false;
}
else
{
return this.Equals((matrix2x4)obj);
}
}
public override int GetHashCode()
{
return HashCode.Combine(this.row1, this.row2);
}
public override string ToString()
{
return $"{this.row1}\n{this.row2}";
}
public static matrix2x4 operator +(matrix2x4 matrix1, matrix2x4 matrix2)
{
return new matrix2x4(
matrix1.row1 + matrix2.row1,
matrix1.row2 + matrix2.row2
);
}
public static matrix2x4 operator -(matrix2x4 matrix1, matrix2x4 matrix2)
{
return new matrix2x4(
matrix1.row1 - matrix2.row1,
matrix1.row2 - matrix2.row2
);
}
public static matrix2x4 operator *(matrix2x4 array, float x)
{
return new matrix2x4(
array.row1 * x,
array.row2 * x
);
}
public static matrix2x4 operator /(matrix2x4 array, float x)
{
return new matrix2x4(
array.row1 / x,
array.row2 / x
);
}
}
}
+2 -71
View File
@@ -3,77 +3,8 @@ using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct matrix3x4 : IEquatable<matrix3x4>
public class Matrix3x4
{
[FieldOffset(0)]
public vec4d row1;
[FieldOffset(16)]
public vec4d row2;
[FieldOffset(32)]
public vec4d row3;
public matrix3x4(
vec4d r1, vec4d r2, vec4d r3
)
{
this.row1 = r1;
this.row2 = r2;
this.row3 = r3;
}
public matrix3x4(
float a11, float a12, float a13, float a14,
float a21, float a22, float a23, float a24,
float a31, float a32, float a33, float a34
)
{
row1 = new vec4d(a11, a12, a13, a14);
row2 = new vec4d(a21, a22, a23, a24);
row3 = new vec4d(a31, a32, a33, a34);
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
else if (obj.GetType() != typeof(matrix3x4))
{
return false;
}
else
{
return this.Equals((matrix3x4)obj);
}
}
bool IEquatable<matrix3x4>.Equals(matrix3x4 other)
{
if (this.GetHashCode() != other.GetHashCode())
{
return false;
}
else
{
return this.row1 == other.row1
&& this.row2 == other.row2
&& this.row3 == other.row3;
}
}
public override int GetHashCode()
{
return HashCode.Combine(this.row1, this.row2, this.row3);
}
public override string ToString()
{
return $"{this.row1}\n{this.row2}\n{this.row3}";
}
}
}
+154 -94
View File
@@ -1,105 +1,165 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct matrix4x4 : IEquatable<matrix4x4>
public enum TransposeMode
{
[FieldOffset(0)]
public vec4d row1;
[FieldOffset(16)]
public vec4d row2;
[FieldOffset(32)]
public vec4d row3;
[FieldOffset(48)]
public vec4d row4;
public matrix4x4(vec4d r1, vec4d r2, vec4d r3, vec4d r4)
{
row1 = r1;
row2 = r2;
row3 = r3;
row4 = r4;
}
public matrix4x4(
float a11, float a12, float a13, float a14,
float a21, float a22, float a23, float a24,
float a31, float a32, float a33, float a34,
float a41, float a42, float a43, float a44
)
{
row1 = new vec4d(a11, a12, a13, a14);
row2 = new vec4d(a21, a22, a23, a24);
row3 = new vec4d(a31, a32, a33, a34);
row4 = new vec4d(a41, a42, a43, a44);
}
public override bool Equals(object obj)
{
return base.Equals(obj);
}
bool IEquatable<matrix4x4>.Equals(matrix4x4 other)
{
if (this.GetHashCode() != other.GetHashCode())
{
return false;
}
else
{
return this.row1 == other.row1
&& this.row2 == other.row2
&& this.row3 == other.row3
&& this.row4 == other.row4;
}
}
public override int GetHashCode()
{
return HashCode.Combine(row1, row2, row3, row4);
}
public override string ToString()
{
return $"{this.row1}\n{this.row2}\n{this.row3}\n{this.row4}";
}
public static matrix4x4 operator +(matrix4x4 matrix1, matrix4x4 matrix2)
{
return new matrix4x4(
matrix1.row1 + matrix2.row1,
matrix1.row2 + matrix2.row2,
matrix1.row3 + matrix2.row3,
matrix1.row4 + matrix2.row4
);
}
public static matrix4x4 operator -(matrix4x4 matrix1, matrix4x4 matrix2)
{
return new matrix4x4(
matrix1.row1 - matrix2.row1,
matrix1.row2 - matrix2.row2,
matrix1.row3 - matrix2.row3,
matrix1.row4 - matrix2.row4
);
}
public static matrix4x4 operator *(matrix4x4 array, float x)
{
return new matrix4x4(
array.row1 * x,
array.row2 * x,
array.row3 * x,
array.row4 * x
);
}
New,
Copy
}
public class Matrix4x4
{
internal long _row0Ptr;
internal long _row1Ptr;
internal long _row2Ptr;
internal long _row3Ptr;
internal M128 _row0;
internal M128 _row1;
internal M128 _row2;
internal M128 _row3;
private bool isTransposed=false;
private Matrix4x4 _transpose;
internal Matrix4x4()
{
_transpose = new Matrix4x4();
_transpose._transpose = this;
_transpose.isTransposed = true;
}
internal Matrix4x4(M128 row0, M128 row1, M128 row2, M128 row3)
{
this._row0 = row0;
this._row1 = row1;
this._row2 = row2;
this._row3 = row3;
}
public Matrix4x4(
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
)
{
_transpose = new Matrix4x4();
_transpose._transpose = this;
this._row0 = new M128(a00, a01, a02, a03);
this._row1 = new M128(a10, a11, a12, a13);
this._row2 = new M128(a20, a21, a22, a23);
this._row3 = new M128(a30, a31, a32, a33);
}
internal void internalTranspose()
{
if (!isTransposed)
{
_transpose._row0.single_0 = _row0.single_0;
_transpose._row0.single_1 = _row1.single_0;
_transpose._row0.single_2 = _row2.single_0;
_transpose._row0.single_3 = _row3.single_0;
_transpose._row1.single_0 = _row0.single_1;
_transpose._row1.single_1 = _row1.single_1;
_transpose._row1.single_2 = _row2.single_1;
_transpose._row1.single_3 = _row3.single_1;
_transpose._row2.single_0 = _row0.single_2;
_transpose._row2.single_1 = _row1.single_2;
_transpose._row2.single_2 = _row2.single_2;
_transpose._row2.single_3 = _row3.single_2;
_transpose._row3.single_0 = _row0.single_3;
_transpose._row3.single_1 = _row1.single_3;
_transpose._row3.single_2 = _row2.single_3;
_transpose._row3.single_3 = _row3.single_3;
isTransposed = true;
}
}
public unsafe Matrix4x4 Transpose(TransposeMode transposeMode)
{
this.internalTranspose();
switch (transposeMode)
{
case TransposeMode.New:
return new Matrix4x4(
_transpose._row0,
_transpose._row1,
_transpose._row2,
_transpose._row3
);
break;
case TransposeMode.Copy:
return _transpose;
break;
default:
throw new Exception();
break;
}
}
public static Matrix4x4 operator +(Matrix4x4 matrix1, Matrix4x4 matrix2)
{
return new Matrix4x4(
internalIO.VecAddVec(matrix1._row0, matrix2._row0),
internalIO.VecAddVec(matrix1._row1, matrix2._row1),
internalIO.VecAddVec(matrix1._row2, matrix2._row2),
internalIO.VecAddVec(matrix1._row3, matrix2._row3)
) ;
}
public static Matrix4x4 operator *(Matrix4x4 matrix, float value)
{
M128 newRow0 = new M128(
matrix._row0.single_0 * value,
matrix._row0.single_1 * value,
matrix._row0.single_2 * value,
matrix._row0.single_3 * value
);
M128 newRow1 = new M128(
matrix._row1.single_0 * value,
matrix._row1.single_1 * value,
matrix._row1.single_2 * value,
matrix._row1.single_3 * value
);
M128 newRow2 = new M128(
matrix._row2.single_0 * value,
matrix._row2.single_1 * value,
matrix._row2.single_2 * value,
matrix._row2.single_3 * value
);
M128 newRow3 = new M128(
matrix._row3.single_0 * value,
matrix._row3.single_1 * value,
matrix._row3.single_2 * value,
matrix._row3.single_3 * value
);
return new Matrix4x4(
newRow0, newRow1, newRow2, newRow3
);
}
}
}
+35 -121
View File
@@ -1,154 +1,68 @@
using System;
using StgSharp.Control;
using StgSharp.Math;
using System;
using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit)]
public struct vec4d : IEquatable<vec4d>
public class Vec4d
{
[FieldOffset(0)]
public float X;
[FieldOffset(4)]
public float Y;
[FieldOffset(8)]
public float Z;
[FieldOffset(12)]
public float W;
internal readonly int mapID;
internal readonly long m128Ptr;
private M128 _value;
[FieldOffset(0)]
public vec2d Point1;
[FieldOffset(8)]
public vec2d Point2;
public vec4d(float a1, float a2, float a3, float a4)
public unsafe float X
{
Point1 = default(vec2d);
Point2 = default(vec2d);
X = a1;
Y = a2;
Z = a3;
W = a4;
get { return (*(M128*)mapID).single_0; }
set { (*(M128*)mapID).single_0 = value; }
}
public vec4d(double a1, double a2, double a3, double a4)
public float Y
{
Point1 = default(vec2d);
Point2 = default(vec2d);
X = (float)a1;
Y = (float)a2;
Z = (float)a3;
W = (float)a4;
get { return _value.single_1; }
set { _value.single_1 = value; }
}
public vec4d(vec2d p1, vec2d p2)
public float Z
{
X = 0;
Y = 0;
Z = 0;
W = 0;
Point1 = p1;
Point2 = p2;
get { return _value.single_2; }
set { _value.single_2 = value; }
}
public override bool Equals(object obj)
public float W
{
if (obj == null)
{
return false;
}
else if (obj.GetType() != typeof(vec4d))
{
return false;
}
else
{
return this == (vec4d)obj;
}
get { return _value.single_3; }
set { _value.single_3 = value; }
}
bool IEquatable<vec4d>.Equals(vec4d other)
public Vec4d(float x, float y, float z, float w)
{
if (this.GetHashCode() != other.GetHashCode())
{
return false;
}
else
{
return this.X == other.X
&& this.Y == other.Y
&& this.Z == other.Z
&& this.W == other.Z;
}
X = x;
Y = y;
Z = z;
W = w;
}
public override int GetHashCode()
internal Vec4d()
{
return HashCode.Combine(X, Y, Z, W);
}
public override string ToString()
public static Vec4d operator +(Vec4d vec1,Vec4d vec2)
{
return $"{X}\t{Y}\t{Z}\t{W}";
Vec4d result = new Vec4d();
result._value = internalIO.VecAddVec(vec1._value,vec2._value);
return result;
}
public static bool operator ==(vec4d vec1, vec4d vec2)
public static Vec4d operator -(Vec4d vec1, Vec4d vec2)
{
return vec1.Equals(vec2);
Vec4d result = new Vec4d();
result._value = internalIO.VecAddVec(vec1._value, vec2._value);
return result;
}
public static bool operator !=(vec4d vec1, vec4d vec2)
{
return !vec1.Equals(vec2);
}
public static vec4d operator +(vec4d vec1, vec4d vec2)
{
return new vec4d(
vec1.X + vec2.X,
vec1.Y + vec2.Y,
vec1.Z + vec2.Z,
vec1.W + vec2.W
);
}
public static vec4d operator -(vec4d vec1, vec4d vec2)
{
return new vec4d(
vec1.X - vec2.X,
vec1.Y - vec2.Y,
vec1.Z - vec2.Z,
vec1.W - vec2.W
);
}
public static float operator *(vec4d vec1, vec4d vec2)
{
return
vec1.X * vec2.X
+ vec1.Y * vec2.Y
+ vec1.Z * vec2.Z
+ vec1.W * vec2.W;
}
public static vec4d operator *(vec4d vec, float x)
{
return new vec4d(vec.X * x, vec.Y * x, vec.Z * x, vec.W * x);
}
public static vec4d operator /(vec4d vec, float x)
{
return new vec4d(vec.X / x, vec.Y / x, vec.Z / x, vec.W / x);
}
public static implicit operator float[](vec4d vec)
{
return new float[] { vec.X, vec.Y, vec.Z, vec.W };
}
}
}