daily update on 20240610 by nitload youmu

This commit is contained in:
Nitload
2024-06-10 15:11:01 +08:00
parent c0093f7b5c
commit f6963b8e00
96 changed files with 2927 additions and 2290 deletions
@@ -16,14 +16,16 @@ namespace StgSharp.Geometries
public bool CollideWith(IPlainEntity entity);
}
public class PlainEntity:IPlainEntity
{
private PlainGeometry _shape;
vec2d IPlainEntity.CenterPosition
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
get => _shape.Coordination.LocalOrigin.Coord.XY;
set => throw new InvalidOperationException();
}
public PlainEntity(PlainGeometry shape)
@@ -76,7 +76,13 @@ namespace StgSharp.Geometries
get;
set;
}
vec2d IPlainEntity.CenterPosition { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
vec2d IPlainEntity.CenterPosition
{
get => GlobalBuffer.CoordAndRotationList[BufferId].XY;
set => throw new NotImplementedException();
}
bool IPlainEntity.CollideWith(IPlainEntity entity)
{
@@ -42,19 +42,19 @@ namespace StgSharp.Geometries
public abstract class PlainGeometry : IGeometry
{
protected vec4d[] vertexMat;
internal ICoord coordinate;
internal CoordinationBase coordinate;
public PlainGeometry()
internal PlainGeometry(CoordinationBase coordination)
{
coordinate = coordination;
}
public vec4d this[int index]
public Point this[int index]
{
get => vertexMat[index];
set => vertexMat[index] = value;
get => new Point(vertexMat[index]);
set => vertexMat[index].vec = value.coordVec;
}
public ICoord ReferenceCoordinate => this.coordinate;
public int VertexCount => this.vertexMat.Length;
@@ -62,9 +62,11 @@ namespace StgSharp.Geometries
#pragma warning disable CA1819
public vec4d[] VertexStream => vertexMat;
#pragma warning restore CA1819
public CoordinationBase Coordination => this.coordinate;
#pragma warning restore CA1819
}
}
@@ -38,32 +38,53 @@ namespace StgSharp.Geometries
public class Parallelogram : Polygon4
{
internal readonly Func<int, vec3d> movCenterOperation =
new Func<int, vec3d>(GeometryOperation.DefaultMotion);
internal Point center;
internal readonly Func<int,vec3d> movCenterOperation =
new Func<int,vec3d>(GeometryOperation.DefaultMotion);
public Parallelogram(
float v0x, float v0y, float v0z,
float v1x, float v1y, float v1z,
float v2x, float v2y, float v2z,
float v3x, float v3y, float v3z
float v0x, float v0y,
float v1x, float v1y,
float v2x, float v2y,
float v3x, float v3y
) : base(
v0x, v0y, v0z,
v1x, v1y, v1z,
v2x, v2y, v2z,
v3x, v3y, v3z
v0x, v0y, v1x, v1y,
v2x, v2y, v3x, v3y
)
{
#if DEBUG
if (
this[0] + this[2] !=
this[1] + this[3]
this[0].Coord + this[2].Coord !=
this[1].Coord + this[3].Coord
)
{
InternalIO.InternalWriteLog("Init of geometry item failed, because four vertices cannot form a rectangle.", LogType.Warning);
}
#endif
}
public Parallelogram(
PlainCoordinate coordination,
float v0x, float v0y,
float v1x, float v1y,
float v2x, float v2y,
float v3x, float v3y
) : base(coordination,
v0x, v0y, v1x, v1y,
v2x, v2y, v3x, v3y
)
{
#if DEBUG
if (
this[0].Coord + this[2].Coord !=
this[1].Coord + this[3].Coord
)
{
InternalIO.InternalWriteLog("Init of geometry item failed, because four vertices cannot form a rectangle.", LogType.Warning);
}
#endif
}
}
}
@@ -71,9 +71,9 @@ namespace StgSharp.Geometries
public Plain(Point p1, Point p2, Point p3)
{
vec3d origin = p1.Position;
vec3d v1 = p2.Position - origin;
vec3d v2 = p3.Position - origin;
vec3d origin = p1.Coord;
vec3d v1 = p2.Coord - origin;
vec3d v2 = p3.Coord - origin;
vec1 = v1 - (v2 * (v1.Y / v2.Y)); //计算平面在xz平面上的方向投影
@@ -40,48 +40,80 @@ namespace StgSharp.Geometries
{
protected static int[] Indices = [0, 1, 2, 0, 2, 3];
internal Polygon4()
internal Polygon4():base(PlainCoordinate.StandardPlainCoordination)
{
vertexMat = new vec4d[4];
}
public Polygon4(ICoord coordinate,
vec3d topLeft,
vec3d topRight,
vec3d bottomRight,
vec3d bottomLeft
)
internal Polygon4(vec4d[] rawCoord):
base(PlainCoordinate.StandardPlainCoordination)
{
this.coordinate = coordinate;
this[0] = new vec4d(topLeft.vec);
this[1] = new vec4d(topRight.vec);
this[2] = new vec4d(bottomRight.vec);
this[3] = new vec4d(bottomLeft.vec);
Vector4 maxCoord = this[0].vec;
Vector4 minCoord = this[0].vec;
maxCoord = Vector4.Max(maxCoord, this[1].vec);
maxCoord = Vector4.Max(maxCoord, this[2].vec);
maxCoord = Vector4.Max(maxCoord, this[3].vec);
minCoord = Vector4.Min(minCoord, this[1].vec);
minCoord = Vector4.Min(minCoord, this[2].vec);
minCoord = Vector4.Min(minCoord, this[3].vec);
if (rawCoord.Length != 4)
{
throw new ArgumentOutOfRangeException(nameof(rawCoord));
}
vertexMat = rawCoord;
}
public Polygon4(
float v0x, float v0y, float v0z,
float v1x, float v1y, float v1z,
float v2x, float v2y, float v2z,
float v3x, float v3y, float v3z
)
Point topLeft,
Point topRight,
Point bottomRight,
Point bottomLeft
):base(PlainCoordinate.StandardPlainCoordination)
{
this[0] = topLeft;
this[1] = topRight;
this[2] = bottomRight;
this[3] = bottomLeft;
}
public Polygon4(
float v0x, float v0y,
float v1x, float v1y,
float v2x, float v2y,
float v3x, float v3y
):base(PlainCoordinate.StandardPlainCoordination)
{
vertexMat = new vec4d[4];
this[0] = new vec4d(v0x, v0y, v0z, 0);
this[1] = new vec4d(v1x, v1y, v1z, 0);
this[2] = new vec4d(v2x, v2y, v2z, 0);
this[3] = new vec4d(v3x, v3y, v3z, 0);
this[0] = new Point(v0x, v0y, 0);
this[1] = new Point(v1x, v1y, 0);
this[2] = new Point(v2x, v2y, 0);
this[3] = new Point(v3x, v3y, 0);
}
public Polygon4(CoordinationBase coordinate,
PlainCoordinate coordination,
Point topLeft,
Point topRight,
Point bottomRight,
Point bottomLeft
) : base(coordinate)
{
this[0] = topLeft;
this[1] = topRight;
this[2] = bottomRight;
this[3] = bottomLeft;
}
public Polygon4(
PlainCoordinate coordination,
float v0x, float v0y,
float v1x, float v1y,
float v2x, float v2y,
float v3x, float v3y
) : base(coordination)
{
vertexMat = new vec4d[4];
this[0] = new Point(v0x, v0y, 0);
this[1] = new Point(v1x, v1y, 0);
this[2] = new Point(v2x, v2y, 0);
this[3] = new Point(v3x, v3y, 0);
}
public override ReadOnlySpan<int> VertexIndices => Indices;
@@ -39,25 +39,42 @@ namespace StgSharp.Geometries
public unsafe class Polygon5 : PlainGeometry
{
public unsafe Polygon5()
public unsafe Polygon5():base(PlainCoordinate.StandardPlainCoordination)
{
vertexMat = new vec4d[5];
}
public Polygon5(
float v0x, float v0y, float v0z,
float v1x, float v1y, float v1z,
float v2x, float v2y, float v2z,
float v3x, float v3y, float v3z,
float v4x, float v4y, float v4z
)
float v0x, float v0y,
float v1x, float v1y,
float v2x, float v2y,
float v3x, float v3y,
float v4x, float v4y
):base(PlainCoordinate.StandardPlainCoordination)
{
vertexMat = new vec4d[5];
this[0] = new vec4d(v0x, v0y, v0z, 0);
this[1] = new vec4d(v1x, v1y, v1z, 0);
this[2] = new vec4d(v2x, v2y, v2z, 0);
this[3] = new vec4d(v3x, v3y, v3z, 0);
this[4] = new vec4d(v4x, v4y, v4z, 0);
this[0] = new Point(v0x, v0y, 0);
this[1] = new Point(v1x, v1y, 0);
this[2] = new Point(v2x, v2y, 0);
this[3] = new Point(v3x, v3y, 0);
this[4] = new Point(v4x, v4y, 0);
}
public Polygon5(
PlainCoordinate coordination,
float v0x, float v0y,
float v1x, float v1y,
float v2x, float v2y,
float v3x, float v3y,
float v4x, float v4y
):base(coordination)
{
vertexMat = new vec4d[5];
this[0] = new Point(v0x, v0y, 0);
this[1] = new Point(v1x, v1y, 0);
this[2] = new Point(v2x, v2y, 0);
this[3] = new Point(v3x, v3y, 0);
this[4] = new Point(v4x, v4y, 0);
}
internal static int[] Indices = [ 0, 1, 2, 0, 2, 3, 0, 3, 4 ];
@@ -38,11 +38,32 @@ namespace StgSharp.Geometries
{
public class Polygon6 : PlainGeometry
{
public Polygon6()
public Polygon6():base(PlainCoordinate.StandardPlainCoordination)
{
vertexMat = new vec4d[6];
}
public Polygon6(
PlainCoordinate coordination,
vec2d vert0,
vec2d vert1,
vec2d vert2,
vec2d vert3,
vec2d vert4,
vec2d vert5,
vec2d vert6
) : base(coordination)
{
vertexMat = new vec4d[6];
vertexMat[0].vec = vert0.vec;
vertexMat[1].vec = vert1.vec;
vertexMat[2].vec = vert2.vec;
vertexMat[3].vec = vert3.vec;
vertexMat[4].vec = vert4.vec;
vertexMat[5].vec = vert5.vec;
vertexMat[6].vec = vert6.vec;
}
internal static int[] Indices = [ 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5 ];
public override ReadOnlySpan<int> VertexIndices => Indices;
@@ -38,20 +38,44 @@ namespace StgSharp.Geometries
{
public Rectangle(
float v0x, float v0y, float v0z,
float v1x, float v1y, float v1z,
float v2x, float v2y, float v2z,
float v3x, float v3y, float v3z
float v0x, float v0y,
float v1x, float v1y,
float v2x, float v2y,
float v3x, float v3y
) : base(
v0x, v0y, v0z,
v1x, v1y, v1z,
v2x, v2y, v2z,
v3x, v3y, v3z
v0x, v0y,
v1x, v1y,
v2x, v2y,
v3x, v3y
)
{
#if DEBUG
vec2d side0 = (this[0] - this[1]).XY;
vec2d side1 = (this[2] - this[1]).XY;
vec2d side0 = (this[0].Coord - this[1].Coord).XY;
vec2d side1 = (this[2].Coord - this[1].Coord).XY;
if (side0.Cross(side1) == 0)
{
throw new ArgumentException();
}
#endif
}
public Rectangle(
PlainCoordinate coordination,
float v0x, float v0y,
float v1x, float v1y,
float v2x, float v2y,
float v3x, float v3y
) : base(coordination,
v0x, v0y,
v1x, v1y,
v2x, v2y,
v3x, v3y
)
{
#if DEBUG
vec2d side0 = (this[0].Coord - this[1].Coord).XY;
vec2d side1 = (this[2].Coord - this[1].Coord).XY;
if (side0.Cross(side1) == 0)
{
throw new ArgumentException();
@@ -42,14 +42,14 @@ namespace StgSharp.Geometries
{
public Square(
float v0x, float v0y, float v0z,
float v1x, float v1y, float v1z,
float v2x, float v2y, float v2z,
float v3x, float v3y, float v3z)
: base(v0x, v0y, v0z,
v1x, v1y, v1z,
v2x, v2y, v2z,
v3x, v3y, v3z)
float v0x, float v0y,
float v1x, float v1y,
float v2x, float v2y,
float v3x, float v3y)
: base(v0x, v0y,
v1x, v1y,
v2x, v2y,
v3x, v3y)
{
if (true)
{
@@ -42,33 +42,54 @@ namespace StgSharp.Geometries
public unsafe class Triangle : PlainGeometry
{
public Triangle()
public Triangle():base(PlainCoordinate.StandardPlainCoordination)
{
vertexMat = new vec4d[3];
}
public Triangle(
vec3d vertex01,
vec3d vertex02,
vec3d vertex03
)
Point vertex01,
Point vertex02,
Point vertex03
) : base(PlainCoordinate.StandardPlainCoordination)
{
this[0] = new vec4d( vertex01.vec);
this[1] = new vec4d( vertex02.vec);
this[2] = new vec4d( vertex03.vec);
this[0] = vertex01;
this[1] = vertex02;
this[2] = vertex03;
}
public Triangle(
float v0x, float v0y, float v0z,
float v1x, float v1y, float v1z,
float v2x, float v2y, float v2z
)
float v0x, float v0y,
float v1x, float v1y,
float v2x, float v2y
) : base(PlainCoordinate.StandardPlainCoordination)
{
this[0] = new vec4d(v0x, v0y, v0z, 0);
this[1] = new vec4d(v1x, v1y, v1z, 0);
this[2] = new vec4d(v2x, v2y, v2z, 0);
this[0] = new Point(v0x, v0y, 0);
this[1] = new Point(v1x, v1y, 0);
this[2] = new Point(v2x, v2y, 0);
}
public Triangle(PlainCoordinate coordination,
Point vertex01,
Point vertex02,
Point vertex03
) : base(coordination)
{
this[0] = vertex01;
this[1] = vertex02;
this[2] = vertex03;
}
public Triangle(PlainCoordinate coordination,
float v0x, float v0y,
float v1x, float v1y,
float v2x, float v2y
) : base(coordination)
{
this[0] = new Point(v0x, v0y, 0);
this[1] = new Point(v1x, v1y, 0);
this[2] = new Point(v2x, v2y, 0);
}
internal static int[] Indices = [ 0, 1, 2 ];
public override ReadOnlySpan<int> VertexIndices => Indices;